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