Coverage Report - org.apache.maven.archiva.dependency.graph.tasks.RefineConflictsTask
 
Classes in this File Line Coverage Branch Coverage Complexity
RefineConflictsTask
0%
0/23
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.ArrayList;
 23  
 import java.util.Collection;
 24  
 import java.util.Iterator;
 25  
 import java.util.List;
 26  
 import java.util.Map;
 27  
 
 28  
 import org.apache.commons.collections.CollectionUtils;
 29  
 import org.apache.commons.collections.map.MultiValueMap;
 30  
 import org.apache.maven.archiva.dependency.graph.DependencyGraph;
 31  
 import org.apache.maven.archiva.dependency.graph.DependencyGraphKeys;
 32  
 import org.apache.maven.archiva.dependency.graph.DependencyGraphNode;
 33  
 import org.apache.maven.archiva.dependency.graph.GraphTask;
 34  
 import org.apache.maven.archiva.dependency.graph.PotentialCyclicEdgeProducer;
 35  
 import org.apache.maven.archiva.dependency.graph.functors.ToArtifactReferenceTransformer;
 36  
 import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphWalker;
 37  
 import org.apache.maven.archiva.dependency.graph.walk.WalkDepthFirstSearch;
 38  
 
 39  
 /**
 40  
  * RefineConflictsTask 
 41  
  *
 42  
  * @version $Id: RefineConflictsTask.java 755277 2009-03-17 15:18:35Z brett $
 43  
  */
 44  0
 public class RefineConflictsTask
 45  
     implements GraphTask, PotentialCyclicEdgeProducer
 46  
 {
 47  
 
 48  
     @SuppressWarnings("unchecked")
 49  
     public void executeTask( DependencyGraph graph )
 50  
     {
 51  0
         DependencyGraphWalker walker = new WalkDepthFirstSearch();
 52  0
         RefineConflictsVisitor refineConflictsVisitor = new RefineConflictsVisitor();
 53  
         
 54  0
         MultiValueMap depMap = new MultiValueMap();
 55  
 
 56  
         // Identify deps that need to be resolved.
 57  0
         for ( DependencyGraphNode node : graph.getNodes() )
 58  
         {
 59  0
             String key = DependencyGraphKeys.toManagementKey( node.getArtifact() );
 60  
             // This will add this node to the specified key, not replace a previous one.
 61  0
             depMap.put( key, node );
 62  0
         }
 63  
 
 64  
         // Process those depMap entries with more than 1 value. 
 65  0
         ToArtifactReferenceTransformer nodeToArtifact = new ToArtifactReferenceTransformer();
 66  
 
 67  0
         Iterator<Map.Entry<String,Collection<DependencyGraphNode>>> it = depMap.entrySet().iterator();
 68  0
         while ( it.hasNext() )
 69  
         {
 70  0
             Map.Entry<String,Collection<DependencyGraphNode>> entry = it.next();
 71  0
             Collection<DependencyGraphNode> nodes = entry.getValue();
 72  0
             if ( nodes.size() > 1 )
 73  
             {
 74  0
                 List<DependencyGraphNode> conflictingArtifacts = new ArrayList<DependencyGraphNode>();
 75  0
                 conflictingArtifacts.addAll( nodes );
 76  0
                 CollectionUtils.transform( conflictingArtifacts, nodeToArtifact );
 77  
 
 78  0
                 refineConflictsVisitor.resetConflictingArtifacts();
 79  0
                 refineConflictsVisitor.addAllConflictingArtifacts( conflictingArtifacts );
 80  0
                 walker.visit( graph, refineConflictsVisitor );
 81  
             }
 82  0
         }
 83  0
     }
 84  
 
 85  
     public String getTaskId()
 86  
     {
 87  0
         return "refine-conflicts";
 88  
     }
 89  
 }