1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.maven.common;
17
18 import java.io.File;
19 import java.util.ArrayList;
20 import java.util.Hashtable;
21 import java.util.List;
22 import java.util.Properties;
23 import java.util.Set;
24
25 import org.apache.tools.ant.BuildException;
26 import org.apache.tools.ant.Task;
27
28
29
30
31
32 public class MvnTask extends Task implements MvnContext {
33 private static final String FS = File.separator;
34
35 MvnExecutor executor = new MvnExecutor();
36
37 @Override
38 public Properties getProjectProperties() {
39 Hashtable<?, ?> hashTable = getProject().getProperties();
40 Properties properties = new Properties();
41 Set<?> keys = hashTable.keySet();
42 for (Object key : keys) {
43 Object value = hashTable.get(key);
44
45 properties.setProperty(key.toString(), value.toString());
46 }
47 return properties;
48 }
49
50
51
52
53 private File workingDir;
54
55
56
57
58 private File basedir;
59
60
61
62
63
64
65 private String executable;
66
67
68
69
70 private String pom;
71
72
73
74
75 private List<String> poms;
76
77
78
79
80 private boolean filterPom = false;
81
82
83
84
85 private List<String> args = new ArrayList<String>();
86
87
88
89
90 private List<String> properties = new ArrayList<String>();
91
92
93
94
95 private List<String> filterProperties = new ArrayList<String>();
96
97
98
99
100 private boolean addEnvironment = false;
101
102
103
104
105 private boolean addMavenOpts = true;
106
107
108
109
110 private boolean deleteTempPom = true;
111
112
113
114
115 private boolean quiet = true;
116
117
118
119
120 private boolean silent = true;
121
122
123
124
125
126 private boolean failOnError = true;
127
128 public void addConfiguredArg(Arg arg) {
129 args.add(arg.getValue());
130 }
131
132 public void addConfiguredProperty(Property property) {
133 properties.add(property.getKey());
134 }
135
136 protected void configure() {
137 if (workingDir == null) {
138 String filename = getProject().getBaseDir().getAbsolutePath() + FS + "target" + FS + "mvn";
139 workingDir = new File(filename);
140 }
141 if (basedir == null) {
142 basedir = workingDir;
143 }
144 }
145
146 @Override
147 public void execute() throws BuildException {
148 try {
149 configure();
150 executor.execute(this);
151 } catch (Exception e) {
152 throw new BuildException("Error invoking mvn", e);
153 }
154 }
155
156
157
158
159
160
161 @Override
162 public File getWorkingDir() {
163 return workingDir;
164 }
165
166
167
168
169
170
171 @Override
172 public void setWorkingDir(File workingDir) {
173 this.workingDir = workingDir;
174 }
175
176
177
178
179
180
181 @Override
182 public File getBasedir() {
183 return basedir;
184 }
185
186
187
188
189
190
191 @Override
192 public void setBasedir(File basedir) {
193 this.basedir = basedir;
194 }
195
196
197
198
199
200
201 @Override
202 public String getExecutable() {
203 return executable;
204 }
205
206
207
208
209
210
211 @Override
212 public void setExecutable(String executable) {
213 this.executable = executable;
214 }
215
216
217
218
219
220
221 @Override
222 public String getPom() {
223 return pom;
224 }
225
226
227
228
229
230
231 @Override
232 public void setPom(String pom) {
233 this.pom = pom;
234 }
235
236
237
238
239
240
241 @Override
242 public boolean isFilterPom() {
243 return filterPom;
244 }
245
246
247
248
249
250
251 @Override
252 public void setFilterPom(boolean filterPom) {
253 this.filterPom = filterPom;
254 }
255
256
257
258
259
260
261 @Override
262 public List<String> getArgs() {
263 return args;
264 }
265
266
267
268
269
270
271 @Override
272 public void setArgs(List<String> args) {
273 this.args = args;
274 }
275
276
277
278
279
280
281 @Override
282 public List<String> getProperties() {
283 return properties;
284 }
285
286
287
288
289
290
291 @Override
292 public void setProperties(List<String> properties) {
293 this.properties = properties;
294 }
295
296
297
298
299
300
301 @Override
302 public boolean isAddEnvironment() {
303 return addEnvironment;
304 }
305
306
307
308
309
310
311 @Override
312 public void setAddEnvironment(boolean addEnvironment) {
313 this.addEnvironment = addEnvironment;
314 }
315
316
317
318
319
320
321 @Override
322 public boolean isAddMavenOpts() {
323 return addMavenOpts;
324 }
325
326
327
328
329
330
331 @Override
332 public void setAddMavenOpts(boolean addMavenOpts) {
333 this.addMavenOpts = addMavenOpts;
334 }
335
336
337
338
339
340
341 @Override
342 public boolean isFailOnError() {
343 return failOnError;
344 }
345
346
347
348
349
350
351 @Override
352 public void setFailOnError(boolean failOnError) {
353 this.failOnError = failOnError;
354 }
355
356 @Override
357 public boolean isDeleteTempPom() {
358 return deleteTempPom;
359 }
360
361 public void setDeleteTempPom(boolean deleteTempPom) {
362 this.deleteTempPom = deleteTempPom;
363 }
364
365 @Override
366 public List<String> getPoms() {
367 return poms;
368 }
369
370 @Override
371 public void setPoms(List<String> poms) {
372 this.poms = poms;
373 }
374
375 @Override
376 public boolean isQuiet() {
377 return quiet;
378 }
379
380 @Override
381 public void setQuiet(boolean quiet) {
382 this.quiet = quiet;
383 }
384
385 @Override
386 public boolean isSilent() {
387 return silent;
388 }
389
390 @Override
391 public void setSilent(boolean silent) {
392 this.silent = silent;
393 }
394
395 @Override
396 public List<String> getFilterProperties() {
397 return filterProperties;
398 }
399
400 @Override
401 public void setFilterProperties(List<String> filterProperties) {
402 this.filterProperties = filterProperties;
403 }
404
405 }