1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.maven.archetype.ui;
21
22 import org.apache.maven.archetype.common.ArchetypeConfiguration;
23 import org.apache.maven.archetype.common.Constants;
24 import org.codehaus.plexus.components.interactivity.Prompter;
25 import org.codehaus.plexus.components.interactivity.PrompterException;
26 import org.codehaus.plexus.logging.AbstractLogEnabled;
27
28 import java.util.Iterator;
29
30
31 public class DefaultArchetypeCreationQueryer
32 extends AbstractLogEnabled
33 implements ArchetypeCreationQueryer
34 {
35
36 private Prompter prompter;
37
38 public String getArchetypeArtifactId( String defaultValue )
39 throws PrompterException
40 {
41 return getValue( Constants.ARCHETYPE_ARTIFACT_ID, defaultValue );
42 }
43
44 public String getArchetypeGroupId( String defaultValue )
45 throws PrompterException
46 {
47 return getValue( Constants.ARCHETYPE_GROUP_ID, defaultValue );
48 }
49
50 public String getArchetypeVersion( String defaultValue )
51 throws PrompterException
52 {
53 return getValue( Constants.ARCHETYPE_VERSION, defaultValue );
54 }
55
56 public String getArtifactId( String defaultValue )
57 throws PrompterException
58 {
59 return getValue( Constants.ARTIFACT_ID, defaultValue );
60 }
61
62 public boolean askAddAnotherProperty()
63 throws PrompterException
64 {
65 String query = "Add a new custom property";
66
67 String answer = prompter.prompt( query, "Y" );
68
69 return "Y".equalsIgnoreCase( answer );
70 }
71
72 public String askNewPropertyKey()
73 throws PrompterException
74 {
75 String query = "Define property key";
76
77 String answer = prompter.prompt( query );
78
79 return answer;
80 }
81
82 public String askReplacementValue( String propertyKey, String defaultValue )
83 throws PrompterException
84 {
85 return getValue( propertyKey, defaultValue );
86 }
87
88 public boolean confirmConfiguration( ArchetypeConfiguration archetypeConfiguration )
89 throws PrompterException
90 {
91 String query =
92 "Confirm archetype configuration:\n" + Constants.ARCHETYPE_GROUP_ID + "="
93 + archetypeConfiguration.getGroupId() + "\n" + Constants.ARCHETYPE_ARTIFACT_ID + "="
94 + archetypeConfiguration.getArtifactId() + "\n" + Constants.ARCHETYPE_VERSION + "="
95 + archetypeConfiguration.getVersion() + "\n";
96
97 for ( Iterator propertiesIter = archetypeConfiguration.getProperties().keySet().iterator();
98 propertiesIter.hasNext(); )
99 {
100 String property = (String) propertiesIter.next();
101 query += property + "=" + archetypeConfiguration.getProperty( property ) + "\n";
102 }
103
104 String answer = prompter.prompt( query, "Y" );
105
106 return "Y".equalsIgnoreCase( answer );
107 }
108
109 public String getGroupId( String defaultValue )
110 throws PrompterException
111 {
112 return getValue( Constants.GROUP_ID, defaultValue );
113 }
114
115 public String getPackage( String defaultValue )
116 throws PrompterException
117 {
118 return getValue( Constants.PACKAGE, defaultValue );
119 }
120
121 public String getVersion( String defaultValue )
122 throws PrompterException
123 {
124 return getValue( Constants.VERSION, defaultValue );
125 }
126
127 private String getValue( String requiredProperty, String defaultValue )
128 throws PrompterException
129 {
130 String query = "Define value for " + requiredProperty + ": ";
131 String answer;
132
133 if ( ( defaultValue != null ) && !defaultValue.equals( "null" ) )
134 {
135 answer = prompter.prompt( query, defaultValue );
136 }
137 else
138 {
139 answer = prompter.prompt( query );
140 }
141 return answer;
142 }
143 }