26
26
*/
27
27
28
28
import org .apache .maven .artifact .Artifact ;
29
- import org .apache .maven .artifact .factory .ArtifactFactory ;
30
- import org .apache .maven .artifact .repository .ArtifactRepository ;
31
- import org .apache .maven .artifact .resolver .AbstractArtifactResolutionException ;
32
- import org .apache .maven .artifact .resolver .ArtifactResolver ;
33
29
import org .apache .maven .model .Dependency ;
34
30
import org .apache .maven .plugin .AbstractMojo ;
35
31
import org .apache .maven .plugin .MojoExecutionException ;
47
43
import org .codehaus .mojo .animal_sniffer .Clazz ;
48
44
import org .codehaus .mojo .animal_sniffer .SignatureChecker ;
49
45
import org .codehaus .plexus .util .StringUtils ;
46
+ import org .eclipse .aether .RepositorySystem ;
47
+ import org .eclipse .aether .RepositorySystemSession ;
48
+ import org .eclipse .aether .resolution .ArtifactRequest ;
49
+ import org .eclipse .aether .resolution .ArtifactResolutionException ;
50
+ import org .eclipse .aether .resolution .ArtifactResult ;
50
51
51
52
import java .io .File ;
52
53
import java .io .FileInputStream ;
53
54
import java .io .IOException ;
54
- import java .io .InputStream ;
55
55
import java .util .ArrayList ;
56
56
import java .util .Arrays ;
57
57
import java .util .HashSet ;
@@ -187,25 +187,16 @@ public void setSignature( String signatureId ) {
187
187
@ Parameter ( defaultValue = "true" , property = "animal.sniffer.failOnError" )
188
188
protected boolean failOnError ;
189
189
190
- /**
191
- */
192
- @ Component
193
- protected ArtifactResolver resolver ;
194
-
195
190
/**
196
191
*/
197
192
@ Parameter ( defaultValue = "${project}" , readonly = true )
198
193
protected MavenProject project ;
199
194
200
- /**
201
- */
202
- @ Parameter ( defaultValue = "${localRepository}" , readonly =true )
203
- protected ArtifactRepository localRepository ;
195
+ @ Parameter ( defaultValue = "${repositorySystemSession}" , readonly = true )
196
+ private RepositorySystemSession repositorySystemSession ;
204
197
205
- /**
206
- */
207
198
@ Component
208
- protected ArtifactFactory artifactFactory ;
199
+ private RepositorySystem repositorySystem ;
209
200
210
201
static Map <File , Map <String , Clazz >> classes = new ConcurrentHashMap <>();
211
202
@@ -249,9 +240,8 @@ public void execute()
249
240
250
241
getLog ().info ( "Checking unresolved references to " + signature );
251
242
252
- Artifact a = signature .createArtifact ( artifactFactory );
243
+ File signatureFile = resolveFileForArtifact ( signature .createArtifact () );
253
244
254
- resolver .resolve ( a , project .getRemoteArtifactRepositories (), localRepository );
255
245
// just check code from this module
256
246
final Set <String > ignoredPackages = buildPackageList ();
257
247
@@ -268,7 +258,7 @@ public void execute()
268
258
}
269
259
270
260
final SignatureChecker signatureChecker =
271
- new SignatureChecker ( loadClasses ( a . getFile () ), ignoredPackages ,
261
+ new SignatureChecker ( loadClasses ( signatureFile ), ignoredPackages ,
272
262
new MavenLogger ( getLog () ) );
273
263
signatureChecker .setCheckJars ( false ); // don't want to decend into jar files that have been copied to
274
264
// the output directory as resources.
@@ -309,12 +299,24 @@ public void execute()
309
299
{
310
300
throw new MojoExecutionException ( "Failed to check signatures" , e );
311
301
}
312
- catch ( AbstractArtifactResolutionException e )
302
+ catch ( ArtifactResolutionException e )
313
303
{
314
304
throw new MojoExecutionException ( "Failed to obtain signature: " + signature , e );
315
305
}
316
306
}
317
307
308
+ private File resolveFileForArtifact (org .eclipse .aether .artifact .Artifact artifact )
309
+ throws ArtifactResolutionException , MojoExecutionException {
310
+
311
+ if ( StringUtils .isBlank ( artifact .getVersion () ) ) {
312
+ throw new MojoExecutionException ( "For artifact {" + artifact + "}: The version cannot be empty." );
313
+ }
314
+
315
+ ArtifactRequest request = new ArtifactRequest ( artifact , project .getRemotePluginRepositories (), null );
316
+ ArtifactResult result = repositorySystem .resolveArtifact ( repositorySystemSession , request );
317
+ return result .getArtifact ().getFile ();
318
+ }
319
+
318
320
private static Map <String , Clazz > loadClasses ( File f ) throws IOException
319
321
{
320
322
Map <String , Clazz > classes = CheckSignatureMojo .classes .get ( f );
0 commit comments