16
16
17
17
package de .thetaphi .forbiddenapis .maven ;
18
18
19
- import static de .thetaphi .forbiddenapis .Checker .Option .*;
20
-
21
- import org .apache .maven .artifact .Artifact ;
22
- import org .apache .maven .artifact .factory .ArtifactFactory ;
23
- import org .apache .maven .artifact .repository .ArtifactRepository ;
24
- import org .apache .maven .artifact .resolver .ArtifactNotFoundException ;
25
- import org .apache .maven .artifact .resolver .ArtifactResolutionException ;
26
- import org .apache .maven .artifact .resolver .ArtifactResolver ;
27
- import org .apache .maven .plugin .AbstractMojo ;
28
- import org .apache .maven .plugin .MojoExecutionException ;
29
- import org .apache .maven .plugins .annotations .Component ;
30
- import org .apache .maven .plugins .annotations .Parameter ;
31
- import org .codehaus .plexus .util .DirectoryScanner ;
32
-
33
- import de .thetaphi .forbiddenapis .Checker ;
34
- import de .thetaphi .forbiddenapis .Constants ;
35
- import de .thetaphi .forbiddenapis .ForbiddenApiException ;
36
- import de .thetaphi .forbiddenapis .Logger ;
37
- import de .thetaphi .forbiddenapis .ParseException ;
19
+ import static de .thetaphi .forbiddenapis .Checker .Option .DISABLE_CLASSLOADING_CACHE ;
20
+ import static de .thetaphi .forbiddenapis .Checker .Option .FAIL_ON_MISSING_CLASSES ;
21
+ import static de .thetaphi .forbiddenapis .Checker .Option .FAIL_ON_UNRESOLVABLE_SIGNATURES ;
22
+ import static de .thetaphi .forbiddenapis .Checker .Option .FAIL_ON_VIOLATION ;
23
+ import static de .thetaphi .forbiddenapis .Checker .Option .IGNORE_SIGNATURES_OF_MISSING_CLASSES ;
38
24
39
25
import java .io .File ;
40
26
import java .io .IOException ;
41
27
import java .lang .annotation .RetentionPolicy ;
28
+ import java .net .MalformedURLException ;
42
29
import java .net .URI ;
43
30
import java .net .URISyntaxException ;
44
- import java .net .URLClassLoader ;
45
- import java .net .MalformedURLException ;
46
31
import java .net .URL ;
32
+ import java .net .URLClassLoader ;
47
33
import java .util .Arrays ;
48
34
import java .util .EnumSet ;
49
35
import java .util .LinkedHashSet ;
50
36
import java .util .List ;
51
37
import java .util .Locale ;
52
38
import java .util .Set ;
53
39
40
+ import org .apache .maven .plugin .AbstractMojo ;
41
+ import org .apache .maven .plugin .MojoExecutionException ;
42
+ import org .apache .maven .plugins .annotations .Component ;
43
+ import org .apache .maven .plugins .annotations .Parameter ;
44
+ import org .codehaus .plexus .util .DirectoryScanner ;
45
+ import org .eclipse .aether .RepositorySystem ;
46
+ import org .eclipse .aether .RepositorySystemSession ;
47
+ import org .eclipse .aether .artifact .Artifact ;
48
+ import org .eclipse .aether .repository .RemoteRepository ;
49
+ import org .eclipse .aether .resolution .ArtifactRequest ;
50
+ import org .eclipse .aether .resolution .ArtifactResolutionException ;
51
+ import org .eclipse .aether .resolution .ArtifactResult ;
52
+
53
+ import de .thetaphi .forbiddenapis .Checker ;
54
+ import de .thetaphi .forbiddenapis .Constants ;
55
+ import de .thetaphi .forbiddenapis .ForbiddenApiException ;
56
+ import de .thetaphi .forbiddenapis .Logger ;
57
+ import de .thetaphi .forbiddenapis .ParseException ;
58
+
54
59
/**
55
60
* Base class for forbiddenapis Mojos.
56
61
* @since 1.0
@@ -242,18 +247,15 @@ public abstract class AbstractCheckMojo extends AbstractMojo implements Constant
242
247
/** The project packaging (pom, jar, etc.). */
243
248
@ Parameter (defaultValue = "${project.packaging}" , readonly = true , required = true )
244
249
private String packaging ;
245
-
246
- @ Component
247
- private ArtifactFactory artifactFactory ;
248
250
249
251
@ Component
250
- private ArtifactResolver artifactResolver ;
251
-
252
- @ Parameter (defaultValue = "${project.remoteArtifactRepositories}" , readonly = true , required = true )
253
- private List <ArtifactRepository > remoteRepositories ;
252
+ private RepositorySystem repoSystem ;
254
253
255
- @ Parameter (defaultValue = "${localRepository}" , readonly = true , required = true )
256
- private ArtifactRepository localRepository ;
254
+ @ Parameter (defaultValue = "${repositorySystemSession}" , readonly = true , required = true )
255
+ private RepositorySystemSession repoSession ;
256
+
257
+ @ Parameter (defaultValue = "${project.remoteProjectRepositories}" , readonly = true , required = true )
258
+ private List <RemoteRepository > projectRepos ;
257
259
258
260
/** provided by the concrete Mojos for compile and test classes processing */
259
261
protected abstract List <String > getClassPathElements ();
@@ -266,15 +268,11 @@ protected String getTargetVersion() {
266
268
return (releaseVersion != null ) ? releaseVersion : targetVersion ;
267
269
}
268
270
269
- private File resolveSignaturesArtifact (SignaturesArtifact signaturesArtifact ) throws ArtifactResolutionException , ArtifactNotFoundException {
270
- final Artifact artifact = signaturesArtifact .createArtifact (artifactFactory );
271
- artifactResolver .resolve (artifact , this .remoteRepositories , this .localRepository );
272
- final File f = artifact .getFile ();
273
- // Can this ever be false? Be sure. Found the null check also in other Maven code, so be safe!
274
- if (f == null ) {
275
- throw new ArtifactNotFoundException ("Artifact does not resolve to a file." , artifact );
276
- }
277
- return f ;
271
+ private File resolveSignaturesArtifact (SignaturesArtifact signaturesArtifact ) throws ArtifactResolutionException {
272
+ final Artifact artifact = signaturesArtifact .createArtifact ();
273
+ ArtifactRequest req = new ArtifactRequest (artifact , projectRepos , null );
274
+ ArtifactResult resolutionResult = repoSystem .resolveArtifact (repoSession , req );
275
+ return resolutionResult .getArtifact ().getFile ();
278
276
}
279
277
280
278
private String encodeUrlPath (String path ) {
@@ -459,8 +457,6 @@ public void debug(String msg) {
459
457
throw new MojoExecutionException ("Parsing signatures failed: " + pe .getMessage (), pe );
460
458
} catch (ArtifactResolutionException e ) {
461
459
throw new MojoExecutionException ("Problem while resolving Maven artifact." , e );
462
- } catch (ArtifactNotFoundException e ) {
463
- throw new MojoExecutionException ("Maven artifact does not exist." , e );
464
460
}
465
461
466
462
if (checker .hasNoSignatures ()) {
0 commit comments