1
2
3
4
5 package org.apache.maven.api.plugin.descriptor;
6
7 import java.io.Serializable;
8 import java.util.ArrayList;
9 import java.util.Collection;
10 import java.util.Collections;
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14 import java.util.Set;
15 import org.apache.maven.api.annotations.Experimental;
16 import org.apache.maven.api.annotations.Generated;
17 import org.apache.maven.api.annotations.Immutable;
18 import org.apache.maven.api.annotations.Nonnull;
19 import org.apache.maven.api.annotations.NotThreadSafe;
20 import org.apache.maven.api.annotations.ThreadSafe;
21
22
23
24
25 @Experimental
26 @Generated @ThreadSafe @Immutable
27 public class PluginDescriptor
28 implements Serializable
29 {
30 final String namespaceUri;
31 final String modelEncoding;
32
33
34
35 final String name;
36
37
38
39 final String description;
40
41
42
43 final String groupId;
44
45
46
47 final String artifactId;
48
49
50
51 final String version;
52
53
54
55 final String goalPrefix;
56
57
58
59 final boolean isolatedRealm;
60
61
62
63 final boolean inheritedByDefault;
64
65
66
67
68 final String requiredJavaVersion;
69
70
71
72
73 final String requiredMavenVersion;
74
75
76
77 final List<MojoDescriptor> mojos;
78
79
80
81
82
83 protected PluginDescriptor(Builder builder) {
84 this.namespaceUri = builder.namespaceUri != null ? builder.namespaceUri : (builder.base != null ? builder.base.namespaceUri : null);
85 this.modelEncoding = builder.modelEncoding != null ? builder.modelEncoding : (builder.base != null ? builder.base.modelEncoding : "UTF-8");
86 this.name = builder.name != null ? builder.name : (builder.base != null ? builder.base.name : null);
87 this.description = builder.description != null ? builder.description : (builder.base != null ? builder.base.description : null);
88 this.groupId = builder.groupId != null ? builder.groupId : (builder.base != null ? builder.base.groupId : null);
89 this.artifactId = builder.artifactId != null ? builder.artifactId : (builder.base != null ? builder.base.artifactId : null);
90 this.version = builder.version != null ? builder.version : (builder.base != null ? builder.base.version : null);
91 this.goalPrefix = builder.goalPrefix != null ? builder.goalPrefix : (builder.base != null ? builder.base.goalPrefix : null);
92 this.isolatedRealm = builder.isolatedRealm != null ? builder.isolatedRealm : (builder.base != null ? builder.base.isolatedRealm : false);
93 this.inheritedByDefault = builder.inheritedByDefault != null ? builder.inheritedByDefault : (builder.base != null ? builder.base.inheritedByDefault : true);
94 this.requiredJavaVersion = builder.requiredJavaVersion != null ? builder.requiredJavaVersion : (builder.base != null ? builder.base.requiredJavaVersion : null);
95 this.requiredMavenVersion = builder.requiredMavenVersion != null ? builder.requiredMavenVersion : (builder.base != null ? builder.base.requiredMavenVersion : null);
96 this.mojos = ImmutableCollections.copy(builder.mojos != null ? builder.mojos : (builder.base != null ? builder.base.mojos : null));
97 }
98
99 public String getNamespaceUri() {
100 return namespaceUri;
101 }
102
103 public String getModelEncoding() {
104 return modelEncoding;
105 }
106
107
108
109
110
111
112 public String getName() {
113 return this.name;
114 }
115
116
117
118
119
120
121 public String getDescription() {
122 return this.description;
123 }
124
125
126
127
128
129
130 public String getGroupId() {
131 return this.groupId;
132 }
133
134
135
136
137
138
139 public String getArtifactId() {
140 return this.artifactId;
141 }
142
143
144
145
146
147
148 public String getVersion() {
149 return this.version;
150 }
151
152
153
154
155
156
157 public String getGoalPrefix() {
158 return this.goalPrefix;
159 }
160
161
162
163
164
165
166 public boolean isIsolatedRealm() {
167 return this.isolatedRealm;
168 }
169
170
171
172
173
174
175 public boolean isInheritedByDefault() {
176 return this.inheritedByDefault;
177 }
178
179
180
181
182
183
184
185 public String getRequiredJavaVersion() {
186 return this.requiredJavaVersion;
187 }
188
189
190
191
192
193
194
195 public String getRequiredMavenVersion() {
196 return this.requiredMavenVersion;
197 }
198
199
200
201
202
203
204 @Nonnull
205 public List<MojoDescriptor> getMojos() {
206 return this.mojos;
207 }
208
209
210
211
212
213
214 @Nonnull
215 public Builder with() {
216 return newBuilder(this);
217 }
218
219
220
221
222
223
224 @Nonnull
225 public PluginDescriptor withName(String name) {
226 return newBuilder(this, true).name(name).build();
227 }
228
229
230
231
232
233
234 @Nonnull
235 public PluginDescriptor withDescription(String description) {
236 return newBuilder(this, true).description(description).build();
237 }
238
239
240
241
242
243
244 @Nonnull
245 public PluginDescriptor withGroupId(String groupId) {
246 return newBuilder(this, true).groupId(groupId).build();
247 }
248
249
250
251
252
253
254 @Nonnull
255 public PluginDescriptor withArtifactId(String artifactId) {
256 return newBuilder(this, true).artifactId(artifactId).build();
257 }
258
259
260
261
262
263
264 @Nonnull
265 public PluginDescriptor withVersion(String version) {
266 return newBuilder(this, true).version(version).build();
267 }
268
269
270
271
272
273
274 @Nonnull
275 public PluginDescriptor withGoalPrefix(String goalPrefix) {
276 return newBuilder(this, true).goalPrefix(goalPrefix).build();
277 }
278
279
280
281
282
283
284 @Nonnull
285 public PluginDescriptor withIsolatedRealm(boolean isolatedRealm) {
286 return newBuilder(this, true).isolatedRealm(isolatedRealm).build();
287 }
288
289
290
291
292
293
294 @Nonnull
295 public PluginDescriptor withInheritedByDefault(boolean inheritedByDefault) {
296 return newBuilder(this, true).inheritedByDefault(inheritedByDefault).build();
297 }
298
299
300
301
302
303
304 @Nonnull
305 public PluginDescriptor withRequiredJavaVersion(String requiredJavaVersion) {
306 return newBuilder(this, true).requiredJavaVersion(requiredJavaVersion).build();
307 }
308
309
310
311
312
313
314 @Nonnull
315 public PluginDescriptor withRequiredMavenVersion(String requiredMavenVersion) {
316 return newBuilder(this, true).requiredMavenVersion(requiredMavenVersion).build();
317 }
318
319
320
321
322
323
324 @Nonnull
325 public PluginDescriptor withMojos(Collection<MojoDescriptor> mojos) {
326 return newBuilder(this, true).mojos(mojos).build();
327 }
328
329
330
331
332
333
334
335
336 @Nonnull
337 public static PluginDescriptor newInstance() {
338 return newInstance(true);
339 }
340
341
342
343
344
345
346
347
348 @Nonnull
349 public static PluginDescriptor newInstance(boolean withDefaults) {
350 return newBuilder(withDefaults).build();
351 }
352
353
354
355
356
357
358
359
360 @Nonnull
361 public static Builder newBuilder() {
362 return newBuilder(true);
363 }
364
365
366
367
368
369
370
371 @Nonnull
372 public static Builder newBuilder(boolean withDefaults) {
373 return new Builder(withDefaults);
374 }
375
376
377
378
379
380
381
382
383 @Nonnull
384 public static Builder newBuilder(PluginDescriptor from) {
385 return newBuilder(from, false);
386 }
387
388
389
390
391
392
393
394
395 @Nonnull
396 public static Builder newBuilder(PluginDescriptor from, boolean forceCopy) {
397 return new Builder(from, forceCopy);
398 }
399
400
401
402
403
404
405 @NotThreadSafe
406 public static class Builder
407 {
408 PluginDescriptor base;
409 String namespaceUri;
410 String modelEncoding;
411 String name;
412 String description;
413 String groupId;
414 String artifactId;
415 String version;
416 String goalPrefix;
417 Boolean isolatedRealm;
418 Boolean inheritedByDefault;
419 String requiredJavaVersion;
420 String requiredMavenVersion;
421 Collection<MojoDescriptor> mojos;
422
423 protected Builder(boolean withDefaults) {
424 if (withDefaults) {
425 this.isolatedRealm = false;
426 this.inheritedByDefault = true;
427 }
428 }
429
430 protected Builder(PluginDescriptor base, boolean forceCopy) {
431 this.namespaceUri = base.namespaceUri;
432 this.modelEncoding = base.modelEncoding;
433 if (forceCopy) {
434 this.name = base.name;
435 this.description = base.description;
436 this.groupId = base.groupId;
437 this.artifactId = base.artifactId;
438 this.version = base.version;
439 this.goalPrefix = base.goalPrefix;
440 this.isolatedRealm = base.isolatedRealm;
441 this.inheritedByDefault = base.inheritedByDefault;
442 this.requiredJavaVersion = base.requiredJavaVersion;
443 this.requiredMavenVersion = base.requiredMavenVersion;
444 this.mojos = base.mojos;
445 } else {
446 this.base = base;
447 }
448 }
449
450 @Nonnull
451 public Builder namespaceUri(String namespaceUri) {
452 this.namespaceUri = namespaceUri;
453 return this;
454 }
455
456 @Nonnull
457 public Builder modelEncoding(String modelEncoding) {
458 this.modelEncoding = modelEncoding;
459 return this;
460 }
461
462 @Nonnull
463 public Builder name(String name) {
464 this.name = name;
465 return this;
466 }
467
468 @Nonnull
469 public Builder description(String description) {
470 this.description = description;
471 return this;
472 }
473
474 @Nonnull
475 public Builder groupId(String groupId) {
476 this.groupId = groupId;
477 return this;
478 }
479
480 @Nonnull
481 public Builder artifactId(String artifactId) {
482 this.artifactId = artifactId;
483 return this;
484 }
485
486 @Nonnull
487 public Builder version(String version) {
488 this.version = version;
489 return this;
490 }
491
492 @Nonnull
493 public Builder goalPrefix(String goalPrefix) {
494 this.goalPrefix = goalPrefix;
495 return this;
496 }
497
498 @Nonnull
499 public Builder isolatedRealm(boolean isolatedRealm) {
500 this.isolatedRealm = isolatedRealm;
501 return this;
502 }
503
504 @Nonnull
505 public Builder inheritedByDefault(boolean inheritedByDefault) {
506 this.inheritedByDefault = inheritedByDefault;
507 return this;
508 }
509
510 @Nonnull
511 public Builder requiredJavaVersion(String requiredJavaVersion) {
512 this.requiredJavaVersion = requiredJavaVersion;
513 return this;
514 }
515
516 @Nonnull
517 public Builder requiredMavenVersion(String requiredMavenVersion) {
518 this.requiredMavenVersion = requiredMavenVersion;
519 return this;
520 }
521
522 @Nonnull
523 public Builder mojos(Collection<MojoDescriptor> mojos) {
524 this.mojos = mojos;
525 return this;
526 }
527
528
529 @Nonnull
530 public PluginDescriptor build() {
531
532 if (base != null
533 && (name == null || name == base.name)
534 && (description == null || description == base.description)
535 && (groupId == null || groupId == base.groupId)
536 && (artifactId == null || artifactId == base.artifactId)
537 && (version == null || version == base.version)
538 && (goalPrefix == null || goalPrefix == base.goalPrefix)
539 && (isolatedRealm == null || isolatedRealm == base.isolatedRealm)
540 && (inheritedByDefault == null || inheritedByDefault == base.inheritedByDefault)
541 && (requiredJavaVersion == null || requiredJavaVersion == base.requiredJavaVersion)
542 && (requiredMavenVersion == null || requiredMavenVersion == base.requiredMavenVersion)
543 && (mojos == null || mojos == base.mojos)
544 ) {
545 return base;
546 }
547 return new PluginDescriptor(this);
548 }
549 }
550
551
552 public String getPluginLookupKey() {
553 return groupId + ":" + artifactId;
554 }
555
556 public String getId() {
557 return groupId + ":" + artifactId + ":" + version;
558 }
559
560
561 }