1 | |
package org.apache.maven.archiva.dependency.graph.tasks; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.commons.collections.Predicate; |
23 | |
import org.apache.maven.archiva.dependency.graph.DependencyGraph; |
24 | |
import org.apache.maven.archiva.dependency.graph.DependencyGraphEdge; |
25 | |
import org.apache.maven.archiva.dependency.graph.functors.EdgeFromPredicate; |
26 | |
import org.apache.maven.archiva.dependency.graph.walk.BaseVisitor; |
27 | |
import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphVisitor; |
28 | |
import org.apache.maven.archiva.model.DependencyScope; |
29 | |
|
30 | |
import java.util.Stack; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class UpdateScopesVisitor |
38 | |
extends BaseVisitor |
39 | |
implements DependencyGraphVisitor |
40 | |
{ |
41 | |
private Stack<String> scopeStack; |
42 | |
|
43 | |
private Predicate rootEdgePredicate; |
44 | |
|
45 | |
public UpdateScopesVisitor() |
46 | 0 | { |
47 | 0 | scopeStack = new Stack<String>(); |
48 | |
|
49 | 0 | scopeStack.add( DependencyScope.COMPILE ); |
50 | 0 | } |
51 | |
|
52 | |
public void discoverGraph( DependencyGraph graph ) |
53 | |
{ |
54 | 0 | super.discoverGraph( graph ); |
55 | 0 | rootEdgePredicate = new EdgeFromPredicate( graph.getRootNode() ); |
56 | 0 | } |
57 | |
|
58 | |
public void discoverEdge( DependencyGraphEdge edge ) |
59 | |
{ |
60 | 0 | super.discoverEdge( edge ); |
61 | |
|
62 | 0 | String scope = edge.getScope(); |
63 | |
|
64 | 0 | if ( !rootEdgePredicate.evaluate( edge ) ) |
65 | |
{ |
66 | |
|
67 | 0 | scope = (String) scopeStack.peek(); |
68 | 0 | edge.setScope( scope ); |
69 | |
} |
70 | |
|
71 | |
|
72 | 0 | scopeStack.push( scope ); |
73 | 0 | } |
74 | |
|
75 | |
public void finishEdge( DependencyGraphEdge edge ) |
76 | |
{ |
77 | 0 | super.finishEdge( edge ); |
78 | |
|
79 | 0 | scopeStack.pop(); |
80 | 0 | } |
81 | |
} |