This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 4378b37  SLING-11948 Remove legacy maven-compat dependency (#76)
4378b37 is described below

commit 4378b37a7a2b16fc161cdd4c6ee93e12f8431452
Author: Konrad Windszus <[email protected]>
AuthorDate: Fri Jul 28 16:52:48 2023 +0200

    SLING-11948 Remove legacy maven-compat dependency (#76)
---
 pom.xml                                            |  6 --
 .../apache/sling/feature/maven/Environment.java    |  4 +-
 .../apache/sling/feature/maven/Preprocessor.java   |  4 +-
 .../apache/sling/feature/maven/ProjectHelper.java  | 37 ++++-----
 .../extensions/DependencyLifecycleParticipant.java | 10 +--
 .../FeatureLifecycleMappingProvider.java           |  1 +
 .../feature/maven/mojos/AbstractFeatureMojo.java   |  8 +-
 .../maven/mojos/AbstractIncludingFeatureMojo.java  |  4 +-
 .../maven/mojos/AbstractRepositoryMojo.java        |  4 +-
 .../feature/maven/mojos/AnalyseFeaturesMojo.java   |  2 +-
 .../maven/mojos/ApplyDefaultConfigMojo.java        |  2 +-
 .../maven/mojos/AttachFeatureArchivesMojo.java     |  2 +-
 .../feature/maven/mojos/AttachFeaturesMojo.java    |  2 +-
 .../feature/maven/mojos/FeaturesDiffMojo.java      | 88 ++++++++--------------
 .../apache/sling/feature/maven/mojos/InfoMojo.java |  2 +-
 .../maven/mojos/AbstractRepositoryMojoTest.java    | 67 +++++++---------
 .../maven/mojos/AggregateFeaturesMojoTest.java     |  4 +-
 17 files changed, 106 insertions(+), 141 deletions(-)

diff --git a/pom.xml b/pom.xml
index a5d7f14..ac3147c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -301,12 +301,6 @@
             <version>${maven.version}</version>
             <scope>provided</scope>
         </dependency>
-        <dependency>
-            <groupId>org.apache.maven</groupId>
-            <artifactId>maven-compat</artifactId>
-            <version>${maven.version}</version>
-            <scope>provided</scope>
-        </dependency>
         <dependency>
             <groupId>org.apache.maven</groupId>
             <artifactId>maven-archiver</artifactId>
diff --git a/src/main/java/org/apache/sling/feature/maven/Environment.java 
b/src/main/java/org/apache/sling/feature/maven/Environment.java
index 84957b3..d739c8e 100644
--- a/src/main/java/org/apache/sling/feature/maven/Environment.java
+++ b/src/main/java/org/apache/sling/feature/maven/Environment.java
@@ -20,9 +20,9 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.execution.MavenSession;
 import org.codehaus.plexus.logging.Logger;
+import org.eclipse.aether.RepositorySystem;
 
 /**
  * The environment provides required services to the {@link Preprocessor} as 
well
@@ -31,7 +31,7 @@ import org.codehaus.plexus.logging.Logger;
 public class Environment {
 
     public ArtifactHandlerManager artifactHandlerManager;
-    public ArtifactResolver resolver;
+    public RepositorySystem repoSystem;
     public MavenSession session;
     public Logger logger;
 
diff --git a/src/main/java/org/apache/sling/feature/maven/Preprocessor.java 
b/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
index a1dda28..5022343 100644
--- a/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
+++ b/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
@@ -214,7 +214,7 @@ public class Preprocessor {
                                                         {
                                                             return 
ProjectHelper
                                                                     
.getOrResolveArtifact(info.project, env.session,
-                                                                            
env.artifactHandlerManager, env.resolver, aid)
+                                                                            
env.artifactHandlerManager, env.repoSystem, aid)
                                                                     
.getFile().toURI().toURL();
                                                         }
                                                         catch (Exception e)
@@ -411,7 +411,7 @@ public class Preprocessor {
                            env.logger.debug("Found external " + id.getType() + 
" dependency: " + id);
 
                            // "external" dependency, we can already resolve it
-                           final File featureFile = 
ProjectHelper.getOrResolveArtifact(info.project, env.session, 
env.artifactHandlerManager, env.resolver, id).getFile();
+                           final File featureFile = 
ProjectHelper.getOrResolveArtifact(info.project, env.session, 
env.artifactHandlerManager, env.repoSystem, id).getFile();
                            try (final FileReader r = new 
FileReader(featureFile)) {
                                return FeatureJSONReader.read(r, 
featureFile.getAbsolutePath());
                            } catch ( final IOException ioe) {
diff --git a/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java 
b/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java
index 6405dbf..85031ff 100644
--- a/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java
+++ b/src/main/java/org/apache/sling/feature/maven/ProjectHelper.java
@@ -37,13 +37,10 @@ import java.util.TreeMap;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 
+import org.apache.maven.RepositoryUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.DefaultArtifact;
 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
-import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.Plugin;
@@ -55,6 +52,9 @@ import org.apache.sling.feature.Feature;
 import org.apache.sling.feature.io.json.FeatureJSONReader;
 import org.apache.sling.feature.io.json.FeatureJSONWriter;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.resolution.ArtifactRequest;
+import org.eclipse.aether.resolution.ArtifactResult;
 
 /**
  * The project helper contains utility functions and provides access
@@ -336,7 +336,7 @@ public abstract class ProjectHelper {
     public static Artifact getOrResolveArtifact(final MavenProject project,
             final MavenSession session,
             final ArtifactHandlerManager artifactHandlerManager,
-            final ArtifactResolver resolver,
+            final RepositorySystem repoSystem,
             final ArtifactId id) {
         @SuppressWarnings("unchecked")
         Map<String, Artifact> cache = (Map<String, Artifact>) 
project.getContextValue(ARTIFACT_CACHE);
@@ -362,19 +362,22 @@ public abstract class ProjectHelper {
                         }
                     }
                     if ( result == null ) {
-                        final Artifact prjArtifact = new 
DefaultArtifact(id.getGroupId(),
-                                id.getArtifactId(),
-                                
VersionRange.createFromVersion(id.getVersion()),
-                                Artifact.SCOPE_PROVIDED,
-                                id.getType(),
-                                id.getClassifier(),
-                                
artifactHandlerManager.getArtifactHandler(id.getType()));
                         try {
-                            resolver.resolve(prjArtifact, 
project.getRemoteArtifactRepositories(), session.getLocalRepository());
-                        } catch (final ArtifactResolutionException | 
ArtifactNotFoundException e) {
+                            
+                            org.eclipse.aether.artifact.Artifact prjArtifact = 
new org.eclipse.aether.artifact.DefaultArtifact(
+                                            id.getGroupId(),
+                                            id.getArtifactId(),
+                                            id.getClassifier(),
+                                            null, // extension retrieved via 
artifactTye
+                                            id.getVersion(),
+                                            
RepositoryUtils.newArtifactType(id.getType(), 
artifactHandlerManager.getArtifactHandler(id.getType()))
+                                    );
+                            ArtifactRequest artifactRequest = new 
ArtifactRequest(prjArtifact, project.getRemoteProjectRepositories(), null);
+                            ArtifactResult artifactResult = 
repoSystem.resolveArtifact(session.getRepositorySession(), artifactRequest);
+                            result = 
RepositoryUtils.toArtifact(artifactResult.getArtifact());
+                        } catch (final 
org.eclipse.aether.resolution.ArtifactResolutionException e) {
                             throw new RuntimeException("Unable to get artifact 
for " + id.toMvnId(), e);
                         }
-                        result = prjArtifact;
                     }
                 }
             }
@@ -385,8 +388,8 @@ public abstract class ProjectHelper {
     }
 
     public static Feature getOrResolveFeature(final MavenProject project, 
final MavenSession session,
-            final ArtifactHandlerManager artifactHandlerManager, final 
ArtifactResolver resolver, final ArtifactId id) {
-        final File artFile = getOrResolveArtifact(project, session, 
artifactHandlerManager, resolver, id).getFile();
+            final ArtifactHandlerManager artifactHandlerManager, final 
RepositorySystem repoSystem, final ArtifactId id) {
+        final File artFile = getOrResolveArtifact(project, session, 
artifactHandlerManager, repoSystem, id).getFile();
         try (final Reader reader = new FileReader(artFile)) {
             return FeatureJSONReader.read(reader, artFile.getAbsolutePath());
         } catch (final IOException ioe) {
diff --git 
a/src/main/java/org/apache/sling/feature/maven/extensions/DependencyLifecycleParticipant.java
 
b/src/main/java/org/apache/sling/feature/maven/extensions/DependencyLifecycleParticipant.java
index 41dea45..a185068 100644
--- 
a/src/main/java/org/apache/sling/feature/maven/extensions/DependencyLifecycleParticipant.java
+++ 
b/src/main/java/org/apache/sling/feature/maven/extensions/DependencyLifecycleParticipant.java
@@ -23,7 +23,6 @@ import javax.inject.Singleton;
 import org.apache.maven.AbstractMavenLifecycleParticipant;
 import org.apache.maven.MavenExecutionException;
 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.project.MavenProject;
@@ -31,6 +30,7 @@ import org.apache.sling.feature.maven.Environment;
 import org.apache.sling.feature.maven.FeatureProjectInfo;
 import org.apache.sling.feature.maven.Preprocessor;
 import org.codehaus.plexus.logging.Logger;
+import org.eclipse.aether.RepositorySystem;
 
 /**
  * Maven lifecycle participant which adds the artifacts of the model to the 
dependencies.
@@ -52,21 +52,21 @@ public class DependencyLifecycleParticipant extends 
AbstractMavenLifecyclePartic
      * Used to look up Artifacts in the remote repository.
      *
      */
-    private final ArtifactResolver resolver;
+    private final RepositorySystem repoSystem;
 
     @Inject
-    public DependencyLifecycleParticipant(Logger logger, 
ArtifactHandlerManager artifactHandlerManager, ArtifactResolver resolver) {
+    public DependencyLifecycleParticipant(Logger logger, 
ArtifactHandlerManager artifactHandlerManager, RepositorySystem repoSystem) {
         super();
         this.logger = logger;
         this.artifactHandlerManager = artifactHandlerManager;
-        this.resolver = resolver;
+        this.repoSystem = repoSystem;
     }
 
     @Override
     public void afterProjectsRead(final MavenSession session) throws 
MavenExecutionException {
         final Environment env = new Environment();
         env.artifactHandlerManager = artifactHandlerManager;
-        env.resolver = resolver;
+        env.repoSystem = repoSystem;
         env.logger = logger;
         env.session = session;
 
diff --git 
a/src/main/java/org/apache/sling/feature/maven/extensions/FeatureLifecycleMappingProvider.java
 
b/src/main/java/org/apache/sling/feature/maven/extensions/FeatureLifecycleMappingProvider.java
index 303f0d6..5237e2c 100644
--- 
a/src/main/java/org/apache/sling/feature/maven/extensions/FeatureLifecycleMappingProvider.java
+++ 
b/src/main/java/org/apache/sling/feature/maven/extensions/FeatureLifecycleMappingProvider.java
@@ -61,6 +61,7 @@ public class FeatureLifecycleMappingProvider implements 
Provider<LifecycleMappin
                 return null;
             }
 
+            @SuppressWarnings("deprecation")
             @Override
             public Map<String, String> getPhases(String lifecycle) {
                 if (DEFAULT_LIFECYCLE_KEY.equals(lifecycle)) {
diff --git 
a/src/main/java/org/apache/sling/feature/maven/mojos/AbstractFeatureMojo.java 
b/src/main/java/org/apache/sling/feature/maven/mojos/AbstractFeatureMojo.java
index f7c786c..b26c90f 100644
--- 
a/src/main/java/org/apache/sling/feature/maven/mojos/AbstractFeatureMojo.java
+++ 
b/src/main/java/org/apache/sling/feature/maven/mojos/AbstractFeatureMojo.java
@@ -27,7 +27,6 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -46,6 +45,7 @@ import org.apache.sling.feature.maven.FeatureConstants;
 import org.apache.sling.feature.maven.FeatureProjectConfig;
 import org.apache.sling.feature.maven.JSONFeatures;
 import org.apache.sling.feature.maven.ProjectHelper;
+import org.eclipse.aether.RepositorySystem;
 
 /**
  * Base class for all mojos.
@@ -209,7 +209,7 @@ public abstract class AbstractFeatureMojo extends 
AbstractMojo {
     ArtifactHandlerManager artifactHandlerManager;
 
     @Component
-    ArtifactResolver artifactResolver;
+    RepositorySystem repoSystem;
 
     protected File getTmpDir() {
         final File dir = new File(this.project.getBuild().getDirectory(), 
"slingfeature-tmp");
@@ -354,7 +354,7 @@ public abstract class AbstractFeatureMojo extends 
AbstractMojo {
 
             // Finally, look the feature up via Maven's dependency mechanism
             return ProjectHelper.getOrResolveFeature(project, mavenSession, 
artifactHandlerManager,
-                artifactResolver, id);
+                repoSystem, id);
         }
     }
 
@@ -368,7 +368,7 @@ public abstract class AbstractFeatureMojo extends 
AbstractMojo {
         public URL provide(final ArtifactId id) {
             try {
                 return ProjectHelper
-                    .getOrResolveArtifact(project, mavenSession, 
artifactHandlerManager, artifactResolver, id)
+                    .getOrResolveArtifact(project, mavenSession, 
artifactHandlerManager, repoSystem, id)
                     .getFile().toURI().toURL();
             } catch (Exception e) {
                 getLog().debug("Artifact " + id.toMvnId() + " not found");
diff --git 
a/src/main/java/org/apache/sling/feature/maven/mojos/AbstractIncludingFeatureMojo.java
 
b/src/main/java/org/apache/sling/feature/maven/mojos/AbstractIncludingFeatureMojo.java
index 6938511..51d6b27 100644
--- 
a/src/main/java/org/apache/sling/feature/maven/mojos/AbstractIncludingFeatureMojo.java
+++ 
b/src/main/java/org/apache/sling/feature/maven/mojos/AbstractIncludingFeatureMojo.java
@@ -208,7 +208,7 @@ public abstract class AbstractIncludingFeatureMojo extends 
AbstractFeatureMojo {
                                         "RefsFile configuration is used to 
select a local feature: " + id.toMvnId());
                         }
                         final Feature feature = 
ProjectHelper.getOrResolveFeature(this.project, this.mavenSession,
-                                this.artifactHandlerManager, 
this.artifactResolver, id);
+                                this.artifactHandlerManager, this.repoSystem, 
id);
                         result.put(id.toMvnUrl(), feature);
                     } catch ( final IllegalArgumentException e) {
                         throw new MojoExecutionException("Reference " + url + 
" in " + selectedFile.getAbsolutePath() + " is not a supported url.");
@@ -228,7 +228,7 @@ public abstract class AbstractIncludingFeatureMojo extends 
AbstractFeatureMojo {
                         "FeatureArtifact configuration is used to select a 
local feature: " + id.toMvnId());
         }
         final Feature feature = 
ProjectHelper.getOrResolveFeature(this.project, this.mavenSession,
-                this.artifactHandlerManager, this.artifactResolver, id);
+                this.artifactHandlerManager, this.repoSystem, id);
         result.put(id.toMvnUrl(), feature);
     }
 
diff --git 
a/src/main/java/org/apache/sling/feature/maven/mojos/AbstractRepositoryMojo.java
 
b/src/main/java/org/apache/sling/feature/maven/mojos/AbstractRepositoryMojo.java
index 51e3435..5eab16a 100644
--- 
a/src/main/java/org/apache/sling/feature/maven/mojos/AbstractRepositoryMojo.java
+++ 
b/src/main/java/org/apache/sling/feature/maven/mojos/AbstractRepositoryMojo.java
@@ -107,7 +107,7 @@ public abstract class AbstractRepositoryMojo extends 
AbstractIncludingFeatureMoj
                 processFeature(artifactDir, prototype);
             } else {
                 final Feature prototype = 
ProjectHelper.getOrResolveFeature(project, mavenSession, artifactHandlerManager,
-                        artifactResolver, f.getPrototype().getId());
+                        repoSystem, f.getPrototype().getId());
                 processFeature(artifactDir, prototype);
             }
         }
@@ -140,7 +140,7 @@ public abstract class AbstractRepositoryMojo extends 
AbstractIncludingFeatureMoj
         File source = ProjectHelper.getOrResolveArtifact(this.project,
             this.mavenSession,
             this.artifactHandlerManager,
-            this.artifactResolver,
+            this.repoSystem,
             artifactId).getFile();
         if (ProjectHelper.isLocalProjectArtifact(this.project, artifactId) && 
source.isDirectory()) {
             if (artifactId.getClassifier() != null) {
diff --git 
a/src/main/java/org/apache/sling/feature/maven/mojos/AnalyseFeaturesMojo.java 
b/src/main/java/org/apache/sling/feature/maven/mojos/AnalyseFeaturesMojo.java
index 8cd87e5..8cac43b 100644
--- 
a/src/main/java/org/apache/sling/feature/maven/mojos/AnalyseFeaturesMojo.java
+++ 
b/src/main/java/org/apache/sling/feature/maven/mojos/AnalyseFeaturesMojo.java
@@ -193,7 +193,7 @@ public class AnalyseFeaturesMojo extends 
AbstractIncludingFeatureMojo {
             @Override
             public URL provide(final ArtifactId id) {
                 try {
-                    return ProjectHelper.getOrResolveArtifact(project, 
mavenSession, artifactHandlerManager, artifactResolver, 
id).getFile().toURI().toURL();
+                    return ProjectHelper.getOrResolveArtifact(project, 
mavenSession, artifactHandlerManager, repoSystem, id).getFile().toURI().toURL();
                 } catch (final MalformedURLException e) {
                     getLog().debug("Malformed url " + e.getMessage(), e);
                     // ignore
diff --git 
a/src/main/java/org/apache/sling/feature/maven/mojos/ApplyDefaultConfigMojo.java
 
b/src/main/java/org/apache/sling/feature/maven/mojos/ApplyDefaultConfigMojo.java
index e1db255..fd91563 100644
--- 
a/src/main/java/org/apache/sling/feature/maven/mojos/ApplyDefaultConfigMojo.java
+++ 
b/src/main/java/org/apache/sling/feature/maven/mojos/ApplyDefaultConfigMojo.java
@@ -92,7 +92,7 @@ public class ApplyDefaultConfigMojo extends 
AbstractIncludingFeatureMojo {
                             "configurationApiDependency configuration is used 
to select a local feature: " + depId.toMvnId());
             }
             final Feature f = ProjectHelper.getOrResolveFeature(this.project, 
this.mavenSession,
-                    this.artifactHandlerManager, this.artifactResolver, depId);
+                    this.artifactHandlerManager, this.repoSystem, depId);
             defaultApi = ConfigurationApi.getConfigurationApi(f);
             if ( defaultApi == null ) {
                 throw new MojoExecutionException("Specified feature " + 
depId.toMvnId() + " does not contain configuration api");
diff --git 
a/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeatureArchivesMojo.java
 
b/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeatureArchivesMojo.java
index b972a24..d17ec72 100644
--- 
a/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeatureArchivesMojo.java
+++ 
b/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeatureArchivesMojo.java
@@ -159,7 +159,7 @@ public class AttachFeatureArchivesMojo extends 
AbstractIncludingFeatureMojo {
 
                         try {
                             return ProjectHelper.getOrResolveArtifact(project, 
mavenSession, artifactHandlerManager,
-                                    artifactResolver, 
id).getFile().toURI().toURL();
+                                    repoSystem, id).getFile().toURI().toURL();
                         } catch (final MalformedURLException e) {
                             getLog().debug("Malformed url " + e.getMessage(), 
e);
                             // ignore
diff --git 
a/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeaturesMojo.java 
b/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeaturesMojo.java
index 7e62ce6..3fbff68 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeaturesMojo.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/AttachFeaturesMojo.java
@@ -101,7 +101,7 @@ public class AttachFeaturesMojo extends AbstractFeatureMojo 
{
                         final org.apache.maven.artifact.Artifact source = 
ProjectHelper.getOrResolveArtifact(this.project,
                              this.mavenSession,
                             this.artifactHandlerManager,
-                            this.artifactResolver,
+                            this.repoSystem,
                             bundle.getId());
         
                         try (final JarFile jarFile = new 
JarFile(source.getFile())) {
diff --git 
a/src/main/java/org/apache/sling/feature/maven/mojos/FeaturesDiffMojo.java 
b/src/main/java/org/apache/sling/feature/maven/mojos/FeaturesDiffMojo.java
index 97e4683..893d328 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/FeaturesDiffMojo.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/FeaturesDiffMojo.java
@@ -24,17 +24,10 @@ import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
-import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
-import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
-import org.apache.maven.artifact.versioning.ArtifactVersion;
+import java.util.Optional;
+
+import org.apache.maven.RepositoryUtils;
+import org.apache.maven.artifact.ArtifactUtils;
 import 
org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
 import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
 import org.apache.maven.artifact.versioning.VersionRange;
@@ -49,6 +42,14 @@ import org.apache.sling.feature.Feature;
 import org.apache.sling.feature.diff.DiffRequest;
 import org.apache.sling.feature.io.json.FeatureJSONReader;
 import org.apache.sling.feature.maven.FeatureConstants;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.resolution.ArtifactRequest;
+import org.eclipse.aether.resolution.ArtifactResult;
+import org.eclipse.aether.resolution.VersionRangeRequest;
+import org.eclipse.aether.resolution.VersionRangeResolutionException;
+import org.eclipse.aether.resolution.VersionRangeResult;
+import org.eclipse.aether.version.Version;
 
 /**
  * Compares different versions of the same Feature Model.
@@ -58,7 +59,6 @@ import org.apache.sling.feature.maven.FeatureConstants;
     requiresDependencyResolution = ResolutionScope.TEST,
     threadSafe = true
 )
-@SuppressWarnings("deprecation")
 public final class FeaturesDiffMojo extends AbstractIncludingFeatureMojo {
 
     @Parameter
@@ -71,13 +71,7 @@ public final class FeaturesDiffMojo extends 
AbstractIncludingFeatureMojo {
     protected String comparisonVersion;
 
     @Component
-    protected ArtifactResolver resolver;
-
-    @Component
-    protected ArtifactFactory factory;
-
-    @Component
-    private ArtifactMetadataSource metadataSource;
+    protected RepositorySystem repoSystem;
 
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
@@ -138,31 +132,26 @@ public final class FeaturesDiffMojo extends 
AbstractIncludingFeatureMojo {
             throw new MojoFailureException("Invalid comparison version: " + 
e.getMessage());
         }
 
-        Artifact previousArtifact;
-
-        try {
-            previousArtifact = 
factory.createDependencyArtifact(current.getId().getGroupId(),
+        org.eclipse.aether.artifact.Artifact previousArtifact = new 
DefaultArtifact(current.getId().getGroupId(),
                                                                 
current.getId().getArtifactId(),
-                                                                range,
                                                                 
current.getId().getType(),
                                                                 
current.getId().getClassifier(),
-                                                                
Artifact.SCOPE_COMPILE);
-
-            if 
(!previousArtifact.getVersionRange().isSelectedVersionKnown(previousArtifact)) {
-                getLog().debug("Searching for versions in range: " + 
previousArtifact.getVersionRange());
-                List<ArtifactVersion> availableVersions = 
metadataSource.retrieveAvailableVersions(previousArtifact,
-                                                                               
                    mavenSession.getLocalRepository(),
-                                                                               
                    project.getRemoteArtifactRepositories());
-                filterSnapshots(availableVersions);
-                ArtifactVersion version = 
range.matchVersion(availableVersions);
-                if (version != null) {
-                    previousArtifact.selectVersion(version.toString());
-                }
+                                                                
comparisonVersion);
+
+        try {
+            
+            if 
(!range.isSelectedVersionKnown(RepositoryUtils.toArtifact(previousArtifact))) {
+                getLog().debug("Searching for versions in range: " + 
comparisonVersion);
+                VersionRangeRequest vrr = new 
VersionRangeRequest(previousArtifact, project.getRemoteProjectRepositories(), 
null);
+                VersionRangeResult vrResult = 
repoSystem.resolveVersionRange(mavenSession.getRepositorySession(), vrr);
+                // filter out snapshots
+                Optional<Version> version = 
vrResult.getVersions().stream().filter(v -> 
!ArtifactUtils.isSnapshot(v.toString())).reduce((first, second) -> second);
+                
previousArtifact.setVersion(version.map(Version::toString).orElse(null));
             }
         } catch (OverConstrainedVersionException ocve) {
             throw new MojoFailureException("Invalid comparison version: " + 
ocve.getMessage());
-        } catch (ArtifactMetadataRetrievalException amre) {
-            throw new MojoExecutionException("Error determining previous 
version: " + amre.getMessage(), amre);
+        } catch (VersionRangeResolutionException e) {
+            throw new MojoExecutionException("Error determining previous 
version: " + e.getMessage(), e);
         }
 
         if (previousArtifact.getVersion() == null) {
@@ -170,16 +159,15 @@ public final class FeaturesDiffMojo extends 
AbstractIncludingFeatureMojo {
             return null;
         }
 
+        File featureFile = null;
         try {
-            resolver.resolve(previousArtifact, 
project.getRemoteArtifactRepositories(), mavenSession.getLocalRepository());
-        } catch (ArtifactResolutionException are) {
-            getLog().warn("Artifact " + previousArtifact + " cannot be 
resolved : " + are.getMessage(), are);
-        } catch (ArtifactNotFoundException anfe) {
-            getLog().warn("Artifact " + previousArtifact + " does not exist on 
local/remote repositories", anfe);
+            ArtifactRequest artifactRequest = new 
ArtifactRequest(previousArtifact, project.getRemoteProjectRepositories(), null);
+            ArtifactResult artifactResult = 
repoSystem.resolveArtifact(mavenSession.getRepositorySession(), 
artifactRequest);
+            featureFile = artifactResult.getArtifact().getFile();
+        } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) {
+            getLog().warn("Artifact " + previousArtifact + " cannot be 
resolved : " + e.getMessage(), e);
         }
 
-        File featureFile = previousArtifact.getFile();
-
         if (featureFile == null || !featureFile.exists()) {
             return null;
         }
@@ -191,14 +179,4 @@ public final class FeaturesDiffMojo extends 
AbstractIncludingFeatureMojo {
         }
     }
 
-    private void filterSnapshots(List<ArtifactVersion> versions) {
-        Iterator<ArtifactVersion> versionIterator = versions.iterator();
-        while (versionIterator.hasNext()) {
-            ArtifactVersion version = versionIterator.next();
-            if (version.getQualifier() != null && 
version.getQualifier().endsWith("SNAPSHOT")) {
-                versionIterator.remove();
-            }
-        }
-    }
-
 }
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/InfoMojo.java 
b/src/main/java/org/apache/sling/feature/maven/mojos/InfoMojo.java
index 0dcea13..d9b8492 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/InfoMojo.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/InfoMojo.java
@@ -315,7 +315,7 @@ public class InfoMojo extends AbstractIncludingFeatureMojo {
                 getLog().info("Searching " + id.toMvnId());
                 try {
                     return ProjectHelper
-                            .getOrResolveArtifact(project, mavenSession, 
artifactHandlerManager, artifactResolver, id)
+                            .getOrResolveArtifact(project, mavenSession, 
artifactHandlerManager, repoSystem, id)
                             .getFile().toURI().toURL();
                 } catch (final MalformedURLException e) {
                     getLog().debug("Malformed url " + e.getMessage(), e);
diff --git 
a/src/test/java/org/apache/sling/feature/maven/mojos/AbstractRepositoryMojoTest.java
 
b/src/test/java/org/apache/sling/feature/maven/mojos/AbstractRepositoryMojoTest.java
index 49bf113..b779101 100644
--- 
a/src/test/java/org/apache/sling/feature/maven/mojos/AbstractRepositoryMojoTest.java
+++ 
b/src/test/java/org/apache/sling/feature/maven/mojos/AbstractRepositoryMojoTest.java
@@ -16,32 +16,39 @@
  */
 package org.apache.sling.feature.maven.mojos;
 
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Comparator;
+
 import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
 import org.apache.sling.feature.ArtifactId;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.resolution.ArtifactResolutionException;
+import org.eclipse.aether.resolution.ArtifactResult;
+import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Comparator;
-
-import static org.junit.Assert.assertEquals;
-
 public class AbstractRepositoryMojoTest {
-    @Test
-    public void testCopyArtifactToRepository() throws Exception {
-        StringBuilder recordedOp = new StringBuilder();
+    private AbstractRepositoryMojo arm;
+    private StringBuilder recordedOp;
 
-        AbstractRepositoryMojo arm = new AbstractRepositoryMojo() {
+    @Before
+    public void setUp() throws ArtifactResolutionException {
+        recordedOp = new StringBuilder();
+        arm = new AbstractRepositoryMojo() {
             @Override
             public void execute() throws MojoExecutionException, 
MojoFailureException {
                 // not used here
@@ -59,11 +66,17 @@ public class AbstractRepositoryMojoTest {
         };
         arm.project = Mockito.mock(MavenProject.class);
         arm.mavenSession = Mockito.mock(MavenSession.class);
-        arm.artifactResolver = Mockito.mock(ArtifactResolver.class);
+        ArtifactResult artifactResult = Mockito.mock(ArtifactResult.class);
+        Mockito.when(artifactResult.getArtifact()).thenReturn(new 
DefaultArtifact("mygroup:dummyartifact:1.0.0"));
+        arm.repoSystem = Mockito.mock(RepositorySystem.class);
+        Mockito.when(arm.repoSystem.resolveArtifact(Mockito.any(), 
Mockito.any())).thenReturn(artifactResult);
         arm.artifactHandlerManager = 
Mockito.mock(ArtifactHandlerManager.class);
         
Mockito.when(arm.artifactHandlerManager.getArtifactHandler(Mockito.anyString()))
                     .thenReturn(Mockito.mock(ArtifactHandler.class));
+    }
 
+    @Test
+    public void testCopyArtifactToRepository() throws Exception {
         Method m = 
AbstractRepositoryMojo.class.getDeclaredMethod("copyArtifactToRepository", 
ArtifactId.class, File.class);
         m.setAccessible(true);
 
@@ -80,30 +93,6 @@ public class AbstractRepositoryMojoTest {
 
     @Test
     public void testCopyDecompressArtifactToRepository() throws Exception {
-        StringBuilder recordedOp = new StringBuilder();
-
-        AbstractRepositoryMojo arm = new AbstractRepositoryMojo() {
-            @Override
-            public void execute() throws MojoExecutionException, 
MojoFailureException {
-                // not used here
-            }
-
-            @Override
-            void copyAndDecompressArtifact(File sourceFile, File artifactFile) 
throws IOException {
-                recordedOp.append("copy_decompress");
-            }
-
-            @Override
-            void copyArtifact(File sourceFile, File artifactFile) throws 
IOException {
-                recordedOp.append("copy");
-            }
-        };
-        arm.project = Mockito.mock(MavenProject.class);
-        arm.mavenSession = Mockito.mock(MavenSession.class);
-        arm.artifactResolver = Mockito.mock(ArtifactResolver.class);
-        arm.artifactHandlerManager = 
Mockito.mock(ArtifactHandlerManager.class);
-        
Mockito.when(arm.artifactHandlerManager.getArtifactHandler(Mockito.anyString()))
-                    .thenReturn(Mockito.mock(ArtifactHandler.class));
         arm.decompress = true;
 
         Method m = 
AbstractRepositoryMojo.class.getDeclaredMethod("copyArtifactToRepository", 
ArtifactId.class, File.class);
diff --git 
a/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojoTest.java
 
b/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojoTest.java
index a8b5164..17cd838 100644
--- 
a/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojoTest.java
+++ 
b/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojoTest.java
@@ -45,7 +45,6 @@ import java.util.Set;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.DefaultArtifact;
 import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.artifact.versioning.VersionRange;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Build;
@@ -60,6 +59,7 @@ import org.apache.sling.feature.builder.BuilderContext;
 import org.apache.sling.feature.io.json.FeatureJSONReader;
 import org.apache.sling.feature.maven.FeatureConstants;
 import org.apache.sling.feature.maven.Preprocessor;
+import org.eclipse.aether.RepositorySystem;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -464,7 +464,7 @@ public class AggregateFeaturesMojoTest {
         af.artifactHandlerManager = Mockito.mock(ArtifactHandlerManager.class);
         af.features = featureFile.getParentFile();
 
-        af.artifactResolver = Mockito.mock(ArtifactResolver.class);
+        af.repoSystem = Mockito.mock(RepositorySystem.class);
         af.execute();
 
         Feature genFeat = featureMap.get(":aggregate:mynewfeature:T");


Reply via email to