sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-slingstart-maven-plugin] 18/27: Get artifacts from repositor if overlayed with a different version
Date Tue, 07 Nov 2017 10:25:47 GMT
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag slingstart-maven-plugin-1.0.0
in repository https://gitbox.apache.org/repos/asf/sling-slingstart-maven-plugin.git

commit b4cf460deec52885b16dbcd429c409e789e9ddf8
Author: Carsten Ziegeler <cziegeler@apache.org>
AuthorDate: Wed Oct 8 14:51:46 2014 +0000

    Get artifacts from repositor if overlayed with a different version
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/maven/slingstart-maven-plugin@1630130
13f79535-47bb-0310-9956-ffa450edef68
---
 .../apache/sling/maven/slingstart/ModelUtils.java  | 25 +++++++++++++++++++++-
 .../sling/maven/slingstart/PreparePackageMojo.java | 17 +++++++++++++--
 2 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/sling/maven/slingstart/ModelUtils.java b/src/main/java/org/apache/sling/maven/slingstart/ModelUtils.java
index 4290fe7..cb079c9 100644
--- a/src/main/java/org/apache/sling/maven/slingstart/ModelUtils.java
+++ b/src/main/java/org/apache/sling/maven/slingstart/ModelUtils.java
@@ -29,6 +29,12 @@ import java.util.Set;
 
 import org.apache.commons.io.IOUtils;
 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.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
@@ -178,6 +184,9 @@ public abstract class ModelUtils {
      * @throws MojoExecutionException
      */
     public static Artifact getArtifact(final MavenProject project,
+            final MavenSession session,
+            final ArtifactHandlerManager artifactHandlerManager,
+            final ArtifactResolver resolver,
             final String groupId, final String artifactId, final String version, final String
type, final String classifier)
     throws MojoExecutionException {
         final Set<Artifact> artifacts = project.getDependencyArtifacts();
@@ -190,7 +199,21 @@ public abstract class ModelUtils {
                 return artifact;
             }
         }
-        return null;
+        final Artifact prjArtifact = new DefaultArtifact(groupId,
+                artifactId,
+                VersionRange.createFromVersion(version),
+                Artifact.SCOPE_PROVIDED,
+                type,
+                classifier,
+                artifactHandlerManager.getArtifactHandler(type));
+        try {
+            resolver.resolve(prjArtifact, project.getRemoteArtifactRepositories(), session.getLocalRepository());
+        } catch (final ArtifactResolutionException e) {
+            throw new MojoExecutionException("Unable to get artifact for " + groupId + ":"
+ artifactId + ":" + version, e);
+        } catch (final ArtifactNotFoundException e) {
+            throw new MojoExecutionException("Unable to get artifact for " + groupId + ":"
+ artifactId + ":" + version, e);
+        }
+        return prjArtifact;
     }
 
     private static final String RAW_MODEL_TXT = Model.class.getName() + "/raw.txt";
diff --git a/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java b/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java
index 1da050e..e29620f 100644
--- a/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java
+++ b/src/main/java/org/apache/sling/maven/slingstart/PreparePackageMojo.java
@@ -29,6 +29,8 @@ import java.util.TreeSet;
 import org.apache.commons.io.IOUtils;
 import org.apache.felix.cm.file.ConfigurationHandler;
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugins.annotations.Component;
@@ -76,6 +78,16 @@ public class PreparePackageMojo extends AbstractSlingStartMojo {
     @Component
     private ArchiverManager archiverManager;
 
+    @Component
+    private ArtifactHandlerManager artifactHandlerManager;
+
+    /**
+     * Used to look up Artifacts in the remote repository.
+     *
+     */
+    @Component
+    private ArtifactResolver resolver;
+
     @Override
     public void execute() throws MojoExecutionException, MojoFailureException {
         final Model model = ModelUtils.getEffectiveModel(this.project);
@@ -183,7 +195,7 @@ public class PreparePackageMojo extends AbstractSlingStartMojo {
     throws MojoExecutionException{
         for(final ArtifactGroup group : runMode.getArtifactGroups()) {
             for(final org.apache.sling.provisioning.model.Artifact a : group) {
-                final Artifact artifact = ModelUtils.getArtifact(this.project, a.getGroupId(),
a.getArtifactId(), a.getVersion(), a.getType(), a.getClassifier());
+                final Artifact artifact = ModelUtils.getArtifact(this.project, this.mavenSession,
this.artifactHandlerManager, this.resolver, a.getGroupId(), a.getArtifactId(), a.getVersion(),
a.getType(), a.getClassifier());
                 final File artifactFile = artifact.getFile();
                 contentsMap.put(getPathForArtifact(group.getStartLevel(), artifactFile.getName(),
runMode, isBoot), artifactFile);
             }
@@ -309,7 +321,8 @@ public class PreparePackageMojo extends AbstractSlingStartMojo {
     private Artifact getBaseArtifact(final Model model, final String classifier, final String
type) throws MojoExecutionException {
         final org.apache.sling.provisioning.model.Artifact baseArtifact = ModelUtils.getBaseArtifact(model);
 
-        final Artifact a = ModelUtils.getArtifact(this.project, baseArtifact.getGroupId(),
+        final Artifact a = ModelUtils.getArtifact(this.project,  this.mavenSession, this.artifactHandlerManager,
this.resolver,
+                baseArtifact.getGroupId(),
                 baseArtifact.getArtifactId(),
                 baseArtifact.getVersion(),
                 type,

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message