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.DependencyScopes;
27 import org.eclipse.aether.util.artifact.JavaScopes;
28 import org.eclipse.aether.util.graph.transformer.ConflictResolver.ConflictContext;
29 import org.eclipse.aether.util.graph.transformer.ConflictResolver.ConflictItem;
30 import org.eclipse.aether.util.graph.transformer.ConflictResolver.ScopeSelector;
31
32
33
34
35
36
37
38
39
40
41 @Deprecated
42 public final class JavaScopeSelector extends ScopeSelector {
43
44
45
46
47 public JavaScopeSelector() {}
48
49 @Override
50 public void selectScope(ConflictContext context) throws RepositoryException {
51 String scope = context.getWinner().getDependency().getScope();
52 if (!JavaScopes.SYSTEM.equals(scope)) {
53 scope = chooseEffectiveScope(context.getItems());
54 }
55 context.setScope(scope);
56 }
57
58 private String chooseEffectiveScope(Collection<ConflictItem> items) {
59 Set<String> scopes = new HashSet<>();
60 for (ConflictItem item : items) {
61 if (item.getDepth() <= 1) {
62 return item.getDependency().getScope();
63 }
64 scopes.addAll(item.getScopes());
65 }
66 return chooseEffectiveScope(scopes);
67 }
68
69 private String chooseEffectiveScope(Set<String> scopes) {
70 if (scopes.size() > 1) {
71 scopes.remove(JavaScopes.SYSTEM);
72 }
73
74 String effectiveScope = "";
75
76 if (scopes.size() == 1) {
77 effectiveScope = scopes.iterator().next();
78 } else if (scopes.contains(JavaScopes.COMPILE)) {
79 effectiveScope = JavaScopes.COMPILE;
80 } else if (scopes.contains(JavaScopes.RUNTIME)) {
81 effectiveScope = JavaScopes.RUNTIME;
82 } else if (scopes.contains(JavaScopes.PROVIDED)) {
83 effectiveScope = JavaScopes.PROVIDED;
84 } else if (scopes.contains(JavaScopes.TEST)) {
85 effectiveScope = JavaScopes.TEST;
86 }
87
88 return effectiveScope;
89 }
90 }