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 java.util.ArrayList; |
23 | |
import java.util.List; |
24 | |
import java.util.Properties; |
25 | |
|
26 | |
import org.apache.maven.archetype.common.Constants; |
27 | |
import org.codehaus.plexus.util.StringUtils; |
28 | |
|
29 | 10 | public class ArchetypeConfiguration |
30 | |
{ |
31 | |
private String groupId; |
32 | |
|
33 | |
private String artifactId; |
34 | |
|
35 | |
private String version; |
36 | |
|
37 | |
private String name; |
38 | |
|
39 | |
private String goals; |
40 | |
|
41 | |
public String getDescription() |
42 | |
{ |
43 | 0 | return description; |
44 | |
} |
45 | |
|
46 | |
public void setDescription( String description ) |
47 | |
{ |
48 | 6 | this.description = description; |
49 | 6 | } |
50 | |
|
51 | |
public String getUrl() |
52 | |
{ |
53 | 0 | return url; |
54 | |
} |
55 | |
|
56 | |
public void setUrl( String url ) |
57 | |
{ |
58 | 6 | this.url = url; |
59 | 6 | } |
60 | |
|
61 | |
private String url; |
62 | |
|
63 | |
private String description; |
64 | |
|
65 | |
private List<String> requiredProperties; |
66 | |
|
67 | |
public void addRequiredProperty( String string ) |
68 | |
{ |
69 | 32 | getRequiredProperties().add( string ); |
70 | 32 | } |
71 | |
|
72 | |
public String getArtifactId() |
73 | |
{ |
74 | 0 | return artifactId; |
75 | |
} |
76 | |
|
77 | |
public String getGoals() |
78 | |
{ |
79 | 0 | return goals; |
80 | |
} |
81 | |
|
82 | |
public String getGroupId() |
83 | |
{ |
84 | 0 | return groupId; |
85 | |
} |
86 | |
|
87 | |
public String getName() |
88 | |
{ |
89 | 0 | return name; |
90 | |
} |
91 | |
|
92 | |
public List<String> getRequiredProperties() |
93 | |
{ |
94 | 52 | if ( requiredProperties == null ) |
95 | |
{ |
96 | 10 | requiredProperties = new ArrayList<String>(); |
97 | |
} |
98 | |
|
99 | 52 | return requiredProperties; |
100 | |
} |
101 | |
|
102 | |
public String getVersion() |
103 | |
{ |
104 | 0 | return version; |
105 | |
} |
106 | |
|
107 | |
public void removeRequiredProperty( String string ) |
108 | |
{ |
109 | 0 | getRequiredProperties().remove( string ); |
110 | 0 | } |
111 | |
|
112 | |
public void setArtifactId( String artifactId ) |
113 | |
{ |
114 | 6 | this.artifactId = artifactId; |
115 | 6 | } |
116 | |
|
117 | |
public void setGoals( String goals ) |
118 | |
{ |
119 | 0 | this.goals = goals; |
120 | 0 | } |
121 | |
|
122 | |
public void setGroupId( String groupId ) |
123 | |
{ |
124 | 6 | this.groupId = groupId; |
125 | 6 | } |
126 | |
|
127 | |
public void setName( String name ) |
128 | |
{ |
129 | 6 | this.name = name; |
130 | 6 | } |
131 | |
|
132 | |
public void setRequiredProperties( List<String> requiredProperties ) |
133 | |
{ |
134 | 0 | this.requiredProperties = requiredProperties; |
135 | 0 | } |
136 | |
|
137 | |
public void setVersion( String version ) |
138 | |
{ |
139 | 6 | this.version = version; |
140 | 6 | } |
141 | |
|
142 | |
public void reset() |
143 | |
{ |
144 | 0 | properties.clear(); |
145 | 0 | } |
146 | |
|
147 | 10 | private Properties properties = new Properties(); |
148 | |
|
149 | |
public void setProperty( String requiredProperty, String propertyValue ) |
150 | |
{ |
151 | 20 | properties.setProperty( requiredProperty, propertyValue ); |
152 | 20 | } |
153 | |
|
154 | |
public String getProperty( String property ) |
155 | |
{ |
156 | 46 | return properties.getProperty( property, null ); |
157 | |
} |
158 | |
|
159 | |
public Properties getProperties() |
160 | |
{ |
161 | 4 | return properties; |
162 | |
} |
163 | |
|
164 | |
public Properties toProperties() |
165 | |
{ |
166 | 0 | Properties result = new Properties(); |
167 | |
|
168 | 0 | result.putAll( properties ); |
169 | |
|
170 | 0 | result.setProperty( Constants.ARCHETYPE_GROUP_ID, StringUtils.isNotEmpty( getGroupId() ) ? getGroupId() : "" ); |
171 | 0 | result.setProperty( Constants.ARCHETYPE_ARTIFACT_ID, |
172 | |
StringUtils.isNotEmpty( getArtifactId() ) ? getArtifactId() : "" ); |
173 | 0 | result.setProperty( Constants.ARCHETYPE_VERSION, StringUtils.isNotEmpty( getVersion() ) ? getVersion() : "" ); |
174 | |
|
175 | 0 | if ( StringUtils.isNotEmpty( getGoals() ) ) |
176 | |
{ |
177 | 0 | result.setProperty( Constants.ARCHETYPE_POST_GENERATION_GOALS, getGoals() ); |
178 | |
} |
179 | |
|
180 | 0 | return result; |
181 | |
} |
182 | |
|
183 | |
public boolean isConfigured() |
184 | |
{ |
185 | 10 | for ( String requiredProperty : getRequiredProperties() ) |
186 | |
{ |
187 | 26 | if ( StringUtils.isEmpty( properties.getProperty( requiredProperty ) ) ) |
188 | |
{ |
189 | 6 | return false; |
190 | |
} |
191 | |
} |
192 | |
|
193 | 4 | return true; |
194 | |
} |
195 | |
|
196 | |
public boolean isConfigured( String requiredProperties ) |
197 | |
{ |
198 | 24 | return StringUtils.isNotEmpty( properties.getProperty( requiredProperties ) ); |
199 | |
} |
200 | |
|
201 | 10 | private Properties defaultProperties = new Properties(); |
202 | |
|
203 | |
public void setDefaultProperty( String requiredProperty, String propertyValue ) |
204 | |
{ |
205 | 26 | defaultProperties.setProperty( requiredProperty, propertyValue ); |
206 | 26 | } |
207 | |
|
208 | |
public String getDefaultValue( String requiredProperty ) |
209 | |
{ |
210 | 16 | return defaultProperties.getProperty( requiredProperty, null ); |
211 | |
} |
212 | |
|
213 | |
public Properties getDefaultValues() |
214 | |
{ |
215 | 0 | return defaultProperties; |
216 | |
} |
217 | |
} |