1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.artifact.resolver;
20
21 import java.util.HashSet;
22 import java.util.Objects;
23 import java.util.Set;
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.artifact.versioning.VersionRange;
26 import org.codehaus.plexus.logging.Logger;
27
28
29
30
31
32
33 public class DebugResolutionListener implements ResolutionListener, ResolutionListenerForDepMgmt {
34 private Logger logger;
35
36 private String indent = "";
37
38 private static Set<Artifact> ignoredArtifacts = new HashSet<>();
39
40 public DebugResolutionListener(Logger logger) {
41 this.logger = logger;
42 }
43
44 public void testArtifact(Artifact node) {}
45
46 public void startProcessChildren(Artifact artifact) {
47 indent += " ";
48 }
49
50 public void endProcessChildren(Artifact artifact) {
51 indent = indent.substring(2);
52 }
53
54 public void includeArtifact(Artifact artifact) {
55 logger.debug(indent + artifact + " (selected for " + artifact.getScope() + ")");
56 }
57
58 public void omitForNearer(Artifact omitted, Artifact kept) {
59 String omittedVersion = omitted.getVersion();
60 String keptVersion = kept.getVersion();
61
62 if (!Objects.equals(omittedVersion, keptVersion)) {
63 logger.debug(indent + omitted + " (removed - nearer found: " + keptVersion + ")");
64 }
65 }
66
67 public void omitForCycle(Artifact omitted) {
68 logger.debug(indent + omitted + " (removed - causes a cycle in the graph)");
69 }
70
71 public void updateScopeCurrentPom(Artifact artifact, String ignoredScope) {
72 logger.debug(indent + artifact + " (not setting artifactScope to: " + ignoredScope + "; local artifactScope "
73 + artifact.getScope() + " wins)");
74
75
76 if (!ignoredArtifacts.contains(artifact)) {
77 logger.warn("\n\tArtifact " + artifact + " retains local artifactScope '" + artifact.getScope()
78 + "' overriding broader artifactScope '" + ignoredScope + "'\n"
79 + "\tgiven by a dependency. If this is not intended, modify or remove the local artifactScope.\n");
80 ignoredArtifacts.add(artifact);
81 }
82 }
83
84 public void updateScope(Artifact artifact, String scope) {
85 logger.debug(indent + artifact + " (setting artifactScope to: " + scope + ")");
86 }
87
88 public void selectVersionFromRange(Artifact artifact) {
89 logger.debug(indent + artifact + " (setting version to: " + artifact.getVersion() + " from range: "
90 + artifact.getVersionRange() + ")");
91 }
92
93 public void restrictRange(Artifact artifact, Artifact replacement, VersionRange newRange) {
94 logger.debug(indent + artifact + " (range restricted from: " + artifact.getVersionRange() + " and: "
95 + replacement.getVersionRange() + " to: " + newRange + " )");
96 }
97
98
99
100
101
102
103
104 public void manageArtifact(Artifact artifact, Artifact replacement) {
105 String msg = indent + artifact;
106 msg += " (";
107 if (replacement.getVersion() != null) {
108 msg += "applying version: " + replacement.getVersion() + ";";
109 }
110 if (replacement.getScope() != null) {
111 msg += "applying artifactScope: " + replacement.getScope();
112 }
113 msg += ")";
114 logger.debug(msg);
115 }
116
117 public void manageArtifactVersion(Artifact artifact, Artifact replacement) {
118
119 if (!replacement.getVersion().equals(artifact.getVersion())) {
120 String msg = indent + artifact + " (applying version: " + replacement.getVersion() + ")";
121 logger.debug(msg);
122 }
123 }
124
125 public void manageArtifactScope(Artifact artifact, Artifact replacement) {
126
127 if (!replacement.getScope().equals(artifact.getScope())) {
128 String msg = indent + artifact + " (applying artifactScope: " + replacement.getScope() + ")";
129 logger.debug(msg);
130 }
131 }
132
133 public void manageArtifactSystemPath(Artifact artifact, Artifact replacement) {
134
135 if (!replacement.getScope().equals(artifact.getScope())) {
136 String msg = indent + artifact + " (applying system path: " + replacement.getFile() + ")";
137 logger.debug(msg);
138 }
139 }
140 }