Coverage Report - org.apache.maven.archiva.dependency.graph.tasks.FlagExcludedEdgesVisitor
 
Classes in this File Line Coverage Branch Coverage Complexity
FlagExcludedEdgesVisitor
0%
0/22
0%
0/6
0
 
 1  
 package org.apache.maven.archiva.dependency.graph.tasks;
 2  
 
 3  
 /*
 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
 11  
  *
 12  
  *  http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 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
 19  
  * under the License.
 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  
  * FlagExcludedEdgesVisitor 
 34  
  *
 35  
  * @version $Id: FlagExcludedEdgesVisitor.java 755277 2009-03-17 15:18:35Z brett $
 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  
         // Process for excluded edges.
 48  0
         String toKey = DependencyGraphKeys.toManagementKey( artifact );
 49  0
         for ( DependencyGraphNode pathNode : this.nodePath )
 50  
         {
 51  
             // Process dependency declared exclusions.
 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  
 }