1 package com.soebes.maven.plugins.iterator;
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.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Properties;
28
29 import org.apache.maven.plugins.annotations.Parameter;
30 import org.apache.maven.project.MavenProject;
31 import org.apache.maven.shared.invoker.DefaultInvocationRequest;
32 import org.apache.maven.shared.invoker.InvocationRequest;
33
34
35
36
37 public abstract class AbstractInvokerMojo
38 extends AbstractIteratorMojo
39 {
40
41
42
43
44
45 @Parameter
46 private List<String> goals = Collections.singletonList( "clean" );
47
48
49
50
51 @Parameter( defaultValue = "false" )
52 private boolean interactive;
53
54
55
56
57 @Parameter( defaultValue = "false" )
58 private boolean alsoMake;
59
60
61
62
63 @Parameter( defaultValue = "false" )
64 private boolean alsoMakeDependents;
65
66
67
68
69
70
71 @Parameter
72 private File baseDirectory;
73
74
75
76
77 @Parameter( defaultValue = "false" )
78 private boolean debug;
79
80
81
82
83
84
85
86
87
88 @Parameter( defaultValue = InvocationRequest.REACTOR_FAIL_FAST )
89 private String failureBehaviour;
90
91
92
93
94
95
96
97
98 @Parameter( defaultValue = InvocationRequest.CHECKSUM_POLICY_WARN )
99 private String globalChecksumPolicy;
100
101
102
103
104
105 @Parameter
106 private File globalSettingsFile;
107
108
109
110
111 @Parameter
112 private File localRepositoryDirectory;
113
114
115
116
117 @Parameter
118 private String mavenOpts;
119
120
121
122
123 @Parameter
124 private boolean nonPluginUpdates;
125
126
127
128
129 @Parameter
130 private boolean offline;
131
132
133
134
135 @Parameter
136 private List<String> profiles;
137
138
139
140
141 @Parameter
142 private List<String> projects;
143
144
145
146
147 @Parameter
148 private Properties properties;
149
150
151
152
153
154 @Parameter( defaultValue = "false" )
155 private boolean recursive;
156
157
158
159
160 @Parameter
161 private String resumeFrom;
162
163
164
165
166
167 @Parameter( defaultValue = "true" )
168 private boolean shellEnvironmentInherited;
169
170
171
172
173
174 @Parameter( defaultValue = "false" )
175 private boolean showErrors;
176
177
178
179
180 @Parameter( defaultValue = "false" )
181 private boolean showVersion;
182
183
184
185
186 @Parameter
187 protected String threads;
188
189
190
191
192 @Parameter
193 private File toolchains;
194
195
196
197
198
199 @Parameter( defaultValue = "false" )
200 private boolean updateSnapshots;
201
202
203
204
205 @Parameter
206 private File userSettings;
207
208 private File getBaseDirectoryAfterPlaceHolderIsReplaced( String currentValue )
209 {
210 File baseDir = getBaseDirectory();
211 if ( baseDir != null && baseDir.toString().contains( getPlaceHolder() ) )
212 {
213 baseDir = new File( baseDir.toString().replaceAll( getPlaceHolder(), currentValue ) );
214 }
215 return baseDir;
216 }
217
218 private List<String> replacePlaceholderInElements( String currentValue, List<String> goals )
219 {
220 List<String> result = new ArrayList<String>();
221 for ( String string : goals )
222 {
223 if ( string.contains( getPlaceHolder() ) )
224 {
225 result.add( string.replaceAll( getPlaceHolder(), currentValue ) );
226 }
227 else
228 {
229 result.add( string );
230 }
231 }
232 return result;
233 }
234
235 private List<String> getGoalsAfterPlaceHolderIsReplaced( String currentValue )
236 {
237 List<String> goals = getGoals();
238 if ( goals == null )
239 {
240 return null;
241 }
242
243 List<String> result = replacePlaceholderInElements( currentValue, goals );
244 return result;
245 }
246
247 private List<String> getProfilesAfterPlaceHolderIsReplaced( String currentValue )
248 {
249 List<String> profiles = getProfiles();
250 if ( profiles == null )
251 {
252 return null;
253 }
254
255 List<String> result = replacePlaceholderInElements( currentValue, profiles );
256 return result;
257 }
258
259 private List<String> getProjectsAfterPlaceHolderIsReplaced( String currentValue )
260 {
261 List<String> projects = getProjects();
262 if ( projects == null )
263 {
264 return null;
265 }
266
267 List<String> result = replacePlaceholderInElements( currentValue, projects );
268 return result;
269 }
270
271 protected InvocationRequest createAndConfigureAnInvocationRequest( ItemWithProperties currentValue )
272 {
273 InvocationRequest request = new DefaultInvocationRequest();
274
275 request.setAlsoMake( isAlsoMake() );
276 request.setAlsoMakeDependents( isAlsoMakeDependents() );
277 request.setDebug( isDebug() );
278 request.setFailureBehavior( getFailureBehaviour() );
279 request.setGlobalChecksumPolicy( getGlobalChecksumPolicy() );
280 request.setGlobalSettingsFile( getGlobalSettingsFile() );
281 request.setInteractive( isInteractive() );
282
283 request.setLocalRepositoryDirectory( getLocalRepositoryDirectory() );
284 request.setMavenOpts( getMavenOpts() );
285 request.setNonPluginUpdates( isNonPluginUpdates() );
286 request.setOffline( isOffline() );
287
288
289
290
291
292
293
294
295
296
297
298
299 request.setBaseDirectory( getBaseDirectoryAfterPlaceHolderIsReplaced( currentValue.getName() ) );
300
301
302
303 request.setGoals( getGoalsAfterPlaceHolderIsReplaced( currentValue.getName() ) );
304
305
306
307 request.setProfiles( getProfilesAfterPlaceHolderIsReplaced( currentValue.getName() ) );
308
309
310 request.setProjects( getProjectsAfterPlaceHolderIsReplaced( currentValue.getName() ) );
311
312 Properties props = getMergedProperties(currentValue );
313 request.setProperties( props );
314
315 request.setRecursive( isRecursive() );
316 request.setResumeFrom( getResumeFrom() );
317 request.setShellEnvironmentInherited( isShellEnvironmentInherited() );
318 request.setShowErrors( isShowErrors() );
319 request.setShowVersion( isShowVersion() );
320 request.setThreads( getThreads() );
321 request.setToolchainsFile( getToolchains() );
322 request.setUpdateSnapshots( isUpdateSnapshots() );
323 request.setUserSettingsFile( getUserSettings() );
324
325 return request;
326 }
327
328 private Properties getMergedProperties( ItemWithProperties item )
329 {
330 Properties props = new Properties();
331 if ( getMavenProject().getProperties() != null )
332 {
333 props.putAll( getMavenProject().getProperties() );
334 }
335
336 if ( getProperties() != null )
337 {
338 props.putAll( getProperties() );
339 }
340
341 if ( item.getProperties() != null )
342 {
343 props.putAll( item.getProperties() );
344 }
345
346 for ( Map.Entry<Object, Object> property : props.entrySet() )
347 {
348 String key = (String) property.getKey();
349 String systemPropertyValue = System.getProperty( key );
350
351 if ( systemPropertyValue != null )
352 {
353 props.put( key, systemPropertyValue );
354 }
355 }
356
357 return props;
358 }
359
360 public List<String> getGoals()
361 {
362 return goals;
363 }
364
365 public boolean isInteractive()
366 {
367 return interactive;
368 }
369
370 public void setInteractive( boolean interactive )
371 {
372 this.interactive = interactive;
373 }
374
375 public boolean isAlsoMake()
376 {
377 return alsoMake;
378 }
379
380 public void setAlsoMake( boolean alsoMake )
381 {
382 this.alsoMake = alsoMake;
383 }
384
385 public boolean isAlsoMakeDependents()
386 {
387 return alsoMakeDependents;
388 }
389
390 public void setAlsoMakeDependents( boolean alsoMakeDependents )
391 {
392 this.alsoMakeDependents = alsoMakeDependents;
393 }
394
395 public File getBaseDirectory()
396 {
397 return baseDirectory;
398 }
399
400 public void setBaseDirectory( File baseDirectory )
401 {
402 this.baseDirectory = baseDirectory;
403 }
404
405 public boolean isDebug()
406 {
407 return debug;
408 }
409
410 public void setDebug( boolean debug )
411 {
412 this.debug = debug;
413 }
414
415 public String getFailureBehaviour()
416 {
417 return failureBehaviour;
418 }
419
420 public void setFailureBehaviour( String failureBehaviour )
421 {
422 this.failureBehaviour = failureBehaviour;
423 }
424
425 public String getGlobalChecksumPolicy()
426 {
427 return globalChecksumPolicy;
428 }
429
430 public void setGlobalChecksumPolicy( String globalChecksumPolicy )
431 {
432 this.globalChecksumPolicy = globalChecksumPolicy;
433 }
434
435 public File getGlobalSettingsFile()
436 {
437 return globalSettingsFile;
438 }
439
440 public void setGlobalSettingsFile( File globalSettingsFile )
441 {
442 this.globalSettingsFile = globalSettingsFile;
443 }
444
445 public File getLocalRepositoryDirectory()
446 {
447 return localRepositoryDirectory;
448 }
449
450 public void setLocalRepositoryDirectory( File localRepositoryDirectory )
451 {
452 this.localRepositoryDirectory = localRepositoryDirectory;
453 }
454
455 public String getMavenOpts()
456 {
457 return mavenOpts;
458 }
459
460 public void setMavenOpts( String mavenOpts )
461 {
462 this.mavenOpts = mavenOpts;
463 }
464
465 public boolean isNonPluginUpdates()
466 {
467 return nonPluginUpdates;
468 }
469
470 public void setNonPluginUpdates( boolean nonPluginUpdates )
471 {
472 this.nonPluginUpdates = nonPluginUpdates;
473 }
474
475 public boolean isOffline()
476 {
477 return offline;
478 }
479
480 public void setOffline( boolean offline )
481 {
482 this.offline = offline;
483 }
484
485 public List<String> getProfiles()
486 {
487 return profiles;
488 }
489
490 public void setProfiles( List<String> profiles )
491 {
492 this.profiles = profiles;
493 }
494
495 public List<String> getProjects()
496 {
497 return projects;
498 }
499
500 public void setProjects( List<String> projects )
501 {
502 this.projects = projects;
503 }
504
505 public Properties getProperties()
506 {
507 return properties;
508 }
509
510 public void setProperties( Properties properties )
511 {
512 this.properties = properties;
513 }
514
515 public boolean isRecursive()
516 {
517 return recursive;
518 }
519
520 public void setRecursive( boolean recursive )
521 {
522 this.recursive = recursive;
523 }
524
525 public String getResumeFrom()
526 {
527 return resumeFrom;
528 }
529
530 public void setResumeFrom( String resumeFrom )
531 {
532 this.resumeFrom = resumeFrom;
533 }
534
535 public boolean isShellEnvironmentInherited()
536 {
537 return shellEnvironmentInherited;
538 }
539
540 public void setShellEnvironmentInherited( boolean shellEnvironmentInherited )
541 {
542 this.shellEnvironmentInherited = shellEnvironmentInherited;
543 }
544
545 public boolean isShowErrors()
546 {
547 return showErrors;
548 }
549
550 public void setShowErrors( boolean showErrors )
551 {
552 this.showErrors = showErrors;
553 }
554
555 public boolean isShowVersion()
556 {
557 return showVersion;
558 }
559
560 public void setShowVersion( boolean showVersion )
561 {
562 this.showVersion = showVersion;
563 }
564
565 public String getThreads()
566 {
567 return threads;
568 }
569
570 public File getToolchains()
571 {
572 return toolchains;
573 }
574
575 public void setToolchains( File toolchains )
576 {
577 this.toolchains = toolchains;
578 }
579
580 public boolean isUpdateSnapshots()
581 {
582 return updateSnapshots;
583 }
584
585 public void setUpdateSnapshots( boolean updateSnapshots )
586 {
587 this.updateSnapshots = updateSnapshots;
588 }
589
590 public File getUserSettings()
591 {
592 return userSettings;
593 }
594
595 public void setUserSettings( File userSettings )
596 {
597 this.userSettings = userSettings;
598 }
599
600 public void setGoals( List<String> goals )
601 {
602 this.goals = goals;
603 }
604
605 }