1 package com.atlassian.plugins.codegen.modules.common.component;
2
3 import com.atlassian.plugins.codegen.ComponentDeclaration;
4 import com.atlassian.plugins.codegen.PluginProjectChangeset;
5 import com.atlassian.plugins.codegen.annotations.BambooPluginModuleCreator;
6 import com.atlassian.plugins.codegen.annotations.ConfluencePluginModuleCreator;
7 import com.atlassian.plugins.codegen.annotations.CrowdPluginModuleCreator;
8 import com.atlassian.plugins.codegen.annotations.FeCruPluginModuleCreator;
9 import com.atlassian.plugins.codegen.annotations.JiraPluginModuleCreator;
10 import com.atlassian.plugins.codegen.annotations.RefAppPluginModuleCreator;
11 import com.atlassian.plugins.codegen.annotations.StashPluginModuleCreator;
12 import com.atlassian.plugins.codegen.modules.AbstractPluginModuleCreator;
13
14 import static com.atlassian.fugue.Option.option;
15 import static com.atlassian.fugue.Option.some;
16 import static com.atlassian.plugins.codegen.ComponentDeclaration.Visibility.PRIVATE;
17 import static com.atlassian.plugins.codegen.ComponentDeclaration.Visibility.PUBLIC;
18 import static com.atlassian.plugins.codegen.modules.Dependencies.MOCKITO_TEST;
19
20
21
22
23 @RefAppPluginModuleCreator
24 @JiraPluginModuleCreator
25 @ConfluencePluginModuleCreator
26 @BambooPluginModuleCreator
27 @FeCruPluginModuleCreator
28 @CrowdPluginModuleCreator
29 @StashPluginModuleCreator
30 public class ComponentModuleCreator extends AbstractPluginModuleCreator<ComponentProperties>
31 {
32 public static final String MODULE_NAME = "Component";
33 private static final String TEMPLATE_PREFIX = "templates/common/component/";
34
35
36 private static final String CLASS_TEMPLATE = TEMPLATE_PREFIX + "Component.java.vtl";
37 private static final String INTERFACE_TEMPLATE = TEMPLATE_PREFIX + "ComponentInterface.java.vtl";
38
39
40 private static final String EXAMPLE_CLASS_TEMPLATE = TEMPLATE_PREFIX + "Example" + CLASS_TEMPLATE;
41
42 @Override
43 public PluginProjectChangeset createModule(ComponentProperties props) throws Exception
44 {
45 ComponentDeclaration.Builder component = ComponentDeclaration.builder(props.getClassId(), props.getModuleKey())
46 .name(option(props.getModuleName()))
47 .nameI18nKey(option(props.getNameI18nKey()))
48 .description(option(props.getDescription()))
49 .descriptionI18nKey(option(props.getDescriptionI18nKey()))
50 .visibility(props.isPublic() ? PUBLIC : PRIVATE);
51 if (props.generateInterface())
52 {
53 component.interfaceId(some(props.getInterfaceId()));
54 }
55 if (props.getServiceProps() != null)
56 {
57 component.serviceProperties(props.getServiceProps());
58 }
59
60 PluginProjectChangeset ret = new PluginProjectChangeset()
61 .with(MOCKITO_TEST)
62 .with(component.build());
63
64 if (props.includeExamples())
65 {
66 return ret.with(createClass(props, EXAMPLE_CLASS_TEMPLATE));
67 }
68 else
69 {
70 if (props.generateClass())
71 {
72 ret = ret.with(createClassAndTests(props, CLASS_TEMPLATE, GENERIC_TEST_TEMPLATE, GENERIC_TEST_TEMPLATE));
73 }
74 if (props.generateInterface())
75 {
76 ret = ret.with(createClass(props, props.getInterfaceId(), INTERFACE_TEMPLATE));
77 }
78 return ret;
79 }
80 }
81
82 @Override
83 public String getModuleName()
84 {
85 return MODULE_NAME;
86 }
87 }