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