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