Coverage Report - org.apache.maven.archiva.dependency.graph.tasks.ResolveGraphTask
 
Classes in this File Line Coverage Branch Coverage Complexity
ResolveGraphTask
0%
0/29
0%
0/6
1.429
 
 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.commons.collections.CollectionUtils;
 23  
 import org.apache.maven.archiva.dependency.graph.DependencyGraph;
 24  
 import org.apache.maven.archiva.dependency.graph.DependencyGraphBuilder;
 25  
 import org.apache.maven.archiva.dependency.graph.DependencyGraphNode;
 26  
 import org.apache.maven.archiva.dependency.graph.GraphTask;
 27  
 import org.apache.maven.archiva.dependency.graph.PotentialCyclicEdgeProducer;
 28  
 import org.apache.maven.archiva.dependency.graph.functors.UnresolvedGraphNodePredicate;
 29  
 import org.apache.maven.archiva.model.VersionedReference;
 30  
 
 31  
 /**
 32  
  * Loop through the unresolved nodes and resolve them, until there
 33  
  * are no more unresolved nodes.
 34  
  *
 35  
  * @version $Id: ResolveGraphTask.java 718864 2008-11-19 06:33:35Z brett $
 36  
  */
 37  0
 public class ResolveGraphTask
 38  
     implements GraphTask, PotentialCyclicEdgeProducer
 39  
 {
 40  
     private DependencyGraphBuilder builder;
 41  
     
 42  0
     private int resolvedCount = 0;
 43  
 
 44  
     private VersionedReference toVersionedReference( DependencyGraphNode node )
 45  
     {
 46  0
         VersionedReference ref = new VersionedReference();
 47  0
         ref.setGroupId( node.getArtifact().getGroupId() );
 48  0
         ref.setArtifactId( node.getArtifact().getArtifactId() );
 49  0
         ref.setVersion( node.getArtifact().getVersion() );
 50  
 
 51  0
         return ref;
 52  
     }
 53  
 
 54  
     public void executeTask( DependencyGraph graph )
 55  
     {
 56  0
         resolvedCount = 0;
 57  0
         VersionedReference rootRef = toVersionedReference( graph.getRootNode() );
 58  
 
 59  0
         if ( !graph.getRootNode().isResolved() )
 60  
         {
 61  0
             builder.resolveNode( graph, graph.getRootNode(), rootRef );
 62  0
             resolvedCount++;
 63  
         }
 64  
 
 65  0
         boolean done = false;
 66  
 
 67  0
         while ( !done )
 68  
         {
 69  0
             DependencyGraphNode node = findUnresolvedNode( graph );
 70  0
             if ( node == null )
 71  
             {
 72  0
                 done = true;
 73  0
                 break;
 74  
             }
 75  
 
 76  0
             VersionedReference otherRef = toVersionedReference( node );
 77  
 
 78  0
             builder.resolveNode( graph, node, otherRef );
 79  0
             resolvedCount++;
 80  0
         }
 81  0
     }
 82  
 
 83  
     private DependencyGraphNode findUnresolvedNode( DependencyGraph graph )
 84  
     {
 85  0
         return (DependencyGraphNode) CollectionUtils
 86  
             .find( graph.getNodes(), UnresolvedGraphNodePredicate.getInstance() );
 87  
     }
 88  
 
 89  
     public DependencyGraphBuilder getBuilder()
 90  
     {
 91  0
         return builder;
 92  
     }
 93  
 
 94  
     public void setBuilder( DependencyGraphBuilder graphBuilder )
 95  
     {
 96  0
         this.builder = graphBuilder;
 97  0
     }
 98  
 
 99  
     public String getTaskId()
 100  
     {
 101  0
         return "resolve-graph";
 102  
     }
 103  
 
 104  
     public int getResolvedCount()
 105  
     {
 106  0
         return resolvedCount;
 107  
     }
 108  
 }