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