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 ProjectTabPanelModuleCreator extends AbstractPluginModuleCreator<TabPanelProperties>
19 {
20
21 public static final String GENERIC_CLASS = "GenericProjectTabPanel";
22 public static final String GENERIC_PACKAGE = "com.atlassian.jira.plugin.projectpanel.impl";
23 public static final String FQ_GENERIC_CLASS = GENERIC_PACKAGE + "." + GENERIC_CLASS;
24
25 public static final String MODULE_NAME = "Project Tab Panel";
26 private static final String TEMPLATE_PREFIX = "templates/jira/tabpanel/project/";
27
28
29 private static final String CLASS_TEMPLATE = TEMPLATE_PREFIX + "ProjectTabPanel.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 + "ProjectTabPanelFuncTest.java.vtl";
32 private static final String VIEW_TEMPLATE = TEMPLATE_PREFIX + "project-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 + "project-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 if (props.isUseCustomClass())
54 {
55
56 templateHelper.writeJavaClassFromTemplate(CLASS_TEMPLATE, classname, location.getSourceDirectory(), packageName, props);
57
58
59 templateHelper.writeJavaClassFromTemplate(UNIT_TEST_TEMPLATE, testClassname(classname), location.getTestDirectory(), packageName, props);
60 }
61
62 templateHelper.writeFileFromTemplate(VIEW_TEMPLATE, viewFileName, templatesDir, props);
63 }
64
65
66 addModuleToPluginXml(PLUGIN_MODULE_TEMPLATE, location, props);
67 }
68
69
70 @Override
71 public String getModuleName()
72 {
73 return MODULE_NAME;
74 }
75 }