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
40 PrompterException
41 {
42 return getValue( Constants.ARCHETYPE_ARTIFACT_ID, defaultValue );
43 }
44
45 public String getArchetypeGroupId( String defaultValue )
46 throws
47 PrompterException
48 {
49 return getValue( Constants.ARCHETYPE_GROUP_ID, defaultValue );
50 }
51
52 public String getArchetypeVersion( String defaultValue )
53 throws
54 PrompterException
55 {
56 return getValue( Constants.ARCHETYPE_VERSION, defaultValue );
57 }
58
59 public String getArtifactId( String defaultValue )
60 throws
61 PrompterException
62 {
63 return getValue( Constants.ARTIFACT_ID, defaultValue );
64 }
65
66 public boolean askAddAnotherProperty()
67 throws
68 PrompterException
69 {
70 String query = "Add a new custom property";
71
72 String answer = prompter.prompt( query, "Y" );
73
74 return "Y".equalsIgnoreCase( answer );
75 }
76
77 public String askNewPropertyKey()
78 throws
79 PrompterException
80 {
81 String query = "Define property key";
82
83 String answer = prompter.prompt( query );
84
85 return answer;
86 }
87
88 public String askReplacementValue( String propertyKey,
89 String defaultValue )
90 throws
91 PrompterException
92 {
93 return getValue( propertyKey, defaultValue );
94 }
95
96 public boolean confirmConfiguration( ArchetypeConfiguration archetypeConfiguration )
97 throws
98 PrompterException
99 {
100 String query = "Confirm archetype configuration:\n";
101 query += Constants.ARCHETYPE_GROUP_ID + "=" + archetypeConfiguration.getGroupId() + "\n";
102 query +=
103 Constants.ARCHETYPE_ARTIFACT_ID + "=" + archetypeConfiguration.getArtifactId() + "\n";
104 query += Constants.ARCHETYPE_VERSION + "=" + archetypeConfiguration.getVersion() + "\n";
105
106 Iterator propertiesIter = archetypeConfiguration.getProperties().keySet().iterator();
107
108 while ( propertiesIter.hasNext() )
109 {
110 String property = (String) propertiesIter.next();
111 query += property + "=" + archetypeConfiguration.getProperty( property ) + "\n";
112 }
113
114 String answer = prompter.prompt( query, "Y" );
115
116 return "Y".equalsIgnoreCase( answer );
117 }
118
119 public String getGroupId( String defaultValue )
120 throws
121 PrompterException
122 {
123 return getValue( Constants.GROUP_ID, defaultValue );
124 }
125
126 public String getPackage( String defaultValue )
127 throws
128 PrompterException
129 {
130 return getValue( Constants.PACKAGE, defaultValue );
131 }
132
133 public String getVersion( String defaultValue )
134 throws
135 PrompterException
136 {
137 return getValue( Constants.VERSION, defaultValue );
138 }
139
140 private String getValue( String requiredProperty,
141 String defaultValue )
142 throws
143 PrompterException
144 {
145 String query = "Define value for " + requiredProperty + ": ";
146 String answer;
147
148 if ( ( defaultValue != null ) && !defaultValue.equals( "null" ) )
149 {
150 answer = prompter.prompt( query, defaultValue );
151 }
152 else
153 {
154 answer = prompter.prompt( query );
155 }
156 return answer;
157 }
158 }