/plugin-module-codegen-engine/src/main/java/com/atlassian/plugins/codegen/modules/jira/RPCModuleCreator.java

https://bitbucket.org/mmeinhold/amps · Java · 70 lines · 54 code · 11 blank · 5 comment · 1 complexity · 6e30ad6a13699ee39cea7846f0d3d7ae MD5 · raw file

  1. package com.atlassian.plugins.codegen.modules.jira;
  2. import com.atlassian.plugins.codegen.ComponentDeclaration;
  3. import com.atlassian.plugins.codegen.PluginProjectChangeset;
  4. import com.atlassian.plugins.codegen.annotations.JiraPluginModuleCreator;
  5. import com.atlassian.plugins.codegen.modules.AbstractPluginModuleCreator;
  6. import static com.atlassian.fugue.Option.option;
  7. import static com.atlassian.fugue.Option.some;
  8. import static com.atlassian.plugins.codegen.modules.Dependencies.HTTPCLIENT_TEST;
  9. import static com.atlassian.plugins.codegen.modules.Dependencies.MOCKITO_TEST;
  10. /**
  11. * @since 3.6
  12. */
  13. @JiraPluginModuleCreator
  14. public class RPCModuleCreator extends AbstractPluginModuleCreator<RPCProperties>
  15. {
  16. public static final String MODULE_NAME = "RPC Endpoint Plugin";
  17. private static final String TEMPLATE_PREFIX = "templates/jira/rpc/";
  18. //stub
  19. private static final String CLASS_TEMPLATE = TEMPLATE_PREFIX + "RPCService.java.vtl";
  20. private static final String INTERFACE_TEMPLATE = TEMPLATE_PREFIX + "RPCServiceInterface.java.vtl";
  21. private static final String UNIT_TEST_TEMPLATE = "templates/generic/GenericTest.java.vtl";
  22. //examples
  23. private static final String EXAMPLE_CLASS_TEMPLATE = TEMPLATE_PREFIX + "Example" + CLASS_TEMPLATE;
  24. private static final String SOAP_PLUGIN_MODULE_TEMPLATE = TEMPLATE_PREFIX + "soap-rpc-plugin.xml.vtl";
  25. private static final String XML_PLUGIN_MODULE_TEMPLATE = TEMPLATE_PREFIX + "xml-rpc-plugin.xml.vtl";
  26. @Override
  27. public PluginProjectChangeset createModule(RPCProperties props) throws Exception
  28. {
  29. String moduleKey = props.getModuleKey() + "-component";
  30. String description = "Component For " + props.getModuleName();
  31. String name = props.getModuleName() + " Component";
  32. String nameI18nKey = props.getNameI18nKey() + ".component";
  33. PluginProjectChangeset ret = new PluginProjectChangeset()
  34. .with(HTTPCLIENT_TEST,
  35. MOCKITO_TEST)
  36. .with(createModule(props, props.isSoap() ? SOAP_PLUGIN_MODULE_TEMPLATE : XML_PLUGIN_MODULE_TEMPLATE));
  37. if (props.includeExamples())
  38. {
  39. ret = ret.with(createClass(props, EXAMPLE_CLASS_TEMPLATE));
  40. }
  41. else
  42. {
  43. ret = ret.with(createClassAndTests(props, CLASS_TEMPLATE, UNIT_TEST_TEMPLATE))
  44. .with(createClass(props, props.getInterfaceId(), INTERFACE_TEMPLATE));
  45. }
  46. ComponentDeclaration component = ComponentDeclaration.builder(props.getClassId(), moduleKey)
  47. .interfaceId(option(props.getInterfaceId()))
  48. .description(some(description))
  49. .name(some(name))
  50. .nameI18nKey(some(nameI18nKey))
  51. .build();
  52. return ret.with(component);
  53. }
  54. @Override
  55. public String getModuleName()
  56. {
  57. return MODULE_NAME;
  58. }
  59. }