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 final InputLocation groupIdLocation;
62
63 final InputLocation artifactIdLocation;
64
65 final InputLocation versionLocation;
66
67 final InputLocation extensionsLocation;
68
69 final InputLocation executionsLocation;
70
71 final InputLocation dependenciesLocation;
72
73
74
75
76
77 Plugin(
78 String inherited,
79 XmlNode configuration,
80 String groupId,
81 String artifactId,
82 String version,
83 String extensions,
84 Collection<PluginExecution> executions,
85 Collection<Dependency> dependencies,
86 Map<Object, InputLocation> locations,
87 InputLocation location,
88 InputLocation inheritedLocation,
89 InputLocation configurationLocation,
90 InputLocation groupIdLocation,
91 InputLocation artifactIdLocation,
92 InputLocation versionLocation,
93 InputLocation extensionsLocation,
94 InputLocation executionsLocation,
95 InputLocation dependenciesLocation
96 )
97 {
98 super(
99 inherited,
100 configuration,
101 locations,
102 location,
103 inheritedLocation,
104 configurationLocation
105 );
106 this.groupId = groupId;
107 this.artifactId = artifactId;
108 this.version = version;
109 this.extensions = extensions;
110 this.executions = ImmutableCollections.copy( executions );
111 this.dependencies = ImmutableCollections.copy( dependencies );
112 this.groupIdLocation = groupIdLocation;
113 this.artifactIdLocation = artifactIdLocation;
114 this.versionLocation = versionLocation;
115 this.extensionsLocation = extensionsLocation;
116 this.executionsLocation = executionsLocation;
117 this.dependenciesLocation = dependenciesLocation;
118 }
119
120
121
122
123
124
125 public String getGroupId()
126 {
127 return this.groupId;
128 }
129
130
131
132
133
134
135 public String getArtifactId()
136 {
137 return this.artifactId;
138 }
139
140
141
142
143
144
145 public String getVersion()
146 {
147 return this.version;
148 }
149
150
151
152
153
154
155
156
157
158 public String getExtensions()
159 {
160 return this.extensions;
161 }
162
163
164
165
166
167
168
169 @Nonnull
170 public List<PluginExecution> getExecutions()
171 {
172 return this.executions;
173 }
174
175
176
177
178
179
180
181 @Nonnull
182 public List<Dependency> getDependencies()
183 {
184 return this.dependencies;
185 }
186
187
188
189
190 public InputLocation getLocation( Object key )
191 {
192 if ( key instanceof String )
193 {
194 switch ( ( String ) key )
195 {
196 case "groupId":
197 return groupIdLocation;
198 case "artifactId":
199 return artifactIdLocation;
200 case "version":
201 return versionLocation;
202 case "extensions":
203 return extensionsLocation;
204 case "executions":
205 return executionsLocation;
206 case "dependencies":
207 return dependenciesLocation;
208 }
209 }
210 return super.getLocation( key );
211 }
212
213
214
215
216
217
218 @Nonnull
219 public Builder with()
220 {
221 return newBuilder( this );
222 }
223
224
225
226
227
228
229 @Nonnull
230 public Plugin withInherited( String inherited )
231 {
232 return with().inherited( inherited ).build();
233 }
234
235
236
237
238
239
240 @Nonnull
241 public Plugin withConfiguration( XmlNode configuration )
242 {
243 return with().configuration( configuration ).build();
244 }
245
246
247
248
249
250
251 @Nonnull
252 public Plugin withGroupId( String groupId )
253 {
254 return with().groupId( groupId ).build();
255 }
256
257
258
259
260
261
262 @Nonnull
263 public Plugin withArtifactId( String artifactId )
264 {
265 return with().artifactId( artifactId ).build();
266 }
267
268
269
270
271
272
273 @Nonnull
274 public Plugin withVersion( String version )
275 {
276 return with().version( version ).build();
277 }
278
279
280
281
282
283
284 @Nonnull
285 public Plugin withExtensions( String extensions )
286 {
287 return with().extensions( extensions ).build();
288 }
289
290
291
292
293
294
295 @Nonnull
296 public Plugin withExecutions( Collection<PluginExecution> executions )
297 {
298 return with().executions( executions ).build();
299 }
300
301
302
303
304
305
306 @Nonnull
307 public Plugin withDependencies( Collection<Dependency> dependencies )
308 {
309 return with().dependencies( dependencies ).build();
310 }
311
312
313
314
315
316
317
318
319 @Nonnull
320 public static Plugin newInstance()
321 {
322 return newInstance( true );
323 }
324
325
326
327
328
329
330
331
332 @Nonnull
333 public static Plugin newInstance( boolean withDefaults )
334 {
335 return newBuilder( withDefaults ).build();
336 }
337
338
339
340
341
342
343
344
345 @Nonnull
346 public static Builder newBuilder()
347 {
348 return newBuilder( true );
349 }
350
351
352
353
354
355
356
357 @Nonnull
358 public static Builder newBuilder( boolean withDefaults )
359 {
360 return new Builder( withDefaults );
361 }
362
363
364
365
366
367
368
369
370 @Nonnull
371 public static Builder newBuilder( Plugin from )
372 {
373 return newBuilder( from, false );
374 }
375
376
377
378
379
380
381
382
383 @Nonnull
384 public static Builder newBuilder( Plugin from, boolean forceCopy )
385 {
386 return new Builder( from, forceCopy );
387 }
388
389
390
391
392
393
394 @NotThreadSafe
395 public static class Builder
396 extends ConfigurationContainer.Builder
397 {
398 Plugin base;
399 String groupId;
400 String artifactId;
401 String version;
402 String extensions;
403 Collection<PluginExecution> executions;
404 Collection<Dependency> dependencies;
405
406 Builder( boolean withDefaults )
407 {
408 super( withDefaults );
409 if ( withDefaults )
410 {
411 this.groupId = "org.apache.maven.plugins";
412 }
413 }
414
415 Builder( Plugin base, boolean forceCopy )
416 {
417 super( base, forceCopy );
418 if ( forceCopy )
419 {
420 this.groupId = base.groupId;
421 this.artifactId = base.artifactId;
422 this.version = base.version;
423 this.extensions = base.extensions;
424 this.executions = base.executions;
425 this.dependencies = base.dependencies;
426 }
427 else
428 {
429 this.base = base;
430 }
431 }
432
433 @Nonnull
434 public Builder inherited( String inherited )
435 {
436 this.inherited = inherited;
437 return this;
438 }
439
440 @Nonnull
441 public Builder configuration( XmlNode configuration )
442 {
443 this.configuration = configuration;
444 return this;
445 }
446
447 @Nonnull
448 public Builder groupId( String groupId )
449 {
450 this.groupId = groupId;
451 return this;
452 }
453
454 @Nonnull
455 public Builder artifactId( String artifactId )
456 {
457 this.artifactId = artifactId;
458 return this;
459 }
460
461 @Nonnull
462 public Builder version( String version )
463 {
464 this.version = version;
465 return this;
466 }
467
468 @Nonnull
469 public Builder extensions( String extensions )
470 {
471 this.extensions = extensions;
472 return this;
473 }
474
475 @Nonnull
476 public Builder executions( Collection<PluginExecution> executions )
477 {
478 this.executions = executions;
479 return this;
480 }
481
482 @Nonnull
483 public Builder dependencies( Collection<Dependency> dependencies )
484 {
485 this.dependencies = dependencies;
486 return this;
487 }
488
489
490 @Nonnull
491 public Builder location( Object key, InputLocation location )
492 {
493 if ( location != null )
494 {
495 if ( this.locations == null )
496 {
497 this.locations = new HashMap<>();
498 }
499 this.locations.put( key, location );
500 }
501 return this;
502 }
503
504 @Nonnull
505 public Plugin build()
506 {
507 if ( base != null
508 && ( inherited == null || inherited == base.inherited )
509 && ( configuration == null || configuration == base.configuration )
510 && ( groupId == null || groupId == base.groupId )
511 && ( artifactId == null || artifactId == base.artifactId )
512 && ( version == null || version == base.version )
513 && ( extensions == null || extensions == base.extensions )
514 && ( executions == null || executions == base.executions )
515 && ( dependencies == null || dependencies == base.dependencies )
516 )
517 {
518 return base;
519 }
520 Map<Object, InputLocation> locations = null;
521 InputLocation location = null;
522 InputLocation inheritedLocation = null;
523 InputLocation configurationLocation = null;
524 InputLocation groupIdLocation = null;
525 InputLocation artifactIdLocation = null;
526 InputLocation versionLocation = null;
527 InputLocation extensionsLocation = null;
528 InputLocation executionsLocation = null;
529 InputLocation dependenciesLocation = null;
530 if ( this.locations != null )
531 {
532 locations = this.locations;
533 location = locations.remove( "" );
534 inheritedLocation = locations.remove( "inherited" );
535 configurationLocation = locations.remove( "configuration" );
536 groupIdLocation = locations.remove( "groupId" );
537 artifactIdLocation = locations.remove( "artifactId" );
538 versionLocation = locations.remove( "version" );
539 extensionsLocation = locations.remove( "extensions" );
540 executionsLocation = locations.remove( "executions" );
541 dependenciesLocation = locations.remove( "dependencies" );
542 }
543 return new Plugin(
544 inherited != null ? inherited : ( base != null ? base.inherited : null ),
545 configuration != null ? configuration : ( base != null ? base.configuration : null ),
546 groupId != null ? groupId : ( base != null ? base.groupId : null ),
547 artifactId != null ? artifactId : ( base != null ? base.artifactId : null ),
548 version != null ? version : ( base != null ? base.version : null ),
549 extensions != null ? extensions : ( base != null ? base.extensions : null ),
550 executions != null ? executions : ( base != null ? base.executions : null ),
551 dependencies != null ? dependencies : ( base != null ? base.dependencies : null ),
552 locations != null ? locations : ( base != null ? base.locations : null ),
553 location != null ? location : ( base != null ? base.location : null ),
554 inheritedLocation != null ? inheritedLocation : ( base != null ? base.inheritedLocation : null ),
555 configurationLocation != null ? configurationLocation : ( base != null ? base.configurationLocation : null ),
556 groupIdLocation != null ? groupIdLocation : ( base != null ? base.groupIdLocation : null ),
557 artifactIdLocation != null ? artifactIdLocation : ( base != null ? base.artifactIdLocation : null ),
558 versionLocation != null ? versionLocation : ( base != null ? base.versionLocation : null ),
559 extensionsLocation != null ? extensionsLocation : ( base != null ? base.extensionsLocation : null ),
560 executionsLocation != null ? executionsLocation : ( base != null ? base.executionsLocation : null ),
561 dependenciesLocation != null ? dependenciesLocation : ( base != null ? base.dependenciesLocation : null )
562 );
563 }
564 }
565
566
567
568 public boolean isExtensions()
569 {
570 return ( getExtensions() != null ) ? Boolean.parseBoolean( getExtensions() ) : false;
571 }
572
573
574
575
576 private java.util.Map<String, PluginExecution> executionMap = null;
577
578
579
580
581 public void flushExecutionMap()
582 {
583 this.executionMap = null;
584 }
585
586
587
588
589 public java.util.Map<String, PluginExecution> getExecutionsAsMap()
590 {
591 if ( executionMap == null )
592 {
593 executionMap = new java.util.LinkedHashMap<String, PluginExecution>();
594 for ( java.util.Iterator<PluginExecution> i = getExecutions().iterator(); i.hasNext(); )
595 {
596 PluginExecution exec = (PluginExecution) i.next();
597 if ( executionMap.containsKey( exec.getId() ) )
598 {
599 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" );
600 }
601 executionMap.put( exec.getId(), exec );
602 }
603 }
604 return executionMap;
605 }
606
607
608
609
610
611
612 public String getId()
613 {
614 StringBuilder id = new StringBuilder( 128 );
615
616 id.append( ( getGroupId() == null ) ? "[unknown-group-id]" : getGroupId() );
617 id.append( ":" );
618 id.append( ( getArtifactId() == null ) ? "[unknown-artifact-id]" : getArtifactId() );
619 id.append( ":" );
620 id.append( ( getVersion() == null ) ? "[unknown-version]" : getVersion() );
621
622 return id.toString();
623 }
624
625
626
627
628 public String getKey()
629 {
630 return constructKey( getGroupId(), getArtifactId() );
631 }
632
633
634
635
636
637
638 public static String constructKey( String groupId, String artifactId )
639 {
640 return groupId + ":" + artifactId;
641 }
642
643
644
645
646
647
648
649
650 public boolean equals( Object other )
651 {
652 if ( other instanceof Plugin )
653 {
654 Plugin otherPlugin = (Plugin) other;
655
656 return getKey().equals( otherPlugin.getKey() );
657 }
658
659 return false;
660 }
661
662
663
664
665 public int hashCode()
666 {
667 return getKey().hashCode();
668 }
669
670
671
672
673 public String toString()
674 {
675 return "Plugin [" + getKey() + "]";
676 }
677
678
679 }