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