24
24
import java .util .LinkedHashSet ;
25
25
import java .util .Set ;
26
26
27
+ import org .apache .maven .RepositoryUtils ;
27
28
import org .apache .maven .artifact .Artifact ;
28
29
import org .apache .maven .artifact .handler .manager .ArtifactHandlerManager ;
29
30
import org .apache .maven .plugin .MojoExecutionException ;
32
33
import org .apache .maven .plugins .dependency .AbstractDependencyMojo ;
33
34
import org .apache .maven .plugins .dependency .utils .DependencyStatusSets ;
34
35
import org .apache .maven .plugins .dependency .utils .DependencyUtil ;
36
+ import org .apache .maven .plugins .dependency .utils .ResolverUtil ;
35
37
import org .apache .maven .plugins .dependency .utils .translators .ArtifactTranslator ;
36
38
import org .apache .maven .plugins .dependency .utils .translators .ClassifierTypeTranslator ;
37
39
import org .apache .maven .project .MavenProject ;
38
40
import org .apache .maven .project .ProjectBuilder ;
39
41
import org .apache .maven .project .ProjectBuildingException ;
40
- import org .apache .maven .project .ProjectBuildingRequest ;
41
42
import org .apache .maven .shared .artifact .filter .collection .ArtifactFilterException ;
42
43
import org .apache .maven .shared .artifact .filter .collection .ArtifactIdFilter ;
43
44
import org .apache .maven .shared .artifact .filter .collection .ArtifactsFilter ;
47
48
import org .apache .maven .shared .artifact .filter .collection .ProjectTransitivityFilter ;
48
49
import org .apache .maven .shared .artifact .filter .collection .ScopeFilter ;
49
50
import org .apache .maven .shared .artifact .filter .collection .TypeFilter ;
50
- import org .apache .maven .shared .transfer .artifact .ArtifactCoordinate ;
51
- import org .apache .maven .shared .transfer .artifact .resolve .ArtifactResolver ;
52
- import org .apache .maven .shared .transfer .artifact .resolve .ArtifactResolverException ;
53
51
import org .apache .maven .shared .transfer .dependencies .resolve .DependencyResolver ;
54
52
import org .apache .maven .shared .transfer .repository .RepositoryManager ;
53
+ import org .eclipse .aether .resolution .ArtifactResolutionException ;
55
54
56
55
/**
57
56
* Class that encapsulates the plugin parameters, and contains methods that handle dependency filtering
60
59
* @see org.apache.maven.plugins.dependency.AbstractDependencyMojo
61
60
*/
62
61
public abstract class AbstractDependencyFilterMojo extends AbstractDependencyMojo {
62
+
63
63
@ Component
64
- private ArtifactResolver artifactResolver ;
64
+ private ResolverUtil resolverUtil ;
65
65
66
66
@ Component
67
67
private DependencyResolver dependencyResolver ;
@@ -364,14 +364,11 @@ private void addParentArtifacts(MavenProject project, Set<Artifact> artifacts) t
364
364
break ;
365
365
}
366
366
try {
367
- ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest ();
368
-
369
- Artifact resolvedArtifact = artifactResolver
370
- .resolveArtifact (buildingRequest , project .getArtifact ())
371
- .getArtifact ();
367
+ org .eclipse .aether .artifact .Artifact resolvedArtifact = resolverUtil .resolveArtifact (
368
+ RepositoryUtils .toArtifact (project .getArtifact ()), project .getRemoteProjectRepositories ());
372
369
373
- artifacts .add (resolvedArtifact );
374
- } catch (ArtifactResolverException e ) {
370
+ artifacts .add (RepositoryUtils . toArtifact ( resolvedArtifact ) );
371
+ } catch (ArtifactResolutionException e ) {
375
372
throw new MojoExecutionException (e .getMessage (), e );
376
373
}
377
374
}
@@ -385,7 +382,7 @@ private void addParentArtifacts(MavenProject project, Set<Artifact> artifacts) t
385
382
* @return DependencyStatusSets - Bean of TreeSets that contains information on the projects dependencies
386
383
* @throws MojoExecutionException in case of an error.
387
384
*/
388
- protected DependencyStatusSets getClassifierTranslatedDependencies (Set <Artifact > artifacts , boolean stopOnFailure )
385
+ private DependencyStatusSets getClassifierTranslatedDependencies (Set <Artifact > artifacts , boolean stopOnFailure )
389
386
throws MojoExecutionException {
390
387
Set <Artifact > unResolvedArtifacts = new LinkedHashSet <>();
391
388
Set <Artifact > resolvedArtifacts = artifacts ;
@@ -397,7 +394,7 @@ protected DependencyStatusSets getClassifierTranslatedDependencies(Set<Artifact>
397
394
if (classifier != null && !classifier .isEmpty ()) {
398
395
ArtifactTranslator translator =
399
396
new ClassifierTypeTranslator (artifactHandlerManager , this .classifier , this .type );
400
- Collection <ArtifactCoordinate > coordinates = translator .translate (artifacts , getLog ());
397
+ Collection <org . eclipse . aether . artifact . Artifact > coordinates = translator .translate (artifacts , getLog ());
401
398
402
399
status = filterMarkedDependencies (artifacts );
403
400
@@ -447,29 +444,26 @@ protected DependencyStatusSets filterMarkedDependencies(Set<Artifact> artifacts)
447
444
}
448
445
449
446
/**
450
- * @param coordinates The set of artifact coordinates{@link ArtifactCoordinate}.
447
+ * @param artifacts The set of artifacts
451
448
* @param stopOnFailure <code>true</code> if we should fail with exception if an artifact couldn't be resolved
452
449
* <code>false</code> otherwise.
453
450
* @return the resolved artifacts. {@link Artifact}.
454
451
* @throws MojoExecutionException in case of error.
455
452
*/
456
- protected Set <Artifact > resolve (Set <ArtifactCoordinate > coordinates , boolean stopOnFailure )
453
+ private Set <Artifact > resolve (Set <org . eclipse . aether . artifact . Artifact > artifacts , boolean stopOnFailure )
457
454
throws MojoExecutionException {
458
- ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest ();
459
455
460
456
Set <Artifact > resolvedArtifacts = new LinkedHashSet <>();
461
- for (ArtifactCoordinate coordinate : coordinates ) {
457
+ for (org . eclipse . aether . artifact . Artifact artifact : artifacts ) {
462
458
try {
463
- Artifact artifact = artifactResolver
464
- .resolveArtifact (buildingRequest , coordinate )
465
- .getArtifact ();
466
- resolvedArtifacts .add (artifact );
467
- } catch (ArtifactResolverException ex ) {
459
+ org .eclipse .aether .artifact .Artifact resolveArtifact =
460
+ resolverUtil .resolveArtifact (artifact , getProject ().getRemoteProjectRepositories ());
461
+ resolvedArtifacts .add (RepositoryUtils .toArtifact (resolveArtifact ));
462
+ } catch (ArtifactResolutionException ex ) {
468
463
// an error occurred during resolution, log it an continue
469
- getLog ().debug ("error resolving: " + coordinate );
470
- getLog ().debug (ex );
464
+ getLog ().debug ("error resolving: " + artifact , ex );
471
465
if (stopOnFailure ) {
472
- throw new MojoExecutionException ("error resolving: " + coordinate , ex );
466
+ throw new MojoExecutionException ("error resolving: " + artifact , ex );
473
467
}
474
468
}
475
469
}
@@ -507,10 +501,10 @@ public void setPrependGroupId(boolean prependGroupId) {
507
501
}
508
502
509
503
/**
510
- * @return {@link #artifactResolver }
504
+ * @return {@link #resolverUtil }
511
505
*/
512
- protected final ArtifactResolver getArtifactResolver () {
513
- return artifactResolver ;
506
+ protected final ResolverUtil getResolverUtil () {
507
+ return resolverUtil ;
514
508
}
515
509
516
510
/**
0 commit comments