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.util.List;
24 import java.util.Map;
25 import java.util.Properties;
26 import java.util.Set;
27
28 import org.apache.maven.plugin.AbstractMojo;
29 import org.apache.maven.plugin.MojoExecutionException;
30
31
32
33
34
35
36
37
38
39
40
41 public class CustomConfigMojo
42 extends AbstractMojo
43 {
44
45
46
47
48
49
50
51 private File basedir;
52
53
54
55
56
57
58 private File propertiesFile;
59
60
61
62
63
64
65 String customParam;
66
67
68
69
70
71
72
73 private String defaultParam;
74
75
76
77
78
79
80 private String stringParam;
81
82
83
84
85
86
87 private File fileParam;
88
89
90
91
92
93
94 private String[] stringParams;
95
96
97
98
99
100
101 private File[] fileParams;
102
103
104
105
106
107
108 private List listParam;
109
110
111
112
113
114
115 private Set setParam;
116
117
118
119
120
121
122 private Map mapParam;
123
124
125
126
127
128
129 private Properties propertiesParam;
130
131
132
133
134
135
136 public void execute()
137 throws MojoExecutionException
138 {
139 getLog().info( "[MAVEN-CORE-IT-LOG] Using output file path: " + propertiesFile );
140
141 if ( propertiesFile == null )
142 {
143 throw new MojoExecutionException( "Path name for output file has not been specified" );
144 }
145
146 if ( !propertiesFile.isAbsolute() )
147 {
148 propertiesFile = new File( basedir, propertiesFile.getPath() ).getAbsoluteFile();
149 }
150
151 Properties configProps = new Properties();
152
153 dumpConfiguration( configProps );
154
155 getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file: " + propertiesFile );
156
157 PropertiesUtil.write( propertiesFile, configProps );
158
159 getLog().info( "[MAVEN-CORE-IT-LOG] Created output file: " + propertiesFile );
160 }
161
162
163
164
165
166
167 private void dumpConfiguration( Properties props )
168 {
169
170
171
172
173 PropertiesUtil.serialize( props, "propertiesFile", propertiesFile );
174 PropertiesUtil.serialize( props, "customParam", customParam );
175 PropertiesUtil.serialize( props, "defaultParam", defaultParam );
176 PropertiesUtil.serialize( props, "stringParam", stringParam );
177 PropertiesUtil.serialize( props, "fileParam", fileParam );
178 PropertiesUtil.serialize( props, "stringParams", stringParams );
179 PropertiesUtil.serialize( props, "fileParams", fileParams );
180 PropertiesUtil.serialize( props, "listParam", listParam );
181 PropertiesUtil.serialize( props, "setParam", setParam );
182 PropertiesUtil.serialize( props, "mapParam", mapParam );
183 PropertiesUtil.serialize( props, "propertiesParam", propertiesParam );
184 }
185
186 }