1 package org.apache.maven.plugin.coreit;
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.plugin.AbstractMojo;
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.codehaus.plexus.configuration.PlexusConfiguration;
25
26 import java.io.File;
27 import java.net.URI;
28 import java.net.URL;
29 import java.util.Date;
30 import java.util.List;
31 import java.util.Map;
32 import java.util.Properties;
33 import java.util.Set;
34
35
36
37
38
39
40
41
42
43 public class ConfigMojo
44 extends AbstractMojo
45 {
46
47
48
49
50
51
52
53 private File basedir;
54
55
56
57
58
59
60 private File propertiesFile;
61
62
63
64
65
66
67 private String aliasParam;
68
69
70
71
72
73
74 private String defaultParam;
75
76
77
78
79
80
81 private String defaultParamWithExpression;
82
83
84
85
86
87
88 private String aliasDefaultExpressionParam;
89
90
91
92
93
94
95 private Boolean booleanParam;
96
97
98
99
100
101
102 private boolean primitiveBooleanParam;
103
104
105
106
107
108
109 private Byte byteParam;
110
111
112
113
114
115
116 private Short shortParam;
117
118
119
120
121
122
123 private Integer integerParam;
124
125
126
127
128
129
130 private int primitiveIntegerParam;
131
132
133
134
135
136
137 private Long longParam;
138
139
140
141
142
143
144 private Float floatParam;
145
146
147
148
149
150
151 private Double doubleParam;
152
153
154
155
156
157
158 private Character characterParam;
159
160
161
162
163
164
165 private String stringParam;
166
167
168
169
170
171
172 private File fileParam;
173
174
175
176
177
178
179 private Date dateParam;
180
181
182
183
184
185
186 private URL urlParam;
187
188
189
190
191
192
193 private URI uriParam;
194
195
196
197
198
199
200 private String[] stringParams;
201
202
203
204
205
206
207 private File[] fileParams;
208
209
210
211
212
213
214 private List listParam;
215
216
217
218
219
220
221 private Set setParam;
222
223
224
225
226
227
228 private Map mapParam;
229
230
231
232
233
234
235 private Properties propertiesParam;
236
237
238
239
240
241
242 private String[] aliasStringParams;
243
244
245
246
247
248
249 private Bean beanParam;
250
251
252
253
254
255
256 private PlexusConfiguration domParam;
257
258
259
260
261
262
263 public void execute()
264 throws MojoExecutionException
265 {
266 getLog().info( "[MAVEN-CORE-IT-LOG] Using output file path: " + propertiesFile );
267
268 if ( propertiesFile == null )
269 {
270 throw new MojoExecutionException( "Path name for output file has not been specified" );
271 }
272
273 if ( !propertiesFile.isAbsolute() )
274 {
275 propertiesFile = new File( basedir, propertiesFile.getPath() ).getAbsoluteFile();
276 }
277
278 Properties configProps = new Properties();
279
280 dumpConfiguration( configProps );
281
282 getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file: " + propertiesFile );
283
284 PropertiesUtil.write( propertiesFile, configProps );
285
286 getLog().info( "[MAVEN-CORE-IT-LOG] Created output file: " + propertiesFile );
287 }
288
289
290
291
292
293
294 private void dumpConfiguration( Properties props )
295 {
296
297
298
299
300 PropertiesUtil.serialize( props, "propertiesFile", propertiesFile );
301 PropertiesUtil.serialize( props, "aliasParam", aliasParam );
302 PropertiesUtil.serialize( props, "defaultParam", defaultParam );
303 PropertiesUtil.serialize( props, "defaultParamWithExpression", defaultParamWithExpression );
304 PropertiesUtil.serialize( props, "aliasDefaultExpressionParam", aliasDefaultExpressionParam );
305 PropertiesUtil.serialize( props, "booleanParam", booleanParam );
306 if ( primitiveBooleanParam )
307 {
308 PropertiesUtil.serialize( props, "primitiveBooleanParam", primitiveBooleanParam );
309 }
310 PropertiesUtil.serialize( props, "byteParam", byteParam );
311 PropertiesUtil.serialize( props, "shortParam", shortParam );
312 PropertiesUtil.serialize( props, "integerParam", integerParam );
313 if ( primitiveIntegerParam != 0 )
314 {
315 PropertiesUtil.serialize( props, "primitiveIntegerParam", primitiveIntegerParam );
316 }
317 PropertiesUtil.serialize( props, "longParam", longParam );
318 PropertiesUtil.serialize( props, "floatParam", floatParam );
319 PropertiesUtil.serialize( props, "doubleParam", doubleParam );
320 PropertiesUtil.serialize( props, "characterParam", characterParam );
321 PropertiesUtil.serialize( props, "stringParam", stringParam );
322 PropertiesUtil.serialize( props, "fileParam", fileParam );
323 PropertiesUtil.serialize( props, "dateParam", dateParam );
324 PropertiesUtil.serialize( props, "urlParam", urlParam );
325 PropertiesUtil.serialize( props, "uriParam", uriParam );
326 PropertiesUtil.serialize( props, "stringParams", stringParams );
327 PropertiesUtil.serialize( props, "fileParams", fileParams );
328 PropertiesUtil.serialize( props, "listParam", listParam );
329 PropertiesUtil.serialize( props, "setParam", setParam );
330 PropertiesUtil.serialize( props, "mapParam", mapParam );
331 PropertiesUtil.serialize( props, "propertiesParam", propertiesParam );
332 PropertiesUtil.serialize( props, "aliasStringParams", aliasStringParams );
333 PropertiesUtil.serialize( props, "domParam", domParam );
334 if ( beanParam != null )
335 {
336 PropertiesUtil.serialize( props, "beanParam.fieldParam", beanParam.fieldParam );
337 PropertiesUtil.serialize( props, "beanParam.setterParam", beanParam.setterParam );
338 PropertiesUtil.serialize( props, "beanParam.setterCalled", beanParam.setterCalled );
339 }
340 }
341
342 }