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