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