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
208
209
210
211 public Map getParameterMap()
212 {
213 if ( parameterMap == null )
214 {
215 parameterMap = new HashMap();
216
217 if ( parameters != null )
218 {
219 for ( Iterator iterator = parameters.iterator(); iterator.hasNext(); )
220 {
221 Parameter pd = (Parameter) iterator.next();
222
223 parameterMap.put( pd.getName(), pd );
224 }
225 }
226 }
227
228 return parameterMap;
229 }
230
231
232
233
234
235
236
237
238 public void setDependencyResolutionRequired( String requiresDependencyResolution )
239 {
240 this.dependencyResolutionRequired = requiresDependencyResolution;
241 }
242
243
244
245
246
247 public String isDependencyResolutionRequired()
248 {
249 return dependencyResolutionRequired;
250 }
251
252
253
254
255
256
257
258
259 public void setProjectRequired( boolean requiresProject )
260 {
261 this.projectRequired = requiresProject;
262 }
263
264
265
266
267 public boolean isProjectRequired()
268 {
269 return projectRequired;
270 }
271
272
273
274
275
276
277
278
279 public void setOnlineRequired( boolean requiresOnline )
280 {
281 this.onlineRequired = requiresOnline;
282 }
283
284
285
286
287
288
289 public boolean isOnlineRequired()
290 {
291 return onlineRequired;
292 }
293
294
295
296
297
298 public boolean requiresOnline()
299 {
300 return onlineRequired;
301 }
302
303
304
305
306 public String getPhase()
307 {
308 return phase;
309 }
310
311
312
313
314 public void setPhase( String phase )
315 {
316 this.phase = phase;
317 }
318
319
320
321
322 public String getSince()
323 {
324 return since;
325 }
326
327
328
329
330 public void setSince( String since )
331 {
332 this.since = since;
333 }
334
335
336
337
338 public String getGoal()
339 {
340 return goal;
341 }
342
343
344
345
346 public void setGoal( String goal )
347 {
348 this.goal = goal;
349 }
350
351
352
353
354 public String getExecutePhase()
355 {
356 return executePhase;
357 }
358
359
360
361
362 public void setExecutePhase( String executePhase )
363 {
364 this.executePhase = executePhase;
365 }
366
367
368
369
370 public boolean alwaysExecute()
371 {
372 return MULTI_PASS_EXEC_STRATEGY.equals( executionStrategy );
373 }
374
375
376
377
378 public String getExecutionStrategy()
379 {
380 return executionStrategy;
381 }
382
383
384
385
386 public void setExecutionStrategy( String executionStrategy )
387 {
388 this.executionStrategy = executionStrategy;
389 }
390
391
392
393
394 public PlexusConfiguration getMojoConfiguration()
395 {
396 if ( mojoConfiguration == null )
397 {
398 mojoConfiguration = new XmlPlexusConfiguration( "configuration" );
399 }
400 return mojoConfiguration;
401 }
402
403
404
405
406 public void setMojoConfiguration( PlexusConfiguration mojoConfiguration )
407 {
408 this.mojoConfiguration = mojoConfiguration;
409 }
410
411
412 public String getRole()
413 {
414 return Mojo.ROLE;
415 }
416
417
418 public String getRoleHint()
419 {
420 return getId();
421 }
422
423
424
425
426 public String getId()
427 {
428 return getPluginDescriptor().getId() + ":" + getGoal();
429 }
430
431
432
433
434
435
436 public String getFullGoalName()
437 {
438 return getPluginDescriptor().getGoalPrefix() + ":" + getGoal();
439 }
440
441
442 public String getComponentType()
443 {
444 return MAVEN_PLUGIN;
445 }
446
447
448
449
450 public PluginDescriptor getPluginDescriptor()
451 {
452 return pluginDescriptor;
453 }
454
455
456
457
458 public void setPluginDescriptor( PluginDescriptor pluginDescriptor )
459 {
460 this.pluginDescriptor = pluginDescriptor;
461 }
462
463
464
465
466 public boolean isInheritedByDefault()
467 {
468 return inheritedByDefault;
469 }
470
471
472
473
474 public void setInheritedByDefault( boolean inheritedByDefault )
475 {
476 this.inheritedByDefault = inheritedByDefault;
477 }
478
479
480 public boolean equals( Object object )
481 {
482 if ( this == object )
483 {
484 return true;
485 }
486
487 if ( object instanceof MojoDescriptor )
488 {
489 MojoDescriptor other = (MojoDescriptor) object;
490
491 if ( !compareObjects( getPluginDescriptor(), other.getPluginDescriptor() ) )
492 {
493 return false;
494 }
495
496 if ( !compareObjects( getGoal(), other.getGoal() ) )
497 {
498 return false;
499 }
500
501 return true;
502 }
503
504 return false;
505 }
506
507 private boolean compareObjects( Object first, Object second )
508 {
509 if ( ( first == null && second != null ) || ( first != null && second == null ) )
510 {
511 return false;
512 }
513
514 if ( !first.equals( second ) )
515 {
516 return false;
517 }
518
519 return true;
520 }
521
522
523 public int hashCode()
524 {
525 int result = 1;
526
527 String goal = getGoal();
528
529 if ( goal != null )
530 {
531 result += goal.hashCode();
532 }
533
534 PluginDescriptor pd = getPluginDescriptor();
535
536 if ( pd != null )
537 {
538 result -= pd.hashCode();
539 }
540
541 return result;
542 }
543
544
545
546
547 public String getExecuteLifecycle()
548 {
549 return executeLifecycle;
550 }
551
552
553
554
555 public void setExecuteLifecycle( String executeLifecycle )
556 {
557 this.executeLifecycle = executeLifecycle;
558 }
559
560
561
562
563 public void setAggregator( boolean aggregator )
564 {
565 this.aggregator = aggregator;
566 }
567
568
569
570
571 public boolean isAggregator()
572 {
573 return aggregator;
574 }
575
576
577
578
579 public boolean isDirectInvocationOnly()
580 {
581 return directInvocationOnly;
582 }
583
584
585
586
587 public void setDirectInvocationOnly( boolean directInvocationOnly )
588 {
589 this.directInvocationOnly = directInvocationOnly;
590 }
591
592
593
594
595 public boolean isRequiresReports()
596 {
597 return requiresReports;
598 }
599
600
601
602
603 public void setRequiresReports( boolean requiresReports )
604 {
605 this.requiresReports = requiresReports;
606 }
607
608
609
610
611 public void setExecuteGoal( String executeGoal )
612 {
613 this.executeGoal = executeGoal;
614 }
615
616
617
618
619 public String getExecuteGoal()
620 {
621 return executeGoal;
622 }
623 }