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 import org.apache.maven.project.MavenProject;
24 import org.apache.maven.shared.artifact.filter.resolve.ScopeFilter;
25
26 import java.util.LinkedHashSet;
27 import java.util.Set;
28
29
30
31
32
33
34
35 class ResolutionManagementInfo
36 {
37 private ScopeFilter scopeFilter;
38
39 private final Set<MavenProject> enabledProjects = new LinkedHashSet<MavenProject>();
40
41 private final LinkedHashSet<Artifact> artifacts = new LinkedHashSet<Artifact>();
42
43 private boolean resolutionRequired;
44
45 private boolean resolvedTransitively;
46
47 ResolutionManagementInfo( final MavenProject currentProject )
48 {
49 enabledProjects.add( currentProject );
50 }
51
52 boolean isResolutionRequired()
53 {
54 return resolutionRequired;
55 }
56
57 void setResolutionRequired( final boolean resolutionRequired )
58 {
59 this.resolutionRequired = resolutionRequired;
60 }
61
62 boolean isResolvedTransitively()
63 {
64 return resolvedTransitively;
65 }
66
67 void setResolvedTransitively( final boolean resolvedTransitively )
68 {
69 this.resolvedTransitively = this.resolvedTransitively || resolvedTransitively;
70 }
71
72 ScopeFilter getScopeFilter()
73 {
74 return scopeFilter;
75 }
76
77 void setScopeFilter( ScopeFilter scopeFilter )
78 {
79 this.scopeFilter = scopeFilter;
80 }
81
82
83
84 void enableProjectResolution( final MavenProject project )
85 {
86 if ( !enabledProjects.contains( project ) )
87 {
88 enabledProjects.add( project );
89 }
90 }
91
92 Set<MavenProject> getEnabledProjects()
93 {
94 return enabledProjects;
95 }
96
97 Set<Artifact> getArtifacts()
98 {
99 return artifacts;
100 }
101
102 void addArtifacts( final Set<Artifact> a )
103 {
104 for ( Artifact artifact : a )
105 {
106 addOneArtifact( artifact );
107 }
108 artifacts.addAll( a );
109 }
110
111 private void addOneArtifact( Artifact artifact )
112 {
113 for ( Artifact existing : artifacts )
114 {
115 if ( existing.equals( artifact ) )
116 {
117 if ( isScopeUpgrade( artifact, existing ) )
118 {
119 artifacts.remove( existing );
120 artifacts.add( artifact );
121 return;
122 }
123 }
124 }
125 }
126
127 private boolean isScopeUpgrade( Artifact a, Artifact existing )
128 {
129 return scopeValue( a.getScope() ) > scopeValue( existing.getScope() );
130 }
131
132 private int scopeValue( final String scope )
133 {
134 if ( Artifact.SCOPE_COMPILE.equals( scope ) )
135 {
136 return 5;
137 }
138 else if ( Artifact.SCOPE_PROVIDED.equals( scope ) )
139 {
140 return 4;
141 }
142 else if ( Artifact.SCOPE_RUNTIME.equals( scope ) )
143 {
144 return 3;
145 }
146 else if ( Artifact.SCOPE_SYSTEM.equals( scope ) )
147 {
148 return 2;
149 }
150 else if ( Artifact.SCOPE_TEST.equals( scope ) )
151 {
152 return 1;
153 }
154 return 0;
155 }
156
157 }