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