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;
45 public class RefineConflictsTask
46 implements GraphTask, PotentialCyclicEdgeProducer
49 public void executeTask( DependencyGraph graph )
52 DependencyGraphWalker walker = new WalkDepthFirstSearch();
53 RefineConflictsVisitor refineConflictsVisitor = new RefineConflictsVisitor();
55 MultiValueMap depMap = new MultiValueMap();
57 // Identify deps that need to be resolved.
58 it = graph.getNodes().iterator();
59 while ( it.hasNext() )
61 DependencyGraphNode node = (DependencyGraphNode) it.next();
62 String key = DependencyGraphKeys.toManagementKey( node.getArtifact() );
63 // This will add this node to the specified key, not replace a previous one.
64 depMap.put( key, node );
67 // Process those depMap entries with more than 1 value.
68 ToArtifactReferenceTransformer nodeToArtifact = new ToArtifactReferenceTransformer();
70 it = depMap.entrySet().iterator();
71 while ( it.hasNext() )
73 Map.Entry entry = (Entry) it.next();
74 Collection nodes = (Collection) entry.getValue();
75 if ( nodes.size() > 1 )
77 List conflictingArtifacts = new ArrayList();
78 conflictingArtifacts.addAll( nodes );
79 CollectionUtils.transform( conflictingArtifacts, nodeToArtifact );
81 refineConflictsVisitor.resetConflictingArtifacts();
82 refineConflictsVisitor.addAllConflictingArtifacts( conflictingArtifacts );
83 walker.visit( graph, refineConflictsVisitor );
88 public String getTaskId()
90 return "refine-conflicts";