1
2
3
4 package org.apache.maven.api.model;
5
6 import java.io.Serializable;
7 import java.util.ArrayList;
8 import java.util.Collection;
9 import java.util.Collections;
10 import java.util.HashMap;
11 import java.util.List;
12 import java.util.Map;
13 import org.apache.maven.api.annotations.Experimental;
14 import org.apache.maven.api.annotations.Generated;
15 import org.apache.maven.api.annotations.Immutable;
16 import org.apache.maven.api.annotations.Nonnull;
17 import org.apache.maven.api.annotations.NotThreadSafe;
18 import org.apache.maven.api.annotations.ThreadSafe;
19
20
21
22
23
24 @Experimental
25 @Generated @ThreadSafe @Immutable
26 public class Dependency
27 implements Serializable, InputLocationTracker
28 {
29
30
31
32
33 final String groupId;
34
35
36
37
38 final String artifactId;
39
40
41
42
43 final String version;
44
45
46
47
48
49
50 final String type;
51
52
53
54
55
56
57
58
59
60
61
62 final String classifier;
63
64
65
66
67
68
69
70
71
72 final String scope;
73
74
75
76
77
78
79
80
81 final String systemPath;
82
83
84
85
86 final List<Exclusion> exclusions;
87
88
89
90
91
92
93
94 final String optional;
95
96 final InputLocation location;
97
98 final InputLocation groupIdLocation;
99
100 final InputLocation artifactIdLocation;
101
102 final InputLocation versionLocation;
103
104 final InputLocation typeLocation;
105
106 final InputLocation classifierLocation;
107
108 final InputLocation scopeLocation;
109
110 final InputLocation systemPathLocation;
111
112 final InputLocation exclusionsLocation;
113
114 final InputLocation optionalLocation;
115
116 final Map<Object, InputLocation> locations;
117
118
119
120
121
122 Dependency(
123 String groupId,
124 String artifactId,
125 String version,
126 String type,
127 String classifier,
128 String scope,
129 String systemPath,
130 Collection<Exclusion> exclusions,
131 String optional,
132 Map<Object, InputLocation> locations,
133 InputLocation location,
134 InputLocation groupIdLocation,
135 InputLocation artifactIdLocation,
136 InputLocation versionLocation,
137 InputLocation typeLocation,
138 InputLocation classifierLocation,
139 InputLocation scopeLocation,
140 InputLocation systemPathLocation,
141 InputLocation exclusionsLocation,
142 InputLocation optionalLocation
143 )
144 {
145 this.groupId = groupId;
146 this.artifactId = artifactId;
147 this.version = version;
148 this.type = type;
149 this.classifier = classifier;
150 this.scope = scope;
151 this.systemPath = systemPath;
152 this.exclusions = ImmutableCollections.copy( exclusions );
153 this.optional = optional;
154 this.locations = ImmutableCollections.copy( locations );
155 this.location = location;
156 this.groupIdLocation = groupIdLocation;
157 this.artifactIdLocation = artifactIdLocation;
158 this.versionLocation = versionLocation;
159 this.typeLocation = typeLocation;
160 this.classifierLocation = classifierLocation;
161 this.scopeLocation = scopeLocation;
162 this.systemPathLocation = systemPathLocation;
163 this.exclusionsLocation = exclusionsLocation;
164 this.optionalLocation = optionalLocation;
165 }
166
167
168
169
170
171
172
173 public String getGroupId()
174 {
175 return this.groupId;
176 }
177
178
179
180
181
182
183
184 public String getArtifactId()
185 {
186 return this.artifactId;
187 }
188
189
190
191
192
193
194
195 public String getVersion()
196 {
197 return this.version;
198 }
199
200
201
202
203
204
205
206
207
208 public String getType()
209 {
210 return this.type;
211 }
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226 public String getClassifier()
227 {
228 return this.classifier;
229 }
230
231
232
233
234
235
236
237
238
239
240
241
242 public String getScope()
243 {
244 return this.scope;
245 }
246
247
248
249
250
251
252
253
254
255
256
257 public String getSystemPath()
258 {
259 return this.systemPath;
260 }
261
262
263
264
265
266
267
268 @Nonnull
269 public List<Exclusion> getExclusions()
270 {
271 return this.exclusions;
272 }
273
274
275
276
277
278
279
280
281
282
283 public String getOptional()
284 {
285 return this.optional;
286 }
287
288
289
290
291 public InputLocation getLocation( Object key )
292 {
293 if ( key instanceof String )
294 {
295 switch ( ( String ) key )
296 {
297 case "":
298 return location;
299 case "groupId":
300 return groupIdLocation;
301 case "artifactId":
302 return artifactIdLocation;
303 case "version":
304 return versionLocation;
305 case "type":
306 return typeLocation;
307 case "classifier":
308 return classifierLocation;
309 case "scope":
310 return scopeLocation;
311 case "systemPath":
312 return systemPathLocation;
313 case "exclusions":
314 return exclusionsLocation;
315 case "optional":
316 return optionalLocation;
317 }
318 }
319 return locations != null ? locations.get( key ) : null;
320 }
321
322
323
324
325
326
327 @Nonnull
328 public Builder with()
329 {
330 return newBuilder( this );
331 }
332
333
334
335
336
337
338 @Nonnull
339 public Dependency withGroupId( String groupId )
340 {
341 return with().groupId( groupId ).build();
342 }
343
344
345
346
347
348
349 @Nonnull
350 public Dependency withArtifactId( String artifactId )
351 {
352 return with().artifactId( artifactId ).build();
353 }
354
355
356
357
358
359
360 @Nonnull
361 public Dependency withVersion( String version )
362 {
363 return with().version( version ).build();
364 }
365
366
367
368
369
370
371 @Nonnull
372 public Dependency withType( String type )
373 {
374 return with().type( type ).build();
375 }
376
377
378
379
380
381
382 @Nonnull
383 public Dependency withClassifier( String classifier )
384 {
385 return with().classifier( classifier ).build();
386 }
387
388
389
390
391
392
393 @Nonnull
394 public Dependency withScope( String scope )
395 {
396 return with().scope( scope ).build();
397 }
398
399
400
401
402
403
404 @Nonnull
405 public Dependency withSystemPath( String systemPath )
406 {
407 return with().systemPath( systemPath ).build();
408 }
409
410
411
412
413
414
415 @Nonnull
416 public Dependency withExclusions( Collection<Exclusion> exclusions )
417 {
418 return with().exclusions( exclusions ).build();
419 }
420
421
422
423
424
425
426 @Nonnull
427 public Dependency withOptional( String optional )
428 {
429 return with().optional( optional ).build();
430 }
431
432
433
434
435
436
437
438
439 @Nonnull
440 public static Dependency newInstance()
441 {
442 return newInstance( true );
443 }
444
445
446
447
448
449
450
451
452 @Nonnull
453 public static Dependency newInstance( boolean withDefaults )
454 {
455 return newBuilder( withDefaults ).build();
456 }
457
458
459
460
461
462
463
464
465 @Nonnull
466 public static Builder newBuilder()
467 {
468 return newBuilder( true );
469 }
470
471
472
473
474
475
476
477 @Nonnull
478 public static Builder newBuilder( boolean withDefaults )
479 {
480 return new Builder( withDefaults );
481 }
482
483
484
485
486
487
488
489
490 @Nonnull
491 public static Builder newBuilder( Dependency from )
492 {
493 return newBuilder( from, false );
494 }
495
496
497
498
499
500
501
502
503 @Nonnull
504 public static Builder newBuilder( Dependency from, boolean forceCopy )
505 {
506 return new Builder( from, forceCopy );
507 }
508
509
510
511
512
513
514 @NotThreadSafe
515 public static class Builder
516 {
517 Dependency base;
518 String groupId;
519 String artifactId;
520 String version;
521 String type;
522 String classifier;
523 String scope;
524 String systemPath;
525 Collection<Exclusion> exclusions;
526 String optional;
527 Map<Object, InputLocation> locations;
528
529 Builder( boolean withDefaults )
530 {
531 if ( withDefaults )
532 {
533 this.type = "jar";
534 }
535 }
536
537 Builder( Dependency base, boolean forceCopy )
538 {
539 if ( forceCopy )
540 {
541 this.groupId = base.groupId;
542 this.artifactId = base.artifactId;
543 this.version = base.version;
544 this.type = base.type;
545 this.classifier = base.classifier;
546 this.scope = base.scope;
547 this.systemPath = base.systemPath;
548 this.exclusions = base.exclusions;
549 this.optional = base.optional;
550 }
551 else
552 {
553 this.base = base;
554 }
555 }
556
557 @Nonnull
558 public Builder groupId( String groupId )
559 {
560 this.groupId = groupId;
561 return this;
562 }
563
564 @Nonnull
565 public Builder artifactId( String artifactId )
566 {
567 this.artifactId = artifactId;
568 return this;
569 }
570
571 @Nonnull
572 public Builder version( String version )
573 {
574 this.version = version;
575 return this;
576 }
577
578 @Nonnull
579 public Builder type( String type )
580 {
581 this.type = type;
582 return this;
583 }
584
585 @Nonnull
586 public Builder classifier( String classifier )
587 {
588 this.classifier = classifier;
589 return this;
590 }
591
592 @Nonnull
593 public Builder scope( String scope )
594 {
595 this.scope = scope;
596 return this;
597 }
598
599 @Nonnull
600 public Builder systemPath( String systemPath )
601 {
602 this.systemPath = systemPath;
603 return this;
604 }
605
606 @Nonnull
607 public Builder exclusions( Collection<Exclusion> exclusions )
608 {
609 this.exclusions = exclusions;
610 return this;
611 }
612
613 @Nonnull
614 public Builder optional( String optional )
615 {
616 this.optional = optional;
617 return this;
618 }
619
620
621 @Nonnull
622 public Builder location( Object key, InputLocation location )
623 {
624 if ( location != null )
625 {
626 if ( this.locations == null )
627 {
628 this.locations = new HashMap<>();
629 }
630 this.locations.put( key, location );
631 }
632 return this;
633 }
634
635 @Nonnull
636 public Dependency build()
637 {
638 if ( base != null
639 && ( groupId == null || groupId == base.groupId )
640 && ( artifactId == null || artifactId == base.artifactId )
641 && ( version == null || version == base.version )
642 && ( type == null || type == base.type )
643 && ( classifier == null || classifier == base.classifier )
644 && ( scope == null || scope == base.scope )
645 && ( systemPath == null || systemPath == base.systemPath )
646 && ( exclusions == null || exclusions == base.exclusions )
647 && ( optional == null || optional == base.optional )
648 )
649 {
650 return base;
651 }
652 Map<Object, InputLocation> locations = null;
653 InputLocation location = null;
654 InputLocation groupIdLocation = null;
655 InputLocation artifactIdLocation = null;
656 InputLocation versionLocation = null;
657 InputLocation typeLocation = null;
658 InputLocation classifierLocation = null;
659 InputLocation scopeLocation = null;
660 InputLocation systemPathLocation = null;
661 InputLocation exclusionsLocation = null;
662 InputLocation optionalLocation = null;
663 if ( this.locations != null )
664 {
665 locations = this.locations;
666 location = locations.remove( "" );
667 groupIdLocation = locations.remove( "groupId" );
668 artifactIdLocation = locations.remove( "artifactId" );
669 versionLocation = locations.remove( "version" );
670 typeLocation = locations.remove( "type" );
671 classifierLocation = locations.remove( "classifier" );
672 scopeLocation = locations.remove( "scope" );
673 systemPathLocation = locations.remove( "systemPath" );
674 exclusionsLocation = locations.remove( "exclusions" );
675 optionalLocation = locations.remove( "optional" );
676 }
677 return new Dependency(
678 groupId != null ? groupId : ( base != null ? base.groupId : null ),
679 artifactId != null ? artifactId : ( base != null ? base.artifactId : null ),
680 version != null ? version : ( base != null ? base.version : null ),
681 type != null ? type : ( base != null ? base.type : null ),
682 classifier != null ? classifier : ( base != null ? base.classifier : null ),
683 scope != null ? scope : ( base != null ? base.scope : null ),
684 systemPath != null ? systemPath : ( base != null ? base.systemPath : null ),
685 exclusions != null ? exclusions : ( base != null ? base.exclusions : null ),
686 optional != null ? optional : ( base != null ? base.optional : null ),
687 locations != null ? locations : ( base != null ? base.locations : null ),
688 location != null ? location : ( base != null ? base.location : null ),
689 groupIdLocation != null ? groupIdLocation : ( base != null ? base.groupIdLocation : null ),
690 artifactIdLocation != null ? artifactIdLocation : ( base != null ? base.artifactIdLocation : null ),
691 versionLocation != null ? versionLocation : ( base != null ? base.versionLocation : null ),
692 typeLocation != null ? typeLocation : ( base != null ? base.typeLocation : null ),
693 classifierLocation != null ? classifierLocation : ( base != null ? base.classifierLocation : null ),
694 scopeLocation != null ? scopeLocation : ( base != null ? base.scopeLocation : null ),
695 systemPathLocation != null ? systemPathLocation : ( base != null ? base.systemPathLocation : null ),
696 exclusionsLocation != null ? exclusionsLocation : ( base != null ? base.exclusionsLocation : null ),
697 optionalLocation != null ? optionalLocation : ( base != null ? base.optionalLocation : null )
698 );
699 }
700 }
701
702
703
704 public boolean isOptional()
705 {
706 return ( getOptional() != null ) ? Boolean.parseBoolean( getOptional() ) : false;
707 }
708
709
710
711
712
713
714
715
716 public String toString()
717 {
718 return "Dependency {groupId=" + getGroupId() + ", artifactId=" + getArtifactId() + ", version=" + getVersion() + ", type=" + getType() + "}";
719 }
720
721
722
723
724 private volatile String managementKey;
725
726
727
728
729 public String getManagementKey()
730 {
731 if ( managementKey == null )
732 {
733 managementKey = getGroupId() + ":" + getArtifactId() + ":" + getType() + ( getClassifier() != null ? ":" + getClassifier() : "" );
734 }
735 return managementKey;
736 }
737
738
739 }