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