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