1 package org.apache.maven.plugin.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Collection;
23 import java.util.IdentityHashMap;
24 import java.util.Iterator;
25 import java.util.LinkedList;
26 import java.util.Map;
27
28 import org.apache.maven.artifact.Artifact;
29 import org.apache.maven.artifact.resolver.ResolutionListener;
30 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
31 import org.apache.maven.artifact.versioning.VersionRange;
32
33
34
35
36
37
38
39
40
41
42
43 class PluginDependencyResolutionListener
44 implements ResolutionListener
45 {
46
47 private ArtifactFilter coreFilter;
48
49 private LinkedList<Artifact> coreArtifacts = new LinkedList<Artifact>();
50
51 private Artifact wagonProvider;
52
53 private Map<Artifact, Object> bannedArtifacts = new IdentityHashMap<Artifact, Object>();
54
55 public PluginDependencyResolutionListener( ArtifactFilter coreFilter )
56 {
57 this.coreFilter = coreFilter;
58 }
59
60 public void removeBannedDependencies( Collection<Artifact> artifacts )
61 {
62 if ( !bannedArtifacts.isEmpty() && artifacts != null )
63 {
64 for ( Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); )
65 {
66 Artifact artifact = it.next();
67 if ( bannedArtifacts.containsKey( artifact ) )
68 {
69 it.remove();
70 }
71 }
72 }
73 }
74
75 public void startProcessChildren( Artifact artifact )
76 {
77 if ( wagonProvider == null )
78 {
79 if ( isLegacyCoreArtifact( artifact ) )
80 {
81 coreArtifacts.addFirst( artifact );
82 }
83 else if ( !coreArtifacts.isEmpty() && isWagonProvider( artifact ) )
84 {
85 wagonProvider = artifact;
86 bannedArtifacts.put( artifact, null );
87 }
88 }
89 }
90
91 private boolean isLegacyCoreArtifact( Artifact artifact )
92 {
93 String version = artifact.getVersion();
94 return version != null && version.startsWith( "2." ) && !coreFilter.include( artifact );
95 }
96
97 public void endProcessChildren( Artifact artifact )
98 {
99 if ( wagonProvider == artifact )
100 {
101 wagonProvider = null;
102 }
103 else if ( coreArtifacts.peek() == artifact )
104 {
105 coreArtifacts.removeFirst();
106 }
107 }
108
109 public void includeArtifact( Artifact artifact )
110 {
111 if ( wagonProvider != null )
112 {
113 bannedArtifacts.put( artifact, null );
114 }
115 }
116
117 private boolean isWagonProvider( Artifact artifact )
118 {
119 if ( "org.apache.maven.wagon".equals( artifact.getGroupId() ) )
120 {
121 return artifact.getArtifactId().startsWith( "wagon-" );
122 }
123 return false;
124 }
125
126 public void manageArtifact( Artifact artifact, Artifact replacement )
127 {
128 }
129
130 public void omitForCycle( Artifact artifact )
131 {
132 }
133
134 public void omitForNearer( Artifact omitted, Artifact kept )
135 {
136 }
137
138 public void restrictRange( Artifact artifact, Artifact replacement, VersionRange newRange )
139 {
140 }
141
142 public void selectVersionFromRange( Artifact artifact )
143 {
144 }
145
146 public void testArtifact( Artifact node )
147 {
148 }
149
150 public void updateScope( Artifact artifact, String scope )
151 {
152 }
153
154 public void updateScopeCurrentPom( Artifact artifact, String ignoredScope )
155 {
156 }
157
158 }