1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.util.graph.transformer;
20
21 import java.util.Collection;
22 import java.util.HashSet;
23 import java.util.Set;
24
25 import org.eclipse.aether.RepositoryException;
26 import org.eclipse.aether.util.artifact.JavaScopes;
27 import org.eclipse.aether.util.graph.transformer.ConflictResolver.ConflictContext;
28 import org.eclipse.aether.util.graph.transformer.ConflictResolver.ConflictItem;
29 import org.eclipse.aether.util.graph.transformer.ConflictResolver.ScopeSelector;
30
31
32
33
34
35
36
37
38 @Deprecated
39 public final class JavaScopeSelector extends ScopeSelector {
40
41
42
43
44 public JavaScopeSelector() {}
45
46 @Override
47 public void selectScope(ConflictContext context) throws RepositoryException {
48 String scope = context.getWinner().getDependency().getScope();
49 if (!JavaScopes.SYSTEM.equals(scope)) {
50 scope = chooseEffectiveScope(context.getItems());
51 }
52 context.setScope(scope);
53 }
54
55 private String chooseEffectiveScope(Collection<ConflictItem> items) {
56 Set<String> scopes = new HashSet<>();
57 for (ConflictItem item : items) {
58 if (item.getDepth() <= 1) {
59 return item.getDependency().getScope();
60 }
61 scopes.addAll(item.getScopes());
62 }
63 return chooseEffectiveScope(scopes);
64 }
65
66 private String chooseEffectiveScope(Set<String> scopes) {
67 if (scopes.size() > 1) {
68 scopes.remove(JavaScopes.SYSTEM);
69 }
70
71 String effectiveScope = "";
72
73 if (scopes.size() == 1) {
74 effectiveScope = scopes.iterator().next();
75 } else if (scopes.contains(JavaScopes.COMPILE)) {
76 effectiveScope = JavaScopes.COMPILE;
77 } else if (scopes.contains(JavaScopes.RUNTIME)) {
78 effectiveScope = JavaScopes.RUNTIME;
79 } else if (scopes.contains(JavaScopes.PROVIDED)) {
80 effectiveScope = JavaScopes.PROVIDED;
81 } else if (scopes.contains(JavaScopes.TEST)) {
82 effectiveScope = JavaScopes.TEST;
83 }
84
85 return effectiveScope;
86 }
87 }