Coverage Report - org.apache.maven.archiva.dependency.graph.tasks.DependencyManagementStack
 
Classes in this File Line Coverage Branch Coverage Complexity
DependencyManagementStack
0%
0/40
0%
0/8
0
DependencyManagementStack$Rules
0%
0/7
0%
0/2
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.HashMap;
 23  
 import java.util.HashSet;
 24  
 import java.util.List;
 25  
 import java.util.Map;
 26  
 import java.util.Set;
 27  
 import java.util.Stack;
 28  
 
 29  
 import org.apache.commons.collections.iterators.ReverseListIterator;
 30  
 import org.apache.commons.lang.StringUtils;
 31  
 import org.apache.maven.archiva.dependency.graph.DependencyGraphEdge;
 32  
 import org.apache.maven.archiva.dependency.graph.DependencyGraphKeys;
 33  
 import org.apache.maven.archiva.dependency.graph.DependencyGraphNode;
 34  
 import org.apache.maven.archiva.model.ArtifactReference;
 35  
 import org.apache.maven.archiva.model.Dependency;
 36  
 import org.apache.maven.archiva.model.Exclusion;
 37  
 
 38  
 /**
 39  
  * DependencyManagementStack 
 40  
  *
 41  
  * @version $Id: DependencyManagementStack.java 755277 2009-03-17 15:18:35Z brett $
 42  
  */
 43  0
 public class DependencyManagementStack
 44  
 {
 45  0
     public class Rules
 46  
     {
 47  
         public ArtifactReference artifact;
 48  
 
 49  
         public String scope;
 50  
 
 51  0
         public Set<String> exclusions = new HashSet<String>();
 52  
 
 53  
         public void addAllExclusions( List<Exclusion> depExclusions )
 54  
         {
 55  0
             for ( Exclusion ref : depExclusions )
 56  
             {
 57  0
                 String key = DependencyGraphKeys.toManagementKey( ref );
 58  0
                 exclusions.add( key );
 59  0
             }
 60  0
         }
 61  
     }
 62  
 
 63  0
     private Stack<DependencyGraphNode> depmanStack = new Stack<DependencyGraphNode>();
 64  
 
 65  0
     private Map<String, Rules> depMap = new HashMap<String, Rules>();
 66  
 
 67  
     private void generateDepMap()
 68  
     {
 69  0
         depMap.clear();
 70  
 
 71  
         // Using a reverse iterator to ensure that we read the
 72  
         // stack from last in to first in
 73  0
         ReverseListIterator it = new ReverseListIterator( depmanStack );
 74  0
         while ( it.hasNext() )
 75  
         {
 76  0
             DependencyGraphNode node = (DependencyGraphNode) it.next();
 77  
 
 78  0
             addDependencies( node.getDependencyManagement() );
 79  0
         }
 80  0
     }
 81  
 
 82  
     private void addDependencies( List<Dependency> dependencies )
 83  
     {
 84  0
         for ( Dependency dep : dependencies )
 85  
         {
 86  0
             String key = DependencyGraphKeys.toManagementKey( dep );
 87  
 
 88  0
             Rules merged = (Rules) depMap.get( key );
 89  0
             if ( merged == null )
 90  
             {
 91  
                 // New map entry.
 92  0
                 merged = new Rules();
 93  0
                 merged.artifact = new ArtifactReference();
 94  0
                 merged.artifact.setGroupId( dep.getGroupId() );
 95  0
                 merged.artifact.setArtifactId( dep.getArtifactId() );
 96  0
                 merged.artifact.setClassifier( dep.getClassifier() );
 97  0
                 merged.artifact.setType( dep.getType() );
 98  
             }
 99  
 
 100  0
             merged.artifact.setVersion( dep.getVersion() );
 101  0
             if ( StringUtils.isNotBlank( dep.getScope() ) )
 102  
             {
 103  0
                 merged.scope = dep.getScope();
 104  
             }
 105  
 
 106  0
             merged.addAllExclusions( dep.getExclusions() );
 107  
 
 108  0
             depMap.put( key, merged );
 109  0
         }
 110  0
     }
 111  
 
 112  
     public Rules getRules( DependencyGraphEdge edge )
 113  
     {
 114  0
         return getRules( edge.getNodeTo() );
 115  
     }
 116  
 
 117  
     public Rules getRules( DependencyGraphNode node )
 118  
     {
 119  0
         return getRules( node.getArtifact() );
 120  
     }
 121  
 
 122  
     public Rules getRules( ArtifactReference ref )
 123  
     {
 124  0
         String key = DependencyGraphKeys.toManagementKey( ref );
 125  0
         return (Rules) depMap.get( key );
 126  
     }
 127  
 
 128  
     public void push( DependencyGraphNode node )
 129  
     {
 130  0
         depmanStack.push( node );
 131  0
         generateDepMap();
 132  0
     }
 133  
 
 134  
     public DependencyGraphNode pop()
 135  
     {
 136  0
         DependencyGraphNode node = (DependencyGraphNode) depmanStack.pop();
 137  0
         generateDepMap();
 138  0
         return node;
 139  
     }
 140  
 
 141  
     public void reset()
 142  
     {
 143  0
         depmanStack.clear();
 144  0
         depMap.clear();
 145  0
     }
 146  
 }