1 package com.atlassian.plugins.codegen.modules.jira;
2
3 import java.io.File;
4
5 import com.atlassian.plugins.codegen.annotations.Dependencies;
6 import com.atlassian.plugins.codegen.annotations.Dependency;
7 import com.atlassian.plugins.codegen.annotations.JiraPluginModuleCreator;
8 import com.atlassian.plugins.codegen.modules.AbstractPluginModuleCreator;
9 import com.atlassian.plugins.codegen.modules.PluginModuleLocation;
10
11
12
13
14 @JiraPluginModuleCreator
15 @Dependencies({
16 @Dependency(groupId = "org.mockito", artifactId = "mockito-all", version = "1.8.5", scope = "test")
17 })
18 public class ComponentTabPanelModuleCreator extends AbstractPluginModuleCreator<TabPanelProperties>
19 {
20
21 public static final String GENERIC_CLASS = "GenericTabPanel";
22 public static final String GENERIC_PACKAGE = "com.atlassian.jira.plugin.componentpanel.impl";
23 public static final String FQ_GENERIC_CLASS = GENERIC_PACKAGE + "." + GENERIC_CLASS;
24
25 public static final String MODULE_NAME = "Component Tab Panel";
26 private static final String TEMPLATE_PREFIX = "templates/jira/tabpanel/component/";
27
28
29 private static final String CLASS_TEMPLATE = TEMPLATE_PREFIX + "ComponentTabPanel.java.vtl";
30 private static final String UNIT_TEST_TEMPLATE = "templates/generic/GenericTest.java.vtl";
31 private static final String FUNC_TEST_TEMPLATE = TEMPLATE_PREFIX + "ComponentTabPanelFuncTest.java.vtl";
32 private static final String VIEW_TEMPLATE = TEMPLATE_PREFIX + "component-tab-panel.vm.vtl";
33
34
35 private static final String EXAMPLE_CLASS_TEMPLATE = TEMPLATE_PREFIX + "Example" + CLASS_TEMPLATE;
36
37 private static final String PLUGIN_MODULE_TEMPLATE = TEMPLATE_PREFIX + "component-tab-panel-plugin.xml.vtl";
38
39 @Override
40 public void createModule(PluginModuleLocation location, TabPanelProperties props) throws Exception
41 {
42 String moduleKey = props.getModuleKey();
43 String packageName = props.getPackage();
44 String classname = props.getClassname();
45 String viewFileName = moduleKey + ".vm";
46 File templatesDir = new File(location.getTemplateDirectory(), "tabpanels");
47
48 if (props.includeExamples())
49 {
50 templateHelper.writeJavaClassFromTemplate(EXAMPLE_CLASS_TEMPLATE, classname, location.getSourceDirectory(), packageName, props);
51 } else
52 {
53
54 if (props.isUseCustomClass())
55 {
56
57 templateHelper.writeJavaClassFromTemplate(CLASS_TEMPLATE, classname, location.getSourceDirectory(), packageName, props);
58
59
60 templateHelper.writeJavaClassFromTemplate(UNIT_TEST_TEMPLATE, testClassname(classname), location.getTestDirectory(), packageName, props);
61 }
62
63 templateHelper.writeFileFromTemplate(VIEW_TEMPLATE, viewFileName, templatesDir, props);
64 }
65
66
67 addModuleToPluginXml(PLUGIN_MODULE_TEMPLATE, location, props);
68 }
69
70
71 @Override
72 public String getModuleName()
73 {
74 return MODULE_NAME;
75 }
76 }