1 package org.apache.maven.plugins.assembly.artifact;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.Artifact;
23
24 import java.util.LinkedHashSet;
25 import java.util.Set;
26
27
28
29
30
31
32
33 class ResolutionManagementInfo
34 {
35 private final LinkedHashSet<Artifact> artifacts = new LinkedHashSet<>();
36
37 Set<Artifact> getArtifacts()
38 {
39 return artifacts;
40 }
41
42 void addArtifacts( final Set<Artifact> a )
43 {
44 for ( Artifact artifact : a )
45 {
46 addOneArtifact( artifact );
47 }
48 artifacts.addAll( a );
49 }
50
51 private void addOneArtifact( Artifact artifact )
52 {
53 for ( Artifact existing : artifacts )
54 {
55 if ( existing.equals( artifact ) )
56 {
57 if ( isScopeUpgrade( artifact, existing ) )
58 {
59 artifacts.remove( existing );
60 artifacts.add( artifact );
61 return;
62 }
63 }
64 }
65 }
66
67 private boolean isScopeUpgrade( Artifact a, Artifact existing )
68 {
69 return scopeValue( a.getScope() ) > scopeValue( existing.getScope() );
70 }
71
72 private int scopeValue( final String scope )
73 {
74 if ( Artifact.SCOPE_COMPILE.equals( scope ) )
75 {
76 return 5;
77 }
78 else if ( Artifact.SCOPE_PROVIDED.equals( scope ) )
79 {
80 return 4;
81 }
82 else if ( Artifact.SCOPE_RUNTIME.equals( scope ) )
83 {
84 return 3;
85 }
86 else if ( Artifact.SCOPE_SYSTEM.equals( scope ) )
87 {
88 return 2;
89 }
90 else if ( Artifact.SCOPE_TEST.equals( scope ) )
91 {
92 return 1;
93 }
94 return 0;
95 }
96
97 }