]> source.dussan.org Git - archiva.git/blob
ebe7841096507e39f6f0e61d4c6dba6c56ab59d8
[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.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  * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
36  * @version $Id$
37  * 
38  * @plexus.component 
39  *      role="org.apache.maven.archiva.dependency.graph.GraphTask"
40  *      role-hint="resolve-graph"
41  *      instantiation-strategy="per-lookup"
42  */
43 public class ResolveGraphTask
44     implements GraphTask, PotentialCyclicEdgeProducer
45 {
46     private DependencyGraphBuilder builder;
47     
48     private int resolvedCount = 0;
49
50     private VersionedReference toVersionedReference( DependencyGraphNode node )
51     {
52         VersionedReference ref = new VersionedReference();
53         ref.setGroupId( node.getArtifact().getGroupId() );
54         ref.setArtifactId( node.getArtifact().getArtifactId() );
55         ref.setVersion( node.getArtifact().getVersion() );
56
57         return ref;
58     }
59
60     public void executeTask( DependencyGraph graph )
61     {
62         resolvedCount = 0;
63         VersionedReference rootRef = toVersionedReference( graph.getRootNode() );
64
65         if ( !graph.getRootNode().isResolved() )
66         {
67             builder.resolveNode( graph, graph.getRootNode(), rootRef );
68             resolvedCount++;
69         }
70
71         boolean done = false;
72
73         while ( !done )
74         {
75             DependencyGraphNode node = findUnresolvedNode( graph );
76             if ( node == null )
77             {
78                 done = true;
79                 break;
80             }
81
82             VersionedReference otherRef = toVersionedReference( node );
83
84             builder.resolveNode( graph, node, otherRef );
85             resolvedCount++;
86         }
87     }
88
89     private DependencyGraphNode findUnresolvedNode( DependencyGraph graph )
90     {
91         return (DependencyGraphNode) CollectionUtils
92             .find( graph.getNodes(), UnresolvedGraphNodePredicate.getInstance() );
93     }
94
95     public DependencyGraphBuilder getBuilder()
96     {
97         return builder;
98     }
99
100     public void setBuilder( DependencyGraphBuilder graphBuilder )
101     {
102         this.builder = graphBuilder;
103     }
104
105     public String getTaskId()
106     {
107         return "resolve-graph";
108     }
109
110     public int getResolvedCount()
111     {
112         return resolvedCount;
113     }
114 }