1   package com.atlassian.plugins.codegen.modules.jira;
2   
3   import com.atlassian.plugins.codegen.annotations.Dependencies;
4   import com.atlassian.plugins.codegen.annotations.Dependency;
5   import com.atlassian.plugins.codegen.annotations.JiraPluginModuleCreator;
6   import com.atlassian.plugins.codegen.modules.AbstractPluginModuleCreator;
7   import com.atlassian.plugins.codegen.modules.PluginModuleLocation;
8   import com.atlassian.plugins.codegen.modules.common.component.ComponentModuleCreator;
9   import com.atlassian.plugins.codegen.modules.common.component.ComponentProperties;
10  
11  /**
12   * @since 3.6
13   */
14  @JiraPluginModuleCreator
15  @Dependencies({
16          @Dependency(groupId = "org.mockito", artifactId = "mockito-all", version = "1.8.5", scope = "test")
17          , @Dependency(groupId = "org.apache.httpcomponents", artifactId = "httpclient", version = "4.1.1", scope = "test")
18  })
19  public class RPCModuleCreator extends AbstractPluginModuleCreator<RPCProperties>
20  {
21  
22      public static final String MODULE_NAME = "RPC Endpoint Plugin";
23      private static final String TEMPLATE_PREFIX = "templates/jira/rpc/";
24  
25      //stub
26      private static final String CLASS_TEMPLATE = TEMPLATE_PREFIX + "RPCService.java.vtl";
27      private static final String INTERFACE_TEMPLATE = TEMPLATE_PREFIX + "RPCServiceInterface.java.vtl";
28      private static final String UNIT_TEST_TEMPLATE = "templates/generic/GenericTest.java.vtl";
29      private static final String FUNC_TEST_TEMPLATE = TEMPLATE_PREFIX + "RPCServiceFuncTest.java.vtl";
30  
31      //examples
32      private static final String EXAMPLE_CLASS_TEMPLATE = TEMPLATE_PREFIX + "Example" + CLASS_TEMPLATE;
33  
34      private static final String SOAP_PLUGIN_MODULE_TEMPLATE = TEMPLATE_PREFIX + "soap-rpc-plugin.xml.vtl";
35      private static final String XML_PLUGIN_MODULE_TEMPLATE = TEMPLATE_PREFIX + "xml-rpc-plugin.xml.vtl";
36  
37      @Override
38      public void createModule(PluginModuleLocation location, RPCProperties props) throws Exception
39      {
40          String packageName = props.getPackage();
41          String classname = props.getClassname();
42          String iClassname = props.getInterfaceClass();
43          String iPackage = props.getInterfacePackage();
44  
45          if (props.includeExamples())
46          {
47              templateHelper.writeJavaClassFromTemplate(EXAMPLE_CLASS_TEMPLATE, classname, location.getSourceDirectory(), packageName, props);
48          } else
49          {
50  
51              //interface
52              templateHelper.writeJavaClassFromTemplate(INTERFACE_TEMPLATE, iClassname, location.getSourceDirectory(), iPackage, props);
53  
54              //main class
55              templateHelper.writeJavaClassFromTemplate(CLASS_TEMPLATE, classname, location.getSourceDirectory(), packageName, props);
56  
57              //unit test
58              templateHelper.writeJavaClassFromTemplate(UNIT_TEST_TEMPLATE, testClassname(iClassname), location.getTestDirectory(), packageName, props);
59  
60          }
61  
62          //add the component element first
63          ComponentProperties cProps = new ComponentProperties(props.getFullyQualifiedClassname());
64          cProps.setFullyQualifiedInterface(props.getFullyQualifiedInterface());
65          cProps.setModuleKey(props.getModuleKey() + "-component");
66          cProps.setModuleName(props.getModuleName() + " Component");
67          cProps.setDescription("Component For " + props.getModuleName());
68          cProps.setDescriptionI18nKey(props.getDescriptionI18nKey() + ".component");
69          cProps.setNameI18nKey(props.getNameI18nKey() + ".component");
70          cProps.setGenerateClass(false);
71          cProps.setGenerateInterface(false);
72          cProps.setIncludeExamples(false);
73          //
74  
75          ComponentModuleCreator componentCreator = new ComponentModuleCreator();
76          componentCreator.createModule(location, cProps);
77  
78          //now add the rpc element
79          if (props.isSoap())
80          {
81              addModuleToPluginXml(SOAP_PLUGIN_MODULE_TEMPLATE, location, props);
82          } else
83          {
84              addModuleToPluginXml(XML_PLUGIN_MODULE_TEMPLATE, location, props);
85          }
86  
87  
88      }
89  
90  
91      @Override
92      public String getModuleName()
93      {
94          return MODULE_NAME;
95      }
96  }