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 org.eclipse.aether.RepositoryException;
22 import org.eclipse.aether.collection.DependencyGraphTransformationContext;
23 import org.eclipse.aether.collection.DependencyGraphTransformer;
24 import org.eclipse.aether.graph.Dependency;
25 import org.eclipse.aether.graph.DependencyNode;
26 import org.eclipse.aether.util.artifact.JavaScopes;
27
28 import static java.util.Objects.requireNonNull;
29
30
31
32
33
34
35
36
37
38
39 @Deprecated
40 public final class JavaDependencyContextRefiner implements DependencyGraphTransformer {
41
42 public DependencyNode transformGraph(DependencyNode node, DependencyGraphTransformationContext context)
43 throws RepositoryException {
44 requireNonNull(node, "node cannot be null");
45 requireNonNull(context, "context cannot be null");
46 String ctx = node.getRequestContext();
47
48 if ("project".equals(ctx)) {
49 String scope = getBuildpathScope(node);
50 if (scope != null) {
51 ctx += '/' + scope;
52 node.setRequestContext(ctx);
53 }
54 }
55
56 for (DependencyNode child : node.getChildren()) {
57 transformGraph(child, context);
58 }
59
60 return node;
61 }
62
63 private String getBuildpathScope(DependencyNode node) {
64 Dependency dependency = node.getDependency();
65 if (dependency == null) {
66 return null;
67 }
68
69 String scope = dependency.getScope();
70
71 if (JavaScopes.COMPILE.equals(scope) || JavaScopes.SYSTEM.equals(scope) || JavaScopes.PROVIDED.equals(scope)) {
72 return JavaScopes.COMPILE;
73 } else if (JavaScopes.RUNTIME.equals(scope)) {
74 return JavaScopes.RUNTIME;
75 } else if (JavaScopes.TEST.equals(scope)) {
76 return JavaScopes.TEST;
77 }
78
79 return null;
80 }
81 }