]> source.dussan.org Git - archiva.git/blob
804cdc3042eaffb9f511a849946ab7fc8736aa0b
[archiva.git] /
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 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;
29
30 import java.util.Iterator;
31 import java.util.Stack;
32
33 /**
34  * FlagExcludedEdgesVisitor 
35  *
36  * @version $Id$
37  */
38 public class FlagExcludedEdgesVisitor
39     extends BaseVisitor
40     implements DependencyGraphVisitor
41 {
42     private Stack nodePath = new Stack();
43
44     public void discoverEdge( DependencyGraphEdge edge )
45     {
46         ArtifactReference artifact = edge.getNodeTo(); 
47         
48         // Process for excluded edges.
49         String toKey = DependencyGraphKeys.toManagementKey( artifact );
50         Iterator it = this.nodePath.iterator();
51         while ( it.hasNext() )
52         {
53             DependencyGraphNode pathNode = (DependencyGraphNode) it.next();
54         
55             // Process dependency declared exclusions.
56             if ( pathNode.getExcludes().contains( toKey ) )
57             {
58                 edge.setDisabled( true );
59                 edge.setDisabledType( DependencyGraph.DISABLED_EXCLUDED );
60                 String whoExcluded = DependencyGraphKeys.toKey( pathNode );
61                 edge.setDisabledReason( "Specifically Excluded by " + whoExcluded );
62                 break;
63             }
64         }
65     }
66
67     public void discoverNode( DependencyGraphNode node )
68     {
69         super.discoverNode( node );
70         nodePath.push( node );
71     }
72
73     public void finishNode( DependencyGraphNode node )
74     {
75         super.finishNode( node );
76         DependencyGraphNode pathNode = (DependencyGraphNode) nodePath.pop();
77         if ( !node.equals( pathNode ) )
78         {
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 );
83         }
84     }
85 }