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 import static java.util.Objects.requireNonNull;
25
26 import org.eclipse.aether.RepositoryException;
27 import org.eclipse.aether.artifact.Artifact;
28 import org.eclipse.aether.collection.DependencyGraphTransformationContext;
29 import org.eclipse.aether.collection.DependencyGraphTransformer;
30 import org.eclipse.aether.graph.Dependency;
31 import org.eclipse.aether.graph.DependencyNode;
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 requireNonNull( node, "node cannot be null" );
44 requireNonNull( context, "context cannot be null" );
45 @SuppressWarnings( "unchecked" )
46 Map<DependencyNode, Object> conflictIds =
47 (Map<DependencyNode, Object>) context.get( TransformationContextKeys.CONFLICT_IDS );
48 if ( conflictIds == null )
49 {
50 conflictIds = new IdentityHashMap<>();
51 context.put( TransformationContextKeys.CONFLICT_IDS, conflictIds );
52 }
53
54 mark( node, conflictIds );
55
56 return node;
57 }
58
59 private void mark( DependencyNode node, Map<DependencyNode, Object> conflictIds )
60 {
61 Dependency dependency = node.getDependency();
62 if ( dependency != null )
63 {
64 Artifact artifact = dependency.getArtifact();
65
66 String key =
67 String.format( "%s:%s:%s:%s", artifact.getGroupId(), artifact.getArtifactId(),
68 artifact.getClassifier(), artifact.getExtension() );
69
70 if ( conflictIds.put( node, key ) != null )
71 {
72 return;
73 }
74 }
75
76 for ( DependencyNode child : node.getChildren() )
77 {
78 mark( child, conflictIds );
79 }
80 }
81
82 }