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