1 | |
package org.apache.maven.archiva.dependency.graph.tasks; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.util.ArrayList; |
23 | |
import java.util.Collection; |
24 | |
import java.util.Iterator; |
25 | |
import java.util.List; |
26 | |
import java.util.Map; |
27 | |
|
28 | |
import org.apache.commons.collections.CollectionUtils; |
29 | |
import org.apache.commons.collections.map.MultiValueMap; |
30 | |
import org.apache.maven.archiva.dependency.graph.DependencyGraph; |
31 | |
import org.apache.maven.archiva.dependency.graph.DependencyGraphKeys; |
32 | |
import org.apache.maven.archiva.dependency.graph.DependencyGraphNode; |
33 | |
import org.apache.maven.archiva.dependency.graph.GraphTask; |
34 | |
import org.apache.maven.archiva.dependency.graph.PotentialCyclicEdgeProducer; |
35 | |
import org.apache.maven.archiva.dependency.graph.functors.ToArtifactReferenceTransformer; |
36 | |
import org.apache.maven.archiva.dependency.graph.walk.DependencyGraphWalker; |
37 | |
import org.apache.maven.archiva.dependency.graph.walk.WalkDepthFirstSearch; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 0 | public class RefineConflictsTask |
45 | |
implements GraphTask, PotentialCyclicEdgeProducer |
46 | |
{ |
47 | |
|
48 | |
@SuppressWarnings("unchecked") |
49 | |
public void executeTask( DependencyGraph graph ) |
50 | |
{ |
51 | 0 | DependencyGraphWalker walker = new WalkDepthFirstSearch(); |
52 | 0 | RefineConflictsVisitor refineConflictsVisitor = new RefineConflictsVisitor(); |
53 | |
|
54 | 0 | MultiValueMap depMap = new MultiValueMap(); |
55 | |
|
56 | |
|
57 | 0 | for ( DependencyGraphNode node : graph.getNodes() ) |
58 | |
{ |
59 | 0 | String key = DependencyGraphKeys.toManagementKey( node.getArtifact() ); |
60 | |
|
61 | 0 | depMap.put( key, node ); |
62 | 0 | } |
63 | |
|
64 | |
|
65 | 0 | ToArtifactReferenceTransformer nodeToArtifact = new ToArtifactReferenceTransformer(); |
66 | |
|
67 | 0 | Iterator<Map.Entry<String,Collection<DependencyGraphNode>>> it = depMap.entrySet().iterator(); |
68 | 0 | while ( it.hasNext() ) |
69 | |
{ |
70 | 0 | Map.Entry<String,Collection<DependencyGraphNode>> entry = it.next(); |
71 | 0 | Collection<DependencyGraphNode> nodes = entry.getValue(); |
72 | 0 | if ( nodes.size() > 1 ) |
73 | |
{ |
74 | 0 | List<DependencyGraphNode> conflictingArtifacts = new ArrayList<DependencyGraphNode>(); |
75 | 0 | conflictingArtifacts.addAll( nodes ); |
76 | 0 | CollectionUtils.transform( conflictingArtifacts, nodeToArtifact ); |
77 | |
|
78 | 0 | refineConflictsVisitor.resetConflictingArtifacts(); |
79 | 0 | refineConflictsVisitor.addAllConflictingArtifacts( conflictingArtifacts ); |
80 | 0 | walker.visit( graph, refineConflictsVisitor ); |
81 | |
} |
82 | 0 | } |
83 | 0 | } |
84 | |
|
85 | |
public String getTaskId() |
86 | |
{ |
87 | 0 | return "refine-conflicts"; |
88 | |
} |
89 | |
} |