1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.internal.impl.scope;
20
21 import org.eclipse.aether.impl.scope.InternalScopeManager;
22 import org.eclipse.aether.scope.DependencyScope;
23 import org.eclipse.aether.scope.ScopeManager;
24 import org.eclipse.aether.util.graph.transformer.ConflictResolver;
25 import org.eclipse.aether.util.graph.transformer.ConflictResolver.ScopeContext;
26 import org.eclipse.aether.util.graph.transformer.ConflictResolver.ScopeDeriver;
27
28 import static java.util.Objects.requireNonNull;
29
30
31
32
33
34
35
36
37
38 public final class ManagedScopeDeriver extends ScopeDeriver {
39 private final InternalScopeManager scopeManager;
40 private final DependencyScope systemScope;
41
42 public ManagedScopeDeriver(InternalScopeManager scopeManager) {
43 this.scopeManager = requireNonNull(scopeManager, "scopeManager");
44 this.systemScope = scopeManager.getSystemDependencyScope().orElse(null);
45 }
46
47 @Override
48 public void deriveScope(ScopeContext context) {
49 context.setDerivedScope(getDerivedScope(context.getParentScope(), context.getChildScope()));
50 }
51
52
53
54
55 public String getDerivedScope(String parentScope, String childScope) {
56
57 DependencyScope parent = parentScope != null
58 ? scopeManager.getDependencyScope(parentScope).orElse(null)
59 : null;
60
61 DependencyScope child = scopeManager.getDependencyScope(childScope).orElse(null);
62
63
64 if (systemScope != null && systemScope == child) {
65 return systemScope.getId();
66 }
67
68 if (parent == null) {
69 return child != null ? child.getId() : "";
70 }
71 if (child == null) {
72 return parent.getId();
73 }
74
75 int parentWidth = scopeManager.getDependencyScopeWidth(parent);
76 int childWidth = scopeManager.getDependencyScopeWidth(child);
77 if (parentWidth < childWidth) {
78 return parent.getId();
79 } else {
80 return child.getId();
81 }
82 }
83 }