1 package org.eclipse.aether.util.graph.transformer;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.IdentityHashMap;
23 import java.util.Map;
24
25 import org.eclipse.aether.RepositoryException;
26 import org.eclipse.aether.artifact.Artifact;
27 import org.eclipse.aether.collection.DependencyGraphTransformationContext;
28 import org.eclipse.aether.collection.DependencyGraphTransformer;
29 import org.eclipse.aether.graph.Dependency;
30 import org.eclipse.aether.graph.DependencyNode;
31 import org.eclipse.aether.util.graph.transformer.TransformationContextKeys;
32
33
34
35
36 class SimpleConflictMarker
37 implements DependencyGraphTransformer
38 {
39
40 public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context )
41 throws RepositoryException
42 {
43 @SuppressWarnings( "unchecked" )
44 Map<DependencyNode, Object> conflictIds =
45 (Map<DependencyNode, Object>) context.get( TransformationContextKeys.CONFLICT_IDS );
46 if ( conflictIds == null )
47 {
48 conflictIds = new IdentityHashMap<DependencyNode, Object>();
49 context.put( TransformationContextKeys.CONFLICT_IDS, conflictIds );
50 }
51
52 mark( node, conflictIds );
53
54 return node;
55 }
56
57 private void mark( DependencyNode node, Map<DependencyNode, Object> conflictIds )
58 {
59 Dependency dependency = node.getDependency();
60 if ( dependency != null )
61 {
62 Artifact artifact = dependency.getArtifact();
63
64 String key =
65 String.format( "%s:%s:%s:%s", artifact.getGroupId(), artifact.getArtifactId(),
66 artifact.getClassifier(), artifact.getExtension() );
67
68 if ( conflictIds.put( node, key ) != null )
69 {
70 return;
71 }
72 }
73
74 for ( DependencyNode child : node.getChildren() )
75 {
76 mark( child, conflictIds );
77 }
78 }
79
80 }