1 package org.eclipse.aether.util.graph.transformer;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.eclipse.aether.RepositoryException;
23 import org.eclipse.aether.collection.DependencyGraphTransformationContext;
24 import org.eclipse.aether.collection.DependencyGraphTransformer;
25 import org.eclipse.aether.graph.Dependency;
26 import org.eclipse.aether.graph.DependencyNode;
27 import org.eclipse.aether.util.artifact.JavaScopes;
28
29
30
31
32
33
34
35
36 public final class JavaDependencyContextRefiner
37 implements DependencyGraphTransformer
38 {
39
40 public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context )
41 throws RepositoryException
42 {
43 String ctx = node.getRequestContext();
44
45 if ( "project".equals( ctx ) )
46 {
47 String scope = getClasspathScope( node );
48 if ( scope != null )
49 {
50 ctx += '/' + scope;
51 node.setRequestContext( ctx );
52 }
53 }
54
55 for ( DependencyNode child : node.getChildren() )
56 {
57 transformGraph( child, context );
58 }
59
60 return node;
61 }
62
63 private String getClasspathScope( DependencyNode node )
64 {
65 Dependency dependency = node.getDependency();
66 if ( dependency == null )
67 {
68 return null;
69 }
70
71 String scope = dependency.getScope();
72
73 if ( JavaScopes.COMPILE.equals( scope ) || JavaScopes.SYSTEM.equals( scope )
74 || JavaScopes.PROVIDED.equals( scope ) )
75 {
76 return JavaScopes.COMPILE;
77 }
78 else if ( JavaScopes.RUNTIME.equals( scope ) )
79 {
80 return JavaScopes.RUNTIME;
81 }
82 else if ( JavaScopes.TEST.equals( scope ) )
83 {
84 return JavaScopes.TEST;
85 }
86
87 return null;
88 }
89
90 }