|
19 | 19 | * under the License.
|
20 | 20 | */
|
21 | 21 |
|
22 |
| -import java.util.ArrayList; |
23 |
| -import java.util.Collections; |
24 |
| -import java.util.List; |
25 |
| -import java.util.Map; |
26 | 22 | import org.apache.maven.artifact.Artifact;
|
27 | 23 | import org.apache.maven.artifact.factory.ArtifactFactory;
|
28 | 24 | import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
|
37 | 33 | import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
|
38 | 34 | import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
|
39 | 35 | import org.apache.maven.artifact.versioning.VersionRange;
|
40 |
| -import org.apache.maven.surefire.booter.Classpath; |
41 | 36 | import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
|
42 | 37 |
|
43 | 38 | import javax.annotation.Nonnull;
|
44 | 39 | import javax.annotation.Nullable;
|
| 40 | +import java.util.Collections; |
| 41 | +import java.util.LinkedHashSet; |
| 42 | +import java.util.List; |
| 43 | +import java.util.Map; |
| 44 | +import java.util.Set; |
| 45 | + |
| 46 | +import static java.util.Collections.singleton; |
| 47 | +import static org.apache.maven.artifact.Artifact.SCOPE_TEST; |
| 48 | +import static org.apache.maven.artifact.versioning.VersionRange.createFromVersion; |
45 | 49 |
|
46 | 50 | /**
|
47 | 51 | * Does dependency resolution and artifact handling for the surefire plugin.
|
@@ -123,65 +127,55 @@ private ArtifactResolutionResult resolveArtifact( Artifact filteredArtifact, Art
|
123 | 127 |
|
124 | 128 | Artifact originatingArtifact = artifactFactory.createBuildArtifact( "dummy", "dummy", "1.0", "jar" );
|
125 | 129 |
|
126 |
| - return artifactResolver.resolveTransitively( Collections.singleton( providerArtifact ), originatingArtifact, |
| 130 | + return artifactResolver.resolveTransitively( singleton( providerArtifact ), originatingArtifact, |
127 | 131 | localRepository, remoteRepositories, artifactMetadataSource,
|
128 | 132 | filter );
|
129 | 133 | }
|
130 | 134 |
|
131 | 135 | @Nonnull
|
132 |
| - public Classpath getProviderClasspath( String provider, String version, Artifact filteredArtifact ) |
| 136 | + @SuppressWarnings( "unchecked" ) |
| 137 | + public Set<Artifact> getProviderClasspath( String provider, String version, Artifact filteredArtifact ) |
133 | 138 | throws ArtifactNotFoundException, ArtifactResolutionException
|
134 | 139 | {
|
135 |
| - Classpath classPath = ClasspathCache.getCachedClassPath( provider ); |
136 |
| - if ( classPath == null ) |
137 |
| - { |
138 |
| - Artifact providerArtifact = artifactFactory.createDependencyArtifact( "org.apache.maven.surefire", provider, |
139 |
| - VersionRange.createFromVersion( |
140 |
| - version ), "jar", null, |
141 |
| - Artifact.SCOPE_TEST ); |
142 |
| - ArtifactResolutionResult result = resolveArtifact( filteredArtifact, providerArtifact ); |
143 |
| - List<String> files = new ArrayList<String>(); |
| 140 | + Artifact providerArtifact = artifactFactory.createDependencyArtifact( "org.apache.maven.surefire", |
| 141 | + provider, createFromVersion( version ), "jar", null, SCOPE_TEST ); |
| 142 | + |
| 143 | + ArtifactResolutionResult result = resolveArtifact( filteredArtifact, providerArtifact ); |
144 | 144 |
|
| 145 | + if ( log.isDebugEnabled() ) |
| 146 | + { |
145 | 147 | for ( Object o : result.getArtifacts() )
|
146 | 148 | {
|
147 | 149 | Artifact artifact = (Artifact) o;
|
148 |
| - |
149 |
| - log.debug( |
150 |
| - "Adding to " + pluginName + " test classpath: " + artifact.getFile().getAbsolutePath() + " Scope: " |
151 |
| - + artifact.getScope() ); |
152 |
| - |
153 |
| - files.add( artifact.getFile().getAbsolutePath() ); |
| 150 | + String artifactPath = artifact.getFile().getAbsolutePath(); |
| 151 | + String scope = artifact.getScope(); |
| 152 | + log.debug( "Adding to " + pluginName + " test classpath: " + artifactPath + " Scope: " + scope ); |
154 | 153 | }
|
155 |
| - classPath = new Classpath( files ); |
156 |
| - ClasspathCache.setCachedClasspath( provider, classPath ); |
157 | 154 | }
|
158 |
| - return classPath; |
| 155 | + |
| 156 | + return result.getArtifacts(); |
159 | 157 | }
|
160 | 158 |
|
161 |
| - public Classpath addProviderToClasspath( Map<String, Artifact> pluginArtifactMap, Artifact surefireArtifact ) |
| 159 | + public Set<Artifact> addProviderToClasspath( Map<String, Artifact> pluginArtifactMap, Artifact surefireArtifact ) |
162 | 160 | throws ArtifactResolutionException, ArtifactNotFoundException
|
163 | 161 | {
|
164 |
| - List<String> files = new ArrayList<String>(); |
| 162 | + Set<Artifact> providerArtifacts = new LinkedHashSet<Artifact>(); |
165 | 163 | if ( surefireArtifact != null )
|
166 | 164 | {
|
167 |
| - final ArtifactResolutionResult artifactResolutionResult = resolveArtifact( null, surefireArtifact ); |
| 165 | + ArtifactResolutionResult artifactResolutionResult = resolveArtifact( null, surefireArtifact ); |
168 | 166 | for ( Artifact artifact : pluginArtifactMap.values() )
|
169 | 167 | {
|
170 | 168 | if ( !artifactResolutionResult.getArtifacts().contains( artifact ) )
|
171 | 169 | {
|
172 |
| - files.add( artifact.getFile().getAbsolutePath() ); |
| 170 | + providerArtifacts.add( artifact ); |
173 | 171 | }
|
174 | 172 | }
|
175 | 173 | }
|
176 | 174 | else
|
177 | 175 | {
|
178 | 176 | // Bit of a brute force strategy if not found. Should probably be improved
|
179 |
| - for ( Artifact artifact : pluginArtifactMap.values() ) |
180 |
| - { |
181 |
| - files.add( artifact.getFile().getPath() ); |
182 |
| - } |
| 177 | + providerArtifacts.addAll( pluginArtifactMap.values() ); |
183 | 178 | }
|
184 |
| - return new Classpath( files ); |
| 179 | + return providerArtifacts; |
185 | 180 | }
|
186 |
| - |
187 | 181 | }
|
0 commit comments