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