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