1 package org.apache.maven.plugin.descriptor;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.LinkedHashMap;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.Objects;
27
28 import org.apache.maven.plugin.Mojo;
29 import org.codehaus.plexus.component.repository.ComponentDescriptor;
30 import org.codehaus.plexus.configuration.PlexusConfiguration;
31 import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
32
33
34
35
36
37
38
39
40
41
42 public class MojoDescriptor
43 extends ComponentDescriptor<Mojo>
44 implements Cloneable
45 {
46
47 public static final String MAVEN_PLUGIN = "maven-plugin";
48
49
50 public static final String SINGLE_PASS_EXEC_STRATEGY = "once-per-session";
51
52
53 public static final String MULTI_PASS_EXEC_STRATEGY = "always";
54
55 private static final String DEFAULT_INSTANTIATION_STRATEGY = "per-lookup";
56
57 private static final String DEFAULT_LANGUAGE = "java";
58
59 private final ArrayList<Parameter> parameters;
60
61
62 private String executionStrategy = SINGLE_PASS_EXEC_STRATEGY;
63
64
65
66
67
68 private String goal;
69
70
71
72
73
74
75
76 private String phase;
77
78
79 private String since;
80
81
82 private String executePhase;
83
84
85 private String executeGoal;
86
87
88 private String executeLifecycle;
89
90
91
92
93
94 private String deprecated;
95
96
97
98
99
100 private boolean aggregator = false;
101
102
103
104
105
106
107 private String dependencyResolutionRequired = null;
108
109
110
111
112
113 private String dependencyCollectionRequired;
114
115
116 private boolean projectRequired = true;
117
118
119 private boolean onlineRequired = false;
120
121
122 private PlexusConfiguration mojoConfiguration;
123
124
125 private PluginDescriptor pluginDescriptor;
126
127
128 private boolean inheritedByDefault = true;
129
130
131 private boolean directInvocationOnly = false;
132
133
134 private boolean requiresReports = false;
135
136
137
138
139
140 private boolean threadSafe = false;
141
142
143
144
145 public MojoDescriptor()
146 {
147 this.parameters = new ArrayList<>();
148 setInstantiationStrategy( DEFAULT_INSTANTIATION_STRATEGY );
149 setComponentFactory( DEFAULT_LANGUAGE );
150 }
151
152
153
154
155
156
157
158
159 public String getLanguage()
160 {
161 return getComponentFactory();
162 }
163
164
165
166
167 public void setLanguage( String language )
168 {
169 setComponentFactory( language );
170 }
171
172
173
174
175 public String getDeprecated()
176 {
177 return deprecated;
178 }
179
180
181
182
183 public void setDeprecated( String deprecated )
184 {
185 this.deprecated = deprecated;
186 }
187
188
189
190
191
192 public List<Parameter> getParameters()
193 {
194 return new ArrayList<>( parameters );
195 }
196
197
198
199
200
201 public void setParameters( List<Parameter> parameters )
202 throws DuplicateParameterException
203 {
204 this.parameters.clear();
205 for ( Parameter parameter : parameters )
206 {
207 addParameter( parameter );
208 }
209 }
210
211
212
213
214
215 public void addParameter( Parameter parameter )
216 throws DuplicateParameterException
217 {
218 if ( parameters.contains( parameter ) )
219 {
220 throw new DuplicateParameterException( parameter.getName()
221 + " has been declared multiple times in mojo with goal: " + getGoal() + " (implementation: "
222 + getImplementation() + ")" );
223 }
224
225 parameters.add( parameter );
226 }
227
228
229
230
231
232
233 public Map<String, Parameter> getParameterMap()
234 {
235 LinkedHashMap<String, Parameter> parameterMap = new LinkedHashMap<>();
236
237 for ( Parameter pd : parameters )
238 {
239 parameterMap.put( pd.getName(), pd );
240 }
241
242 return parameterMap;
243 }
244
245
246
247
248
249
250
251
252 public void setDependencyResolutionRequired( String requiresDependencyResolution )
253 {
254 this.dependencyResolutionRequired = requiresDependencyResolution;
255 }
256
257 public String getDependencyResolutionRequired()
258 {
259 return dependencyResolutionRequired;
260 }
261
262
263
264
265
266 @Deprecated
267 public String isDependencyResolutionRequired()
268 {
269 return dependencyResolutionRequired;
270 }
271
272
273
274
275 public void setDependencyCollectionRequired( String requiresDependencyCollection )
276 {
277 this.dependencyCollectionRequired = requiresDependencyCollection;
278 }
279
280
281
282
283
284
285
286
287
288
289
290 public String getDependencyCollectionRequired()
291 {
292 return dependencyCollectionRequired;
293 }
294
295
296
297
298
299
300
301
302
303 public void setProjectRequired( boolean requiresProject )
304 {
305 this.projectRequired = requiresProject;
306 }
307
308
309
310
311 public boolean isProjectRequired()
312 {
313 return projectRequired;
314 }
315
316
317
318
319
320
321
322
323 public void setOnlineRequired( boolean requiresOnline )
324 {
325 this.onlineRequired = requiresOnline;
326 }
327
328
329
330
331
332
333 public boolean isOnlineRequired()
334 {
335 return onlineRequired;
336 }
337
338
339
340
341
342 public boolean requiresOnline()
343 {
344 return onlineRequired;
345 }
346
347
348
349
350 public String getPhase()
351 {
352 return phase;
353 }
354
355
356
357
358 public void setPhase( String phase )
359 {
360 this.phase = phase;
361 }
362
363
364
365
366 public String getSince()
367 {
368 return since;
369 }
370
371
372
373
374 public void setSince( String since )
375 {
376 this.since = since;
377 }
378
379
380
381
382 public String getGoal()
383 {
384 return goal;
385 }
386
387
388
389
390 public void setGoal( String goal )
391 {
392 this.goal = goal;
393 }
394
395
396
397
398 public String getExecutePhase()
399 {
400 return executePhase;
401 }
402
403
404
405
406 public void setExecutePhase( String executePhase )
407 {
408 this.executePhase = executePhase;
409 }
410
411
412
413
414 public boolean alwaysExecute()
415 {
416 return MULTI_PASS_EXEC_STRATEGY.equals( executionStrategy );
417 }
418
419
420
421
422 public String getExecutionStrategy()
423 {
424 return executionStrategy;
425 }
426
427
428
429
430 public void setExecutionStrategy( String executionStrategy )
431 {
432 this.executionStrategy = executionStrategy;
433 }
434
435
436
437
438 public PlexusConfiguration getMojoConfiguration()
439 {
440 if ( mojoConfiguration == null )
441 {
442 mojoConfiguration = new XmlPlexusConfiguration( "configuration" );
443 }
444 return mojoConfiguration;
445 }
446
447
448
449
450 public void setMojoConfiguration( PlexusConfiguration mojoConfiguration )
451 {
452 this.mojoConfiguration = mojoConfiguration;
453 }
454
455
456 public String getRole()
457 {
458 return Mojo.ROLE;
459 }
460
461
462 public String getRoleHint()
463 {
464 return getId();
465 }
466
467
468
469
470 public String getId()
471 {
472 return getPluginDescriptor().getId() + ":" + getGoal();
473 }
474
475
476
477
478
479
480 public String getFullGoalName()
481 {
482 return getPluginDescriptor().getGoalPrefix() + ":" + getGoal();
483 }
484
485
486 public String getComponentType()
487 {
488 return MAVEN_PLUGIN;
489 }
490
491
492
493
494 public PluginDescriptor getPluginDescriptor()
495 {
496 return pluginDescriptor;
497 }
498
499
500
501
502 public void setPluginDescriptor( PluginDescriptor pluginDescriptor )
503 {
504 this.pluginDescriptor = pluginDescriptor;
505 }
506
507
508
509
510 public boolean isInheritedByDefault()
511 {
512 return inheritedByDefault;
513 }
514
515
516
517
518 public void setInheritedByDefault( boolean inheritedByDefault )
519 {
520 this.inheritedByDefault = inheritedByDefault;
521 }
522
523
524 public boolean equals( Object object )
525 {
526 if ( this == object )
527 {
528 return true;
529 }
530
531 if ( object instanceof MojoDescriptor )
532 {
533 MojoDescriptor other = (MojoDescriptor) object;
534
535 return Objects.equals( getPluginDescriptor(), other.getPluginDescriptor() )
536 && Objects.equals( getGoal(), other.getGoal() );
537 }
538
539 return false;
540 }
541
542
543 public int hashCode()
544 {
545 return Objects.hash( getGoal(), getPluginDescriptor() );
546 }
547
548
549
550
551 public String getExecuteLifecycle()
552 {
553 return executeLifecycle;
554 }
555
556
557
558
559 public void setExecuteLifecycle( String executeLifecycle )
560 {
561 this.executeLifecycle = executeLifecycle;
562 }
563
564
565
566
567
568 public void setAggregator( boolean aggregator )
569 {
570 this.aggregator = aggregator;
571 }
572
573
574
575
576
577 public boolean isAggregator()
578 {
579 return aggregator;
580 }
581
582
583
584
585 public boolean isDirectInvocationOnly()
586 {
587 return directInvocationOnly;
588 }
589
590
591
592
593
594 public void setDirectInvocationOnly( boolean directInvocationOnly )
595 {
596 this.directInvocationOnly = directInvocationOnly;
597 }
598
599
600
601
602 public boolean isRequiresReports()
603 {
604 return requiresReports;
605 }
606
607
608
609
610 public void setRequiresReports( boolean requiresReports )
611 {
612 this.requiresReports = requiresReports;
613 }
614
615
616
617
618 public void setExecuteGoal( String executeGoal )
619 {
620 this.executeGoal = executeGoal;
621 }
622
623
624
625
626 public String getExecuteGoal()
627 {
628 return executeGoal;
629 }
630
631
632
633
634
635
636 public boolean isThreadSafe()
637 {
638 return threadSafe;
639 }
640
641
642
643
644
645 public void setThreadSafe( boolean threadSafe )
646 {
647 this.threadSafe = threadSafe;
648 }
649
650
651
652
653 public boolean isForking()
654 {
655 return ( getExecuteGoal() != null && getExecuteGoal().length() > 0 )
656 || ( getExecutePhase() != null && getExecutePhase().length() > 0 );
657 }
658
659
660
661
662 @Override
663 public MojoDescriptor clone()
664 {
665 try
666 {
667 return (MojoDescriptor) super.clone();
668 }
669 catch ( CloneNotSupportedException e )
670 {
671 throw new UnsupportedOperationException( e );
672 }
673 }
674
675 }