1 package org.apache.maven.archiva.dependency.graph.tasks;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
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;
32 * Loop through the unresolved nodes and resolve them, until there
33 * are no more unresolved nodes.
35 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
39 * role="org.apache.maven.archiva.dependency.graph.GraphTask"
40 * role-hint="resolve-graph"
41 * instantiation-strategy="per-lookup"
43 public class ResolveGraphTask
44 implements GraphTask, PotentialCyclicEdgeProducer
46 private DependencyGraphBuilder builder;
48 private int resolvedCount = 0;
50 private VersionedReference toVersionedReference( DependencyGraphNode node )
52 VersionedReference ref = new VersionedReference();
53 ref.setGroupId( node.getArtifact().getGroupId() );
54 ref.setArtifactId( node.getArtifact().getArtifactId() );
55 ref.setVersion( node.getArtifact().getVersion() );
60 public void executeTask( DependencyGraph graph )
63 VersionedReference rootRef = toVersionedReference( graph.getRootNode() );
65 if ( !graph.getRootNode().isResolved() )
67 builder.resolveNode( graph, graph.getRootNode(), rootRef );
75 DependencyGraphNode node = findUnresolvedNode( graph );
82 VersionedReference otherRef = toVersionedReference( node );
84 builder.resolveNode( graph, node, otherRef );
89 private DependencyGraphNode findUnresolvedNode( DependencyGraph graph )
91 return (DependencyGraphNode) CollectionUtils
92 .find( graph.getNodes(), UnresolvedGraphNodePredicate.getInstance() );
95 public DependencyGraphBuilder getBuilder()
100 public void setBuilder( DependencyGraphBuilder graphBuilder )
102 this.builder = graphBuilder;
105 public String getTaskId()
107 return "resolve-graph";
110 public int getResolvedCount()
112 return resolvedCount;