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.commons.collections.map.MultiValueMap;
24 import org.apache.maven.archiva.dependency.graph.DependencyGraph;
25 import org.apache.maven.archiva.dependency.graph.DependencyGraphKeys;
26 import org.apache.maven.archiva.dependency.graph.DependencyGraphNode;
27 import org.apache.maven.archiva.dependency.graph.GraphTask;
28 import org.apache.maven.archiva.dependency.graph.PotentialCyclicEdgeProducer;
29 import org.apache.maven.archiva.dependency.graph.functors.ToArtifactReferenceTransformer;
30 import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphWalker;
31 import org.apache.maven.archiva.dependency.graph.walk.WalkDepthFirstSearch;
33 import java.util.ArrayList;
34 import java.util.Collection;
35 import java.util.Iterator;
36 import java.util.List;
38 import java.util.Map.Entry;
43 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
47 * role="org.apache.maven.archiva.dependency.graph.GraphTask"
48 * role-hint="refine-conflicts"
49 * instantiation-strategy="per-lookup"
51 public class RefineConflictsTask
52 implements GraphTask, PotentialCyclicEdgeProducer
55 public void executeTask( DependencyGraph graph )
58 DependencyGraphWalker walker = new WalkDepthFirstSearch();
59 RefineConflictsVisitor refineConflictsVisitor = new RefineConflictsVisitor();
61 MultiValueMap depMap = new MultiValueMap();
63 // Identify deps that need to be resolved.
64 it = graph.getNodes().iterator();
65 while ( it.hasNext() )
67 DependencyGraphNode node = (DependencyGraphNode) it.next();
68 String key = DependencyGraphKeys.toManagementKey( node.getArtifact() );
69 // This will add this node to the specified key, not replace a previous one.
70 depMap.put( key, node );
73 // Process those depMap entries with more than 1 value.
74 ToArtifactReferenceTransformer nodeToArtifact = new ToArtifactReferenceTransformer();
76 it = depMap.entrySet().iterator();
77 while ( it.hasNext() )
79 Map.Entry entry = (Entry) it.next();
80 Collection nodes = (Collection) entry.getValue();
81 if ( nodes.size() > 1 )
83 List conflictingArtifacts = new ArrayList();
84 conflictingArtifacts.addAll( nodes );
85 CollectionUtils.transform( conflictingArtifacts, nodeToArtifact );
87 refineConflictsVisitor.resetConflictingArtifacts();
88 refineConflictsVisitor.addAllConflictingArtifacts( conflictingArtifacts );
89 walker.visit( graph, refineConflictsVisitor );
94 public String getTaskId()
96 return "refine-conflicts";