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