1 package com.atlassian.plugins.codegen.modules.jira;
2
3 import java.util.Map;
4
5 import com.atlassian.plugins.codegen.PluginProjectChangeset;
6 import com.atlassian.plugins.codegen.annotations.JiraPluginModuleCreator;
7 import com.atlassian.plugins.codegen.modules.AbstractPluginModuleCreator;
8
9 import com.google.common.collect.ImmutableMap;
10
11 import org.apache.commons.io.FilenameUtils;
12
13 import static com.atlassian.plugins.codegen.modules.Dependencies.HTTPCLIENT_TEST;
14 import static com.atlassian.plugins.codegen.modules.Dependencies.MOCKITO_TEST;
15
16
17
18
19 @JiraPluginModuleCreator
20 public class WebworkModuleCreator extends AbstractPluginModuleCreator<WebworkProperties>
21 {
22
23 public static final String MODULE_NAME = "Webwork Plugin";
24 private static final String TEMPLATE_PREFIX = "templates/jira/webwork/";
25
26
27 private static final String CLASS_TEMPLATE = TEMPLATE_PREFIX + "WebworkAction.java.vtl";
28
29 private static final String UNIT_TEST_TEMPLATE = "templates/generic/GenericTest.java.vtl";
30 private static final String VIEW_TEMPLATE = "templates/common/actionview.vm.vtl";
31
32
33 private static final String EXAMPLE_CLASS_TEMPLATE = TEMPLATE_PREFIX + "Example" + CLASS_TEMPLATE;
34
35 private static final String PLUGIN_MODULE_TEMPLATE = TEMPLATE_PREFIX + "webwork-plugin.xml.vtl";
36
37 @Override
38 public PluginProjectChangeset createModule(WebworkProperties props) throws Exception
39 {
40 PluginProjectChangeset ret = new PluginProjectChangeset()
41 .with(HTTPCLIENT_TEST,
42 MOCKITO_TEST)
43 .with(createModule(props, PLUGIN_MODULE_TEMPLATE));
44
45 if (props.includeExamples())
46 {
47 }
48 else
49 {
50 for (ActionProperties action : props.getActions())
51 {
52 ret = ret.with(createClassAndTests(action, CLASS_TEMPLATE, UNIT_TEST_TEMPLATE));
53
54
55 for (View view : action.getViews())
56 {
57 ret = ret.with(createViewResource(action, view, VIEW_TEMPLATE));
58 }
59 }
60 }
61
62 return ret;
63 }
64
65 protected PluginProjectChangeset createViewResource(Map<Object, Object> props, View view, String templateName) throws Exception
66 {
67 String resourceFullPath = FilenameUtils.separatorsToSystem(view.getPath());
68 String path = FilenameUtils.getPath(resourceFullPath);
69 String fileName = FilenameUtils.getName(resourceFullPath);
70 Map<Object, Object> tempProps = ImmutableMap.builder().putAll(props).put("CURRENT_VIEW", fileName).build();
71 return createTemplateResource(tempProps, path, fileName, templateName);
72 }
73
74 @Override
75 public String getModuleName()
76 {
77 return MODULE_NAME;
78 }
79 }