1   package com.atlassian.maven.plugins.amps.codegen.prompter.jira;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import com.atlassian.maven.plugins.amps.codegen.annotations.ModuleCreatorClass;
7   import com.atlassian.maven.plugins.amps.codegen.prompter.common.AbstractResourcePrompter;
8   import com.atlassian.plugins.codegen.modules.PluginModuleLocation;
9   import com.atlassian.plugins.codegen.modules.common.Resource;
10  import com.atlassian.plugins.codegen.modules.jira.UserFormatModuleCreator;
11  import com.atlassian.plugins.codegen.modules.jira.UserFormatProperties;
12  import com.atlassian.plugins.codegen.util.ClassnameUtil;
13  
14  import org.codehaus.plexus.components.interactivity.Prompter;
15  import org.codehaus.plexus.components.interactivity.PrompterException;
16  
17  /**
18   * @since 3.5
19   */
20  @ModuleCreatorClass(UserFormatModuleCreator.class)
21  public class UserFormatPrompter extends AbstractResourcePrompter<UserFormatProperties>
22  {
23  
24      public UserFormatPrompter(Prompter prompter)
25      {
26          super(prompter);
27  
28      }
29  
30      @Override
31      public UserFormatProperties promptForBasicProperties(PluginModuleLocation moduleLocation) throws PrompterException
32      {
33          String className = promptJavaClassname("Enter New Classname", "MyUserFormat");
34          String packageName = promptJavaPackagename("Enter Package Name", getDefaultBasePackage() + ".jira.userformat");
35  
36          String fqClass = ClassnameUtil.fullyQualifiedName(packageName, className);
37  
38          UserFormatProperties props = new UserFormatProperties(fqClass);
39  
40          props.setTypeName(promptNotBlank("Enter Type Name"));
41          props.setTypeKey(promptNotBlank("Enter Type i18n Key"));
42  
43          List<Resource> resources = new ArrayList<Resource>(1);
44  
45          String templatePath = "/templates/userformat/" + props.getModuleKey() + "/";
46  
47          Resource view = new Resource();
48          view.setName("view");
49          view.setType("velocity");
50          view.setLocation(templatePath + "view.vm");
51          resources.add(view);
52          props.setResources(resources);
53  
54          return props;
55      }
56  
57      @Override
58      public void promptForAdvancedProperties(UserFormatProperties props, PluginModuleLocation moduleLocation) throws PrompterException
59      {
60          props.setResources(promptForResources());
61      }
62  
63      @Override
64      protected Resource promptForResource() throws PrompterException
65      {
66          Resource resource = new Resource();
67          resource.setName(promptNotBlank("Enter Resource Name"));
68  
69          resource.setType("velocity");
70          resource.setLocation(promptNotBlank("Enter Location (path to resource file)"));
71  
72          return resource;
73      }
74  }