You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by pa...@apache.org on 2019/06/07 16:43:34 UTC

[sling-slingfeature-maven-plugin] branch issues/SLING-8421 created (now daf5fe1)

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

pauls pushed a change to branch issues/SLING-8421
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git.


      at daf5fe1  SLING-8421: Allow artifact providers that work with URLs instead of Files

This branch includes the following new commits:

     new daf5fe1  SLING-8421: Allow artifact providers that work with URLs instead of Files

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[sling-slingfeature-maven-plugin] 01/01: SLING-8421: Allow artifact providers that work with URLs instead of Files

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pauls pushed a commit to branch issues/SLING-8421
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git

commit daf5fe16ea9c11caf7a8a4142f85cdcba6b4d068
Author: Karl Pauls <ka...@gmail.com>
AuthorDate: Fri Jun 7 18:43:20 2019 +0200

    SLING-8421: Allow artifact providers that work with URLs instead of Files
---
 pom.xml                                            |  6 +++---
 .../apache/sling/feature/maven/Preprocessor.java   | 20 +++++++++++++----
 .../feature/maven/mojos/AggregateFeaturesMojo.java | 18 ++++++++++++----
 .../feature/maven/mojos/AnalyseFeaturesMojo.java   | 14 ++++++++++--
 .../sling/feature/maven/mojos/ApisJarMojo.java     | 25 +++++++++++++++-------
 5 files changed, 62 insertions(+), 21 deletions(-)

diff --git a/pom.xml b/pom.xml
index 7d9f48a..b171561 100644
--- a/pom.xml
+++ b/pom.xml
@@ -159,17 +159,17 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.feature</artifactId>
-            <version>1.0.2</version>
+            <version>1.0.3-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.feature.io</artifactId>
-            <version>1.0.2</version>
+            <version>1.0.3-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.feature.analyser</artifactId>
-            <version>1.0.2</version>
+            <version>1.0.3-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.apache.maven</groupId>
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 a1661e1..9562877 100644
--- a/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
+++ b/src/main/java/org/apache/sling/feature/maven/Preprocessor.java
@@ -23,6 +23,7 @@ import java.io.Reader;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.Writer;
+import java.net.MalformedURLException;
 import java.util.ArrayList;
 import java.util.Formatter;
 import java.util.HashMap;
@@ -218,10 +219,21 @@ public class Preprocessor {
     		                config.isSkipAddDependencies(),
                                     config.getScope(), null))
                                             .setArtifactProvider(
-                                                    aid -> ProjectHelper
-                                                            .getOrResolveArtifact(info.project, env.session,
-                                                                    env.artifactHandlerManager, env.resolver, aid)
-                                                            .getFile()));
+                                                    aid ->
+                                                    {
+                                                        try
+                                                        {
+                                                            return ProjectHelper
+                                                                    .getOrResolveArtifact(info.project, env.session,
+                                                                            env.artifactHandlerManager, env.resolver, aid)
+                                                                    .getFile().toURI().toURL();
+                                                        }
+                                                        catch (Exception e)
+                                                        {
+                                                            env.logger.error(e.getMessage(), e);
+                                                            return null;
+                                                        }
+                                                    }));
     	            aggregatedFeatures.put(entry.getKey(), assembledFeature);
     	            break;
         		}
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojo.java b/src/main/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojo.java
index c600d02..6ba448b 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojo.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojo.java
@@ -34,6 +34,8 @@ import org.apache.sling.feature.maven.FeatureConstants;
 import org.apache.sling.feature.maven.ProjectHelper;
 
 import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -117,7 +119,7 @@ public class AggregateFeaturesMojo extends AbstractIncludingFeatureMojo {
             }).setArtifactProvider(new ArtifactProvider() {
 
                 @Override
-                public File provide(final ArtifactId id) {
+                public URL provide(final ArtifactId id) {
                     if (ProjectHelper.isLocalProjectArtifact(project, id)) {
                         for (final Map.Entry<String, Feature> entry : ProjectHelper.getAssembledFeatures(project)
                                 .entrySet()) {
@@ -128,9 +130,17 @@ public class AggregateFeaturesMojo extends AbstractIncludingFeatureMojo {
                             }
                         }
                     }
-                    return ProjectHelper
-                            .getOrResolveArtifact(project, mavenSession, artifactHandlerManager, artifactResolver, id)
-                            .getFile();
+                    try
+                    {
+                        return ProjectHelper
+                                .getOrResolveArtifact(project, mavenSession, artifactHandlerManager, artifactResolver, id)
+                                .getFile().toURI().toURL();
+                    }
+                    catch (Exception e)
+                    {
+                        getLog().error(e);
+                        return null;
+                    }
                 }
             }).addArtifactsOverrides(artifactsOverrides)
                 .addVariablesOverrides(variablesOverwrites)
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 f04c7b5..613d256 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
@@ -34,6 +34,8 @@ import org.apache.sling.feature.scanner.Scanner;
 
 import java.io.File;
 import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -73,8 +75,16 @@ public class AnalyseFeaturesMojo extends AbstractIncludingFeatureMojo {
         final ArtifactProvider am = new ArtifactProvider() {
 
             @Override
-            public File provide(final ArtifactId id) {
-                return ProjectHelper.getOrResolveArtifact(project, mavenSession, artifactHandlerManager, artifactResolver, id).getFile();
+            public URL provide(final ArtifactId id) {
+                try
+                {
+                    return ProjectHelper.getOrResolveArtifact(project, mavenSession, artifactHandlerManager, artifactResolver, id).getFile().toURI().toURL();
+                }
+                catch (Exception e)
+                {
+                    getLog().error(e);
+                    return null;
+                }
             }
         };
 
diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/ApisJarMojo.java b/src/main/java/org/apache/sling/feature/maven/mojos/ApisJarMojo.java
index e23e5ae..18caf5a 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/ApisJarMojo.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/ApisJarMojo.java
@@ -19,6 +19,8 @@ package org.apache.sling.feature.maven.mojos;
 import java.io.File;
 import java.io.IOException;
 import java.io.StringReader;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -168,10 +170,17 @@ public class ApisJarMojo extends AbstractIncludingFeatureMojo implements Artifac
         artifactProvider = new ArtifactProvider() {
 
             @Override
-            public File provide(final ArtifactId id) {
-                return ProjectHelper.getOrResolveArtifact(project, mavenSession, artifactHandlerManager, artifactResolver, id).getFile();
+            public URL provide(final ArtifactId id) {
+                try
+                {
+                    return ProjectHelper.getOrResolveArtifact(project, mavenSession, artifactHandlerManager, artifactResolver, id).getFile().toURI().toURL();
+                }
+                catch (Exception e)
+                {
+                    getLog().error(e);
+                    return null;
+                }
             }
-
         };
 
         getLog().debug("Retrieving Feature files...");
@@ -263,7 +272,7 @@ public class ApisJarMojo extends AbstractIncludingFeatureMojo implements Artifac
                             File deflatedSourcesDir,
                             File checkedOutSourcesDir) throws MojoExecutionException {
         ArtifactId artifactId = artifact.getId();
-        File bundleFile = retrieve(artifactId);
+        File bundleFile = new File(retrieve(artifactId).getPath());
 
         Manifest manifest;
         if (wrappingBundleManifest == null) {
@@ -466,9 +475,9 @@ public class ApisJarMojo extends AbstractIncludingFeatureMojo implements Artifac
         }
     }
 
-    private File retrieve(ArtifactId artifactId) {
+    private URL retrieve(ArtifactId artifactId) {
         getLog().debug("Retrieving artifact " + artifactId + "...");
-        File sourceFile = artifactProvider.provide(artifactId);
+        URL sourceFile = artifactProvider.provide(artifactId);
         getLog().debug("Artifact " + artifactId + " successfully retrieved");
         return sourceFile;
     }
@@ -541,7 +550,7 @@ public class ApisJarMojo extends AbstractIncludingFeatureMojo implements Artifac
                                                     "sources",
                                                     "jar");
         try {
-            File sourcesBundle = retrieve(sourcesArtifactId);
+            File sourcesBundle = new File(retrieve(sourcesArtifactId).getPath());
             deflate(deflatedSourcesDir, sourcesBundle, exportedPackages);
         } catch (Throwable t) {
             getLog().warn("Impossible to download -sources bundle "
@@ -558,7 +567,7 @@ public class ApisJarMojo extends AbstractIncludingFeatureMojo implements Artifac
             ArtifactId pomArtifactId = newArtifacId(artifactId, null, "pom");
             getLog().debug("Falling back to SCM checkout, retrieving POM " + pomArtifactId + "...");
             // POM file must exist, let the plugin fail otherwise
-            File pomFile = retrieve(pomArtifactId);
+            File pomFile = new File(retrieve(pomArtifactId).getPath());
             getLog().debug("POM " + pomArtifactId + " successfully retrieved, reading the model...");
 
             // read model