1
2
3
4
5 package org.apache.maven.api.model;
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 import org.apache.maven.api.xml.XmlNode;
22
23
24
25
26 @Experimental
27 @Generated @ThreadSafe @Immutable
28 public class Plugin
29 extends ConfigurationContainer
30 implements Serializable, InputLocationTracker
31 {
32
33
34
35 final String groupId;
36
37
38
39 final String artifactId;
40
41
42
43 final String version;
44
45
46
47
48
49
50 final String extensions;
51
52
53
54
55 final List<PluginExecution> executions;
56
57
58
59
60 final List<Dependency> dependencies;
61
62 final Map<Object, InputLocation> locations;
63
64
65
66
67
68 protected Plugin(Builder builder) {
69 super(builder);
70 this.groupId = builder.groupId != null ? builder.groupId : (builder.base != null ? builder.base.groupId : null);
71 this.artifactId = builder.artifactId != null ? builder.artifactId : (builder.base != null ? builder.base.artifactId : null);
72 this.version = builder.version != null ? builder.version : (builder.base != null ? builder.base.version : null);
73 this.extensions = builder.extensions != null ? builder.extensions : (builder.base != null ? builder.base.extensions : null);
74 this.executions = ImmutableCollections.copy(builder.executions != null ? builder.executions : (builder.base != null ? builder.base.executions : null));
75 this.dependencies = ImmutableCollections.copy(builder.dependencies != null ? builder.dependencies : (builder.base != null ? builder.base.dependencies : null));
76 Map<Object, InputLocation> newlocs = builder.locations != null ? builder.locations : Collections.emptyMap();
77 Map<Object, InputLocation> oldlocs = builder.base != null && builder.base.locations != null ? builder.base.locations : Collections.emptyMap();
78 Map<Object, InputLocation> mutableLocations = new HashMap<>(super.locations);
79 mutableLocations.put("groupId", newlocs.containsKey("groupId") ? newlocs.get("groupId") : oldlocs.get("groupId"));
80 mutableLocations.put("artifactId", newlocs.containsKey("artifactId") ? newlocs.get("artifactId") : oldlocs.get("artifactId"));
81 mutableLocations.put("version", newlocs.containsKey("version") ? newlocs.get("version") : oldlocs.get("version"));
82 mutableLocations.put("extensions", newlocs.containsKey("extensions") ? newlocs.get("extensions") : oldlocs.get("extensions"));
83 mutableLocations.put("executions", newlocs.containsKey("executions") ? newlocs.get("executions") : oldlocs.get("executions"));
84 mutableLocations.put("dependencies", newlocs.containsKey("dependencies") ? newlocs.get("dependencies") : oldlocs.get("dependencies"));
85 this.locations = Collections.unmodifiableMap(mutableLocations);
86 }
87
88
89
90
91
92
93 public String getGroupId() {
94 return this.groupId;
95 }
96
97
98
99
100
101
102 public String getArtifactId() {
103 return this.artifactId;
104 }
105
106
107
108
109
110
111 public String getVersion() {
112 return this.version;
113 }
114
115
116
117
118
119
120
121
122
123 public String getExtensions() {
124 return this.extensions;
125 }
126
127
128
129
130
131
132
133 @Nonnull
134 public List<PluginExecution> getExecutions() {
135 return this.executions;
136 }
137
138
139
140
141
142
143
144 @Nonnull
145 public List<Dependency> getDependencies() {
146 return this.dependencies;
147 }
148
149
150
151
152 public InputLocation getLocation(Object key) {
153 return locations != null ? locations.get(key) : null;
154 }
155
156
157
158
159 public Set<Object> getLocationKeys() {
160 return locations != null ? locations.keySet() : null;
161 }
162
163
164
165
166
167
168 @Nonnull
169 public Builder with() {
170 return newBuilder(this);
171 }
172
173
174
175
176
177
178 @Nonnull
179 public Plugin withInherited(String inherited) {
180 return newBuilder(this, true).inherited(inherited).build();
181 }
182
183
184
185
186
187
188 @Nonnull
189 public Plugin withConfiguration(XmlNode configuration) {
190 return newBuilder(this, true).configuration(configuration).build();
191 }
192
193
194
195
196
197
198 @Nonnull
199 public Plugin withGroupId(String groupId) {
200 return newBuilder(this, true).groupId(groupId).build();
201 }
202
203
204
205
206
207
208 @Nonnull
209 public Plugin withArtifactId(String artifactId) {
210 return newBuilder(this, true).artifactId(artifactId).build();
211 }
212
213
214
215
216
217
218 @Nonnull
219 public Plugin withVersion(String version) {
220 return newBuilder(this, true).version(version).build();
221 }
222
223
224
225
226
227
228 @Nonnull
229 public Plugin withExtensions(String extensions) {
230 return newBuilder(this, true).extensions(extensions).build();
231 }
232
233
234
235
236
237
238 @Nonnull
239 public Plugin withExecutions(Collection<PluginExecution> executions) {
240 return newBuilder(this, true).executions(executions).build();
241 }
242
243
244
245
246
247
248 @Nonnull
249 public Plugin withDependencies(Collection<Dependency> dependencies) {
250 return newBuilder(this, true).dependencies(dependencies).build();
251 }
252
253
254
255
256
257
258
259
260 @Nonnull
261 public static Plugin newInstance() {
262 return newInstance(true);
263 }
264
265
266
267
268
269
270
271
272 @Nonnull
273 public static Plugin newInstance(boolean withDefaults) {
274 return newBuilder(withDefaults).build();
275 }
276
277
278
279
280
281
282
283
284 @Nonnull
285 public static Builder newBuilder() {
286 return newBuilder(true);
287 }
288
289
290
291
292
293
294
295 @Nonnull
296 public static Builder newBuilder(boolean withDefaults) {
297 return new Builder(withDefaults);
298 }
299
300
301
302
303
304
305
306
307 @Nonnull
308 public static Builder newBuilder(Plugin from) {
309 return newBuilder(from, false);
310 }
311
312
313
314
315
316
317
318
319 @Nonnull
320 public static Builder newBuilder(Plugin from, boolean forceCopy) {
321 return new Builder(from, forceCopy);
322 }
323
324
325
326
327
328
329 @NotThreadSafe
330 public static class Builder
331 extends ConfigurationContainer.Builder
332 {
333 Plugin base;
334 String groupId;
335 String artifactId;
336 String version;
337 String extensions;
338 Collection<PluginExecution> executions;
339 Collection<Dependency> dependencies;
340
341 protected Builder(boolean withDefaults) {
342 super(withDefaults);
343 if (withDefaults) {
344 this.groupId = "org.apache.maven.plugins";
345 }
346 }
347
348 protected Builder(Plugin base, boolean forceCopy) {
349 super(base, forceCopy);
350 if (forceCopy) {
351 this.groupId = base.groupId;
352 this.artifactId = base.artifactId;
353 this.version = base.version;
354 this.extensions = base.extensions;
355 this.executions = base.executions;
356 this.dependencies = base.dependencies;
357 this.locations = base.locations;
358 this.importedFrom = base.importedFrom;
359 } else {
360 this.base = base;
361 }
362 }
363
364 @Nonnull
365 public Builder inherited(String inherited) {
366 this.inherited = inherited;
367 return this;
368 }
369
370 @Nonnull
371 public Builder configuration(XmlNode configuration) {
372 this.configuration = configuration;
373 return this;
374 }
375
376 @Nonnull
377 public Builder groupId(String groupId) {
378 this.groupId = groupId;
379 return this;
380 }
381
382 @Nonnull
383 public Builder artifactId(String artifactId) {
384 this.artifactId = artifactId;
385 return this;
386 }
387
388 @Nonnull
389 public Builder version(String version) {
390 this.version = version;
391 return this;
392 }
393
394 @Nonnull
395 public Builder extensions(String extensions) {
396 this.extensions = extensions;
397 return this;
398 }
399
400 @Nonnull
401 public Builder executions(Collection<PluginExecution> executions) {
402 this.executions = executions;
403 return this;
404 }
405
406 @Nonnull
407 public Builder dependencies(Collection<Dependency> dependencies) {
408 this.dependencies = dependencies;
409 return this;
410 }
411
412
413 @Nonnull
414 public Builder location(Object key, InputLocation location) {
415 if (location != null) {
416 if (!(this.locations instanceof HashMap)) {
417 this.locations = this.locations != null ? new HashMap<>(this.locations) : new HashMap<>();
418 }
419 this.locations.put(key, location);
420 }
421 return this;
422 }
423
424 @Nonnull
425 public Builder importedFrom(InputLocation importedFrom) {
426 this.importedFrom = importedFrom;
427 return this;
428 }
429
430 @Nonnull
431 public Plugin build() {
432
433 if (base != null
434 && (inherited == null || inherited == base.inherited)
435 && (configuration == null || configuration == base.configuration)
436 && (groupId == null || groupId == base.groupId)
437 && (artifactId == null || artifactId == base.artifactId)
438 && (version == null || version == base.version)
439 && (extensions == null || extensions == base.extensions)
440 && (executions == null || executions == base.executions)
441 && (dependencies == null || dependencies == base.dependencies)
442 ) {
443 return base;
444 }
445 return new Plugin(this);
446 }
447 }
448
449
450
451 public boolean isExtensions() {
452 return (getExtensions() != null) ? Boolean.parseBoolean(getExtensions()) : false;
453 }
454
455
456
457
458
459
460
461
462
463 public String getId() {
464 return new StringBuilder(128)
465 .append((getGroupId() == null) ? "[unknown-group-id]" : getGroupId())
466 .append(":")
467 .append((getArtifactId() == null) ? "[unknown-artifact-id]" : getArtifactId())
468 .append(":")
469 .append((getVersion() == null) ? "[unknown-version]" : getVersion())
470 .toString();
471 }
472
473
474
475
476 public String getKey() {
477 return constructKey(getGroupId(), getArtifactId());
478 }
479
480
481
482
483
484
485 public static String constructKey(String groupId, String artifactId) {
486 return groupId + ":" + artifactId;
487 }
488
489
490
491
492
493
494
495
496 public boolean equals(Object other) {
497 if (other instanceof Plugin) {
498 Plugin otherPlugin = (Plugin) other;
499 return getKey().equals(otherPlugin.getKey());
500 }
501 return false;
502 }
503
504
505
506
507 public int hashCode() {
508 return getKey().hashCode();
509 }
510
511
512
513
514 public String toString() {
515 return "Plugin [" + getKey() + "]";
516 }
517
518
519 }