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 private boolean v4Api = false;
143
144
145
146
147 public MojoDescriptor()
148 {
149 this.parameters = new ArrayList<>();
150 setInstantiationStrategy( DEFAULT_INSTANTIATION_STRATEGY );
151 setComponentFactory( DEFAULT_LANGUAGE );
152 }
153
154
155
156
157
158
159
160
161 public String getLanguage()
162 {
163 return getComponentFactory();
164 }
165
166
167
168
169 public void setLanguage( String language )
170 {
171 setComponentFactory( language );
172 }
173
174
175
176
177 public String getDeprecated()
178 {
179 return deprecated;
180 }
181
182
183
184
185 public void setDeprecated( String deprecated )
186 {
187 this.deprecated = deprecated;
188 }
189
190
191
192
193
194 public List<Parameter> getParameters()
195 {
196 return new ArrayList<>( parameters );
197 }
198
199
200
201
202
203 public void setParameters( List<Parameter> parameters )
204 throws DuplicateParameterException
205 {
206 this.parameters.clear();
207 for ( Parameter parameter : parameters )
208 {
209 addParameter( parameter );
210 }
211 }
212
213
214
215
216
217 public void addParameter( Parameter parameter )
218 throws DuplicateParameterException
219 {
220 if ( parameters.contains( parameter ) )
221 {
222 throw new DuplicateParameterException( parameter.getName()
223 + " has been declared multiple times in mojo with goal: " + getGoal() + " (implementation: "
224 + getImplementation() + ")" );
225 }
226
227 parameters.add( parameter );
228 }
229
230
231
232
233
234
235 public Map<String, Parameter> getParameterMap()
236 {
237 LinkedHashMap<String, Parameter> parameterMap = new LinkedHashMap<>();
238
239 for ( Parameter pd : parameters )
240 {
241 parameterMap.put( pd.getName(), pd );
242 }
243
244 return parameterMap;
245 }
246
247
248
249
250
251
252
253
254 public void setDependencyResolutionRequired( String requiresDependencyResolution )
255 {
256 this.dependencyResolutionRequired = requiresDependencyResolution;
257 }
258
259 public String getDependencyResolutionRequired()
260 {
261 return dependencyResolutionRequired;
262 }
263
264
265
266
267
268 @Deprecated
269 public String isDependencyResolutionRequired()
270 {
271 return dependencyResolutionRequired;
272 }
273
274
275
276
277 public void setDependencyCollectionRequired( String requiresDependencyCollection )
278 {
279 this.dependencyCollectionRequired = requiresDependencyCollection;
280 }
281
282
283
284
285
286
287
288
289
290
291
292 public String getDependencyCollectionRequired()
293 {
294 return dependencyCollectionRequired;
295 }
296
297
298
299
300
301
302
303
304
305 public void setProjectRequired( boolean requiresProject )
306 {
307 this.projectRequired = requiresProject;
308 }
309
310
311
312
313 public boolean isProjectRequired()
314 {
315 return projectRequired;
316 }
317
318
319
320
321
322
323
324
325 public void setOnlineRequired( boolean requiresOnline )
326 {
327 this.onlineRequired = requiresOnline;
328 }
329
330
331
332
333
334
335 public boolean isOnlineRequired()
336 {
337 return onlineRequired;
338 }
339
340
341
342
343
344 public boolean requiresOnline()
345 {
346 return onlineRequired;
347 }
348
349
350
351
352 public String getPhase()
353 {
354 return phase;
355 }
356
357
358
359
360 public void setPhase( String phase )
361 {
362 this.phase = phase;
363 }
364
365
366
367
368 public String getSince()
369 {
370 return since;
371 }
372
373
374
375
376 public void setSince( String since )
377 {
378 this.since = since;
379 }
380
381
382
383
384 public String getGoal()
385 {
386 return goal;
387 }
388
389
390
391
392 public void setGoal( String goal )
393 {
394 this.goal = goal;
395 }
396
397
398
399
400 public String getExecutePhase()
401 {
402 return executePhase;
403 }
404
405
406
407
408 public void setExecutePhase( String executePhase )
409 {
410 this.executePhase = executePhase;
411 }
412
413
414
415
416 public boolean alwaysExecute()
417 {
418 return MULTI_PASS_EXEC_STRATEGY.equals( executionStrategy );
419 }
420
421
422
423
424 public String getExecutionStrategy()
425 {
426 return executionStrategy;
427 }
428
429
430
431
432 public void setExecutionStrategy( String executionStrategy )
433 {
434 this.executionStrategy = executionStrategy;
435 }
436
437
438
439
440 public PlexusConfiguration getMojoConfiguration()
441 {
442 if ( mojoConfiguration == null )
443 {
444 mojoConfiguration = new XmlPlexusConfiguration( "configuration" );
445 }
446 return mojoConfiguration;
447 }
448
449
450
451
452 public void setMojoConfiguration( PlexusConfiguration mojoConfiguration )
453 {
454 this.mojoConfiguration = mojoConfiguration;
455 }
456
457
458 public String getRole()
459 {
460 return isV4Api() ? "org.apache.maven.api.plugin.Mojo" : Mojo.ROLE;
461 }
462
463
464 public String getRoleHint()
465 {
466 return getId();
467 }
468
469
470
471
472 public String getId()
473 {
474 return getPluginDescriptor().getId() + ":" + getGoal();
475 }
476
477
478
479
480
481
482 public String getFullGoalName()
483 {
484 return getPluginDescriptor().getGoalPrefix() + ":" + getGoal();
485 }
486
487
488 public String getComponentType()
489 {
490 return MAVEN_PLUGIN;
491 }
492
493
494
495
496 public PluginDescriptor getPluginDescriptor()
497 {
498 return pluginDescriptor;
499 }
500
501
502
503
504 public void setPluginDescriptor( PluginDescriptor pluginDescriptor )
505 {
506 this.pluginDescriptor = pluginDescriptor;
507 }
508
509
510
511
512 public boolean isInheritedByDefault()
513 {
514 return inheritedByDefault;
515 }
516
517
518
519
520 public void setInheritedByDefault( boolean inheritedByDefault )
521 {
522 this.inheritedByDefault = inheritedByDefault;
523 }
524
525
526 public boolean equals( Object object )
527 {
528 if ( this == object )
529 {
530 return true;
531 }
532
533 if ( object instanceof MojoDescriptor )
534 {
535 MojoDescriptor other = (MojoDescriptor) object;
536
537 return Objects.equals( getPluginDescriptor(), other.getPluginDescriptor() )
538 && Objects.equals( getGoal(), other.getGoal() );
539 }
540
541 return false;
542 }
543
544
545 public int hashCode()
546 {
547 return Objects.hash( getGoal(), getPluginDescriptor() );
548 }
549
550
551
552
553 public String getExecuteLifecycle()
554 {
555 return executeLifecycle;
556 }
557
558
559
560
561 public void setExecuteLifecycle( String executeLifecycle )
562 {
563 this.executeLifecycle = executeLifecycle;
564 }
565
566
567
568
569
570 public void setAggregator( boolean aggregator )
571 {
572 this.aggregator = aggregator;
573 }
574
575
576
577
578
579 public boolean isAggregator()
580 {
581 return aggregator;
582 }
583
584
585
586
587 public boolean isDirectInvocationOnly()
588 {
589 return directInvocationOnly;
590 }
591
592
593
594
595
596 public void setDirectInvocationOnly( boolean directInvocationOnly )
597 {
598 this.directInvocationOnly = directInvocationOnly;
599 }
600
601
602
603
604 public boolean isRequiresReports()
605 {
606 return requiresReports;
607 }
608
609
610
611
612 public void setRequiresReports( boolean requiresReports )
613 {
614 this.requiresReports = requiresReports;
615 }
616
617
618
619
620 public void setExecuteGoal( String executeGoal )
621 {
622 this.executeGoal = executeGoal;
623 }
624
625
626
627
628 public String getExecuteGoal()
629 {
630 return executeGoal;
631 }
632
633
634
635
636
637
638 public boolean isThreadSafe()
639 {
640 return threadSafe;
641 }
642
643
644
645
646
647 public void setThreadSafe( boolean threadSafe )
648 {
649 this.threadSafe = threadSafe;
650 }
651
652
653
654
655 public boolean isForking()
656 {
657 return ( getExecuteGoal() != null && getExecuteGoal().length() > 0 )
658 || ( getExecutePhase() != null && getExecutePhase().length() > 0 );
659 }
660
661 public boolean isV4Api()
662 {
663 return v4Api;
664 }
665
666 public void setV4Api( boolean v4Api )
667 {
668 this.v4Api = v4Api;
669 }
670
671
672
673
674 @Override
675 public MojoDescriptor clone()
676 {
677 try
678 {
679 return (MojoDescriptor) super.clone();
680 }
681 catch ( CloneNotSupportedException e )
682 {
683 throw new UnsupportedOperationException( e );
684 }
685 }
686
687 }