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 import com.atlassian.plugins.codegen.modules.common.Resource;
11
12 import org.apache.commons.io.FilenameUtils;
13 import org.apache.commons.lang.StringUtils;
14
15
16
17
18 @JiraPluginModuleCreator
19 @Dependencies({
20 @Dependency(groupId = "org.mockito", artifactId = "mockito-all", version = "1.8.5", scope = "test")
21 })
22 public class SearchRequestViewModuleCreator extends AbstractPluginModuleCreator<SearchRequestViewProperties>
23 {
24
25 public static final String MODULE_NAME = "Search Request View";
26 private static final String TEMPLATE_PREFIX = "templates/jira/searchrequestview/";
27
28
29 private static final String CLASS_TEMPLATE = TEMPLATE_PREFIX + "SearchRequestView.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 + "SearchRequestViewFuncTest.java.vtl";
32 private static final String VIEW_TEMPLATE = "templates/common/actionview.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 + "search-request-view-plugin.xml.vtl";
38
39 @Override
40 public void createModule(PluginModuleLocation location, SearchRequestViewProperties props) throws Exception
41 {
42 String packageName = props.getPackage();
43
44 String classname = props.getClassname();
45
46 if (props.includeExamples())
47 {
48 templateHelper.writeJavaClassFromTemplate(EXAMPLE_CLASS_TEMPLATE, classname, location.getSourceDirectory(), packageName, props);
49 } else
50 {
51
52 templateHelper.writeJavaClassFromTemplate(CLASS_TEMPLATE, classname, location.getSourceDirectory(), packageName, props);
53
54
55 templateHelper.writeJavaClassFromTemplate(UNIT_TEST_TEMPLATE, testClassname(classname), location.getTestDirectory(), packageName, props);
56
57
58
59 }
60
61
62 for (Resource resource : props.getResources())
63 {
64 String resourcePath = FilenameUtils.separatorsToSystem(resource.getLocation());
65
66 if (resourcePath.startsWith("templates" + File.separator) || resourcePath.startsWith(File.separator + "templates" + File.separator))
67 {
68 resourcePath = StringUtils.substringAfter(resourcePath, "templates" + File.separator);
69 }
70
71 File resourceFolder = new File(location.getTemplateDirectory(), FilenameUtils.getPath(resourcePath));
72 String resourceFile = FilenameUtils.getName(resourcePath);
73
74 props.setProperty("CURRENT_VIEW", resourceFile);
75
76 templateHelper.writeFileFromTemplate(VIEW_TEMPLATE, FilenameUtils.getName(resourcePath), resourceFolder, props);
77 }
78
79 addModuleToPluginXml(PLUGIN_MODULE_TEMPLATE, location, props);
80 }
81
82
83 @Override
84 public String getModuleName()
85 {
86 return MODULE_NAME;
87 }
88 }