1 package org.apache.maven.archiva.dependency.graph.tasks;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.maven.archiva.dependency.graph.DependencyGraph;
23 import org.apache.maven.archiva.dependency.graph.DependencyGraphEdge;
24 import org.apache.maven.archiva.dependency.graph.DependencyGraphKeys;
25 import org.apache.maven.archiva.dependency.graph.DependencyGraphNode;
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.ArtifactReference;
30 import java.util.Iterator;
31 import java.util.Stack;
34 * FlagExcludedEdgesVisitor
38 public class FlagExcludedEdgesVisitor
40 implements DependencyGraphVisitor
42 private Stack nodePath = new Stack();
44 public void discoverEdge( DependencyGraphEdge edge )
46 ArtifactReference artifact = edge.getNodeTo();
48 // Process for excluded edges.
49 String toKey = DependencyGraphKeys.toManagementKey( artifact );
50 Iterator it = this.nodePath.iterator();
51 while ( it.hasNext() )
53 DependencyGraphNode pathNode = (DependencyGraphNode) it.next();
55 // Process dependency declared exclusions.
56 if ( pathNode.getExcludes().contains( toKey ) )
58 edge.setDisabled( true );
59 edge.setDisabledType( DependencyGraph.DISABLED_EXCLUDED );
60 String whoExcluded = DependencyGraphKeys.toKey( pathNode );
61 edge.setDisabledReason( "Specifically Excluded by " + whoExcluded );
67 public void discoverNode( DependencyGraphNode node )
69 super.discoverNode( node );
70 nodePath.push( node );
73 public void finishNode( DependencyGraphNode node )
75 super.finishNode( node );
76 DependencyGraphNode pathNode = (DependencyGraphNode) nodePath.pop();
77 if ( !node.equals( pathNode ) )
79 String pathNodeKey = ArtifactReference.toKey( pathNode.getArtifact() );
80 String finishNodeKey = ArtifactReference.toKey( node.getArtifact() );
81 throw new IllegalStateException( "Encountered bad visitor state. Expected finish on node " + pathNodeKey
82 + ", but instead got notified of node " + finishNodeKey );