1   package com.atlassian.plugins.codegen.modules.common;
2   
3   import java.io.File;
4   
5   import com.atlassian.plugins.codegen.annotations.*;
6   import com.atlassian.plugins.codegen.modules.AbstractPluginModuleCreator;
7   import com.atlassian.plugins.codegen.modules.PluginModuleLocation;
8   
9   import org.apache.commons.io.FilenameUtils;
10  import org.apache.commons.lang.StringUtils;
11  
12  /**
13   * @since 3.6
14   */
15  @RefAppPluginModuleCreator
16  @JiraPluginModuleCreator
17  @ConfluencePluginModuleCreator
18  @FeCruPluginModuleCreator
19  @Dependencies({
20          @Dependency(groupId = "org.mockito", artifactId = "mockito-all", version = "1.8.5", scope = "test")
21  })
22  public class GadgetModuleCreator extends AbstractPluginModuleCreator<GadgetProperties>
23  {
24  
25      public static final String MODULE_NAME = "Gadget Plugin Module";
26      private static final String TEMPLATE_PREFIX = "templates/common/gadget/";
27  
28      //stub
29      private static final String GADGET_TEMPLATE = TEMPLATE_PREFIX + "gadget.xml.vtl";
30  
31      private static final String PLUGIN_MODULE_TEMPLATE = TEMPLATE_PREFIX + "gadget-plugin.xml.vtl";
32  
33      @Override
34      public void createModule(PluginModuleLocation location, GadgetProperties props) throws Exception
35      {
36  
37  
38          if (props.includeExamples())
39          {
40  
41          } else
42          {
43              String gadgetLocation = props.getLocation();
44              String gadgetFilename = FilenameUtils.getName(gadgetLocation);
45              String gadgetPath = FilenameUtils.getPath(gadgetLocation);
46              File gadgetFolder;
47  
48              if (StringUtils.isNotBlank(gadgetPath))
49              {
50                  gadgetFolder = new File(location.getResourcesDir(), gadgetPath);
51              } else
52              {
53                  gadgetFolder = location.getResourcesDir();
54              }
55  
56              //gadget
57              templateHelper.writeFileFromTemplate(GADGET_TEMPLATE, gadgetFilename, gadgetFolder, props);
58  
59          }
60  
61  
62          addModuleToPluginXml(PLUGIN_MODULE_TEMPLATE, location, props);
63      }
64  
65  
66      @Override
67      public String getModuleName()
68      {
69          return MODULE_NAME;
70      }
71  }