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 java.util.Stack; |
23 | |
|
24 | |
import org.apache.maven.archiva.dependency.graph.DependencyGraph; |
25 | |
import org.apache.maven.archiva.dependency.graph.DependencyGraphEdge; |
26 | |
import org.apache.maven.archiva.dependency.graph.DependencyGraphKeys; |
27 | |
import org.apache.maven.archiva.dependency.graph.DependencyGraphNode; |
28 | |
import org.apache.maven.archiva.dependency.graph.walk.BaseVisitor; |
29 | |
import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphVisitor; |
30 | |
import org.apache.maven.archiva.model.ArtifactReference; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public class FlagExcludedEdgesVisitor |
38 | |
extends BaseVisitor |
39 | |
implements DependencyGraphVisitor |
40 | |
{ |
41 | 0 | private Stack<DependencyGraphNode> nodePath = new Stack<DependencyGraphNode>(); |
42 | |
|
43 | |
public void discoverEdge( DependencyGraphEdge edge ) |
44 | |
{ |
45 | 0 | ArtifactReference artifact = edge.getNodeTo(); |
46 | |
|
47 | |
|
48 | 0 | String toKey = DependencyGraphKeys.toManagementKey( artifact ); |
49 | 0 | for ( DependencyGraphNode pathNode : this.nodePath ) |
50 | |
{ |
51 | |
|
52 | 0 | if ( pathNode.getExcludes().contains( toKey ) ) |
53 | |
{ |
54 | 0 | edge.setDisabled( true ); |
55 | 0 | edge.setDisabledType( DependencyGraph.DISABLED_EXCLUDED ); |
56 | 0 | String whoExcluded = DependencyGraphKeys.toKey( pathNode ); |
57 | 0 | edge.setDisabledReason( "Specifically Excluded by " + whoExcluded ); |
58 | 0 | break; |
59 | |
} |
60 | |
} |
61 | 0 | } |
62 | |
|
63 | |
public void discoverNode( DependencyGraphNode node ) |
64 | |
{ |
65 | 0 | super.discoverNode( node ); |
66 | 0 | nodePath.push( node ); |
67 | 0 | } |
68 | |
|
69 | |
public void finishNode( DependencyGraphNode node ) |
70 | |
{ |
71 | 0 | super.finishNode( node ); |
72 | 0 | DependencyGraphNode pathNode = (DependencyGraphNode) nodePath.pop(); |
73 | 0 | if ( !node.equals( pathNode ) ) |
74 | |
{ |
75 | 0 | String pathNodeKey = ArtifactReference.toKey( pathNode.getArtifact() ); |
76 | 0 | String finishNodeKey = ArtifactReference.toKey( node.getArtifact() ); |
77 | 0 | throw new IllegalStateException( "Encountered bad visitor state. Expected finish on node " + pathNodeKey |
78 | |
+ ", but instead got notified of node " + finishNodeKey ); |
79 | |
} |
80 | 0 | } |
81 | |
} |