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