1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.resolver.internal.ant.tasks;
20
21 import org.apache.tools.ant.Project;
22 import org.apache.tools.ant.Task;
23 import org.eclipse.aether.artifact.Artifact;
24 import org.eclipse.aether.graph.Dependency;
25 import org.eclipse.aether.graph.DependencyNode;
26 import org.eclipse.aether.graph.DependencyVisitor;
27 import org.eclipse.aether.util.graph.manager.DependencyManagerUtils;
28
29
30
31 class DependencyGraphLogger implements DependencyVisitor {
32
33 private final Task task;
34
35 private String indent = "";
36
37 DependencyGraphLogger(Task task) {
38 this.task = task;
39 }
40
41 @Override
42 public boolean visitEnter(DependencyNode node) {
43 StringBuilder buffer = new StringBuilder(128);
44 buffer.append(indent);
45 Dependency dep = node.getDependency();
46 if (dep != null) {
47 Artifact art = dep.getArtifact();
48
49 buffer.append(art);
50 buffer.append(':').append(dep.getScope());
51
52 String premanagedScope = DependencyManagerUtils.getPremanagedScope(node);
53 if (premanagedScope != null && !premanagedScope.equals(dep.getScope())) {
54 buffer.append(" (scope managed from ").append(premanagedScope).append(")");
55 }
56
57 String premanagedVersion = DependencyManagerUtils.getPremanagedVersion(node);
58 if (premanagedVersion != null && !premanagedVersion.equals(art.getVersion())) {
59 buffer.append(" (version managed from ")
60 .append(premanagedVersion)
61 .append(")");
62 }
63 } else {
64 buffer.append("Resolved Dependency Graph:");
65 }
66
67 task.log(buffer.toString(), Project.MSG_VERBOSE);
68 indent += " ";
69 return true;
70 }
71
72 @Override
73 public boolean visitLeave(DependencyNode node) {
74 indent = indent.substring(0, indent.length() - 3);
75 return true;
76 }
77 }