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