PageRenderTime 23ms CodeModel.GetById 19ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/plugin-module-codegen-engine/src/main/java/com/atlassian/plugins/codegen/modules/jira/CustomFieldModuleCreator.java

https://bitbucket.org/mmeinhold/amps
Java | 59 lines | 42 code | 11 blank | 6 comment | 2 complexity | dd2fed0aa3ccc478358faa83289a90a1 MD5 | raw file
 1package com.atlassian.plugins.codegen.modules.jira;
 2
 3import com.atlassian.plugins.codegen.PluginProjectChangeset;
 4import com.atlassian.plugins.codegen.annotations.JiraPluginModuleCreator;
 5import com.atlassian.plugins.codegen.modules.AbstractPluginModuleCreator;
 6import com.atlassian.plugins.codegen.modules.common.Resource;
 7
 8import static com.atlassian.plugins.codegen.modules.Dependencies.MOCKITO_TEST;
 9
10/**
11 * @since 3.6
12 */
13@JiraPluginModuleCreator
14public class CustomFieldModuleCreator extends AbstractPluginModuleCreator<CustomFieldProperties>
15{
16    public static final String MODULE_NAME = "Custom Field";
17    private static final String TEMPLATE_PREFIX = "templates/jira/customfield/";
18
19    //stub
20    private static final String CLASS_TEMPLATE = TEMPLATE_PREFIX + "CustomField.java.vtl";
21    private static final String UNIT_TEST_TEMPLATE = "templates/generic/GenericTest.java.vtl";
22    private static final String VIEW_TEMPLATE = "templates/common/actionview.vm.vtl";
23
24    //examples
25    private static final String EXAMPLE_CLASS_TEMPLATE = TEMPLATE_PREFIX + "Example" + CLASS_TEMPLATE;
26
27    private static final String PLUGIN_MODULE_TEMPLATE = TEMPLATE_PREFIX + "custom-field-plugin.xml.vtl";
28
29    @Override
30    public PluginProjectChangeset createModule(CustomFieldProperties props) throws Exception
31    {
32        PluginProjectChangeset ret = new PluginProjectChangeset()
33            .with(MOCKITO_TEST)
34            .with(createModule(props, PLUGIN_MODULE_TEMPLATE));
35        
36        if (props.includeExamples())
37        {
38            return ret.with(createClass(props, EXAMPLE_CLASS_TEMPLATE));
39        }
40        else
41        {
42            ret = ret.with(createClassAndTests(props, CLASS_TEMPLATE, UNIT_TEST_TEMPLATE));
43            
44            //since we know resources are velocity templates, let's create them
45            for (Resource resource : props.getResources())
46            {
47                ret = ret.with(createTemplateResource(props, resource, VIEW_TEMPLATE));
48            }
49            
50            return ret;
51        }
52    }
53
54    @Override
55    public String getModuleName()
56    {
57        return MODULE_NAME;
58    }
59}