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