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:40:24 UTC

[sling-org-apache-sling-feature-extension-content] 01/01: SLING-8421: Allow artifact providers that work with URLs instead of Files

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-org-apache-sling-feature-extension-content.git

commit 52fcd2dfbe65c25c3d3382879d0070efa9debc6d
Author: Karl Pauls <kp...@adobe.com>
AuthorDate: Fri Jun 7 18:40:11 2019 +0200

    SLING-8421: Allow artifact providers that work with URLs instead of Files
---
 pom.xml                                            |  6 ++---
 .../feature/extension/content/ContentHandler.java  | 27 ++++++++++++++++++----
 .../extension/content/ContentHandlerTest.java      |  6 ++---
 3 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/pom.xml b/pom.xml
index 4ad3e37..347ee33 100644
--- a/pom.xml
+++ b/pom.xml
@@ -127,19 +127,19 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.feature</artifactId>
-            <version>1.0.2</version>
+            <version>1.0.3-SNAPSHOT</version>
             <scope>provided</scope>
         </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>
             <scope>provided</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.feature.launcher</artifactId>
-            <version>1.0.2</version>
+            <version>1.0.3-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
diff --git a/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java b/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java
index 1111a32..50f9cf0 100644
--- a/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java
+++ b/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java
@@ -18,7 +18,11 @@ package org.apache.sling.feature.extension.content;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
 import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -51,12 +55,26 @@ public class ContentHandler implements ExtensionHandler {
 
     private static ExecutionPlanBuilder buildExecutionPlan(Collection<Artifact> artifacts, Set<PackageId> satisfiedPackages, LauncherPrepareContext prepareContext, File registryHome) throws Exception {
 
-        List<File> packageReferences = new ArrayList<File>();
+        List<File> packageReferences = new ArrayList<>();
 
         for (final Artifact a : artifacts) {
-            final File file = prepareContext.getArtifactFile(a.getId());
-            if (file.exists() && file.length() > 0) {
-                packageReferences.add(file);
+            final URL file = prepareContext.getArtifactFile(a.getId());
+            File tmp;
+            if (file.getProtocol().equals("file")) {
+                tmp = new File(file.getPath());
+            }
+            else {
+                tmp = File.createTempFile("contenthandler", ".zip");
+                try (FileOutputStream output = new FileOutputStream(tmp); InputStream input = file.openStream()) {
+                    byte[] buffer = new byte[64 * 1024];
+                    for (int i = input.read(buffer); i != -1; i = input.read(buffer)) {
+                        output.write(buffer, 0 ,i);
+                    }
+                }
+            }
+            if (tmp.length() > 0)
+            {
+                packageReferences.add(tmp);
             }
 
         }
@@ -71,6 +89,7 @@ public class ContentHandler implements ExtensionHandler {
         builder.with(satisfiedPackages);
 
         for (File pkgFile : packageReferences) {
+
             PackageId pid = registry.registerExternal(pkgFile, true);
             extractSubPackages(registry, builder, pid);
 
diff --git a/src/test/java/org/apache/sling/feature/extension/content/ContentHandlerTest.java b/src/test/java/org/apache/sling/feature/extension/content/ContentHandlerTest.java
index adbcbd9..7e65070 100644
--- a/src/test/java/org/apache/sling/feature/extension/content/ContentHandlerTest.java
+++ b/src/test/java/org/apache/sling/feature/extension/content/ContentHandlerTest.java
@@ -76,11 +76,11 @@ public class ContentHandlerTest {
     @Before
     public void setUp() throws Exception {
         URL test_a = this.getClass().getResource(TEST_PACKAGE_A_10);
-        when(extensionContext.getArtifactFile(TEST_PACKAGE_AID_A_10)).thenReturn(new File(test_a.getFile()));
+        when(extensionContext.getArtifactFile(TEST_PACKAGE_AID_A_10)).thenReturn(test_a);
         URL test_b = this.getClass().getResource(TEST_PACKAGE_B_10);
-        when(extensionContext.getArtifactFile(TEST_PACKAGE_AID_B_10)).thenReturn(new File(test_b.getFile()));
+        when(extensionContext.getArtifactFile(TEST_PACKAGE_AID_B_10)).thenReturn(test_b);
         URL test_c = this.getClass().getResource(TEST_PACKAGE_C_10);
-        when(extensionContext.getArtifactFile(TEST_PACKAGE_AID_C_10)).thenReturn(new File(test_c.getFile()));
+        when(extensionContext.getArtifactFile(TEST_PACKAGE_AID_C_10)).thenReturn(test_c);
     }
 
     @Test