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:41:52 UTC

[sling-org-apache-sling-feature-modelconverter] branch issues/SLING-8421 created (now decbd0a)

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


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

This branch includes the following new commits:

     new decbd0a  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-org-apache-sling-feature-modelconverter] 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-org-apache-sling-feature-modelconverter.git

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

    SLING-8421: Allow artifact providers that work with URLs instead of Files
---
 pom.xml                                            |  4 ++--
 .../modelconverter/ProvisioningToFeature.java      | 25 ++++++++++++----------
 .../feature/modelconverter/ModelConverterTest.java | 18 +++++++++-------
 3 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/pom.xml b/pom.xml
index f695b50..77e9d15 100644
--- a/pom.xml
+++ b/pom.xml
@@ -69,13 +69,13 @@
         <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>
diff --git a/src/main/java/org/apache/sling/feature/modelconverter/ProvisioningToFeature.java b/src/main/java/org/apache/sling/feature/modelconverter/ProvisioningToFeature.java
index 961b22a..02f27d3 100644
--- a/src/main/java/org/apache/sling/feature/modelconverter/ProvisioningToFeature.java
+++ b/src/main/java/org/apache/sling/feature/modelconverter/ProvisioningToFeature.java
@@ -20,6 +20,9 @@ import java.io.File;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -37,9 +40,9 @@ import org.apache.sling.feature.Configurations;
 import org.apache.sling.feature.Extension;
 import org.apache.sling.feature.ExtensionType;
 import org.apache.sling.feature.Extensions;
-import org.apache.sling.feature.io.file.ArtifactHandler;
-import org.apache.sling.feature.io.file.ArtifactManager;
-import org.apache.sling.feature.io.file.ArtifactManagerConfig;
+import org.apache.sling.feature.io.artifacts.ArtifactHandler;
+import org.apache.sling.feature.io.artifacts.ArtifactManager;
+import org.apache.sling.feature.io.artifacts.ArtifactManagerConfig;
 import org.apache.sling.feature.io.json.FeatureJSONWriter;
 import org.apache.sling.provisioning.model.Artifact;
 import org.apache.sling.provisioning.model.ArtifactGroup;
@@ -127,7 +130,7 @@ public class ProvisioningToFeature {
         Model model = null;
         for(final File initFile : files) {
             try {
-                model = processModel(model, initFile, includeModelInfo, variableResolver);
+                model = processModel(model, initFile.toURI().toURL(), includeModelInfo, variableResolver);
             } catch ( final IOException iae) {
                 LOGGER.error("Unable to read provisioning model {} : {}", initFile, iae.getMessage(), iae);
                 System.exit(1);
@@ -170,7 +173,7 @@ public class ProvisioningToFeature {
      * @throws IOException If reading fails
      */
     private static Model processModel(Model model,
-            File modelFile, boolean includeModelInfo) throws IOException {
+            URL modelFile, boolean includeModelInfo) throws IOException {
         return processModel(model, modelFile, includeModelInfo,
             new ResolverOptions().variableResolver(new VariableResolver() {
                 @Override
@@ -182,7 +185,7 @@ public class ProvisioningToFeature {
     }
 
     private static Model processModel(Model model,
-            File modelFile, boolean includeModelInfo, ResolverOptions options) throws IOException {
+            URL modelFile, boolean includeModelInfo, ResolverOptions options) throws IOException {
         LOGGER.info("- reading model {}", modelFile);
 
         final Model nextModel = readProvisioningModel(modelFile);
@@ -206,14 +209,14 @@ public class ProvisioningToFeature {
                                     "txt");
 
                             final ArtifactHandler handler = mgr.getArtifactHandler(correctedId.toMvnUrl());
-                            model = processModel(model, handler.getFile(), includeModelInfo);
+                            model = processModel(model, handler.getLocalURL(), includeModelInfo);
 
                             removeList.add(a);
                         } else {
                             final org.apache.sling.provisioning.model.Artifact realArtifact = nextModel.getFeature(feature.getName()).getRunMode(runMode.getNames()).getArtifactGroup(group.getStartLevel()).search(a);
 
                             if ( includeModelInfo ) {
-                                realArtifact.getMetadata().put("model-filename", modelFile.getName());
+                                realArtifact.getMetadata().put("model-filename", modelFile.getPath().substring(modelFile.getPath().lastIndexOf("/") + 1));
                             }
                             if ( runMode.getNames() != null ) {
                                 realArtifact.getMetadata().put("runmodes", String.join(",", runMode.getNames()));
@@ -238,10 +241,10 @@ public class ProvisioningToFeature {
     /**
      * Read the provisioning model
      */
-    private static Model readProvisioningModel(final File file)
+    private static Model readProvisioningModel(final URL file)
     throws IOException {
-        try (final FileReader is = new FileReader(file)) {
-            return ModelReader.read(is, file.getAbsolutePath());
+        try (final Reader is = new InputStreamReader(file.openStream(), "UTF-8")) {
+            return ModelReader.read(is, file.getPath());
         }
     }
 
diff --git a/src/test/java/org/apache/sling/feature/modelconverter/ModelConverterTest.java b/src/test/java/org/apache/sling/feature/modelconverter/ModelConverterTest.java
index 498cb2e..797ddf8 100644
--- a/src/test/java/org/apache/sling/feature/modelconverter/ModelConverterTest.java
+++ b/src/test/java/org/apache/sling/feature/modelconverter/ModelConverterTest.java
@@ -22,9 +22,9 @@ import org.apache.sling.feature.Extension;
 import org.apache.sling.feature.ExtensionType;
 import org.apache.sling.feature.Extensions;
 import org.apache.sling.feature.builder.FeatureProvider;
-import org.apache.sling.feature.io.file.ArtifactHandler;
-import org.apache.sling.feature.io.file.ArtifactManager;
-import org.apache.sling.feature.io.file.ArtifactManagerConfig;
+import org.apache.sling.feature.io.artifacts.ArtifactHandler;
+import org.apache.sling.feature.io.artifacts.ArtifactManager;
+import org.apache.sling.feature.io.artifacts.ArtifactManagerConfig;
 import org.apache.sling.feature.io.json.FeatureJSONReader;
 import org.apache.sling.provisioning.model.Artifact;
 import org.apache.sling.provisioning.model.ArtifactGroup;
@@ -50,9 +50,11 @@ import org.mockito.stubbing.Answer;
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 import java.io.Reader;
 import java.io.UncheckedIOException;
 import java.net.URISyntaxException;
+import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -94,9 +96,9 @@ public class ModelConverterTest {
         featureProvider =
             id -> {
                 try {
-                    File file = artifactManager.getArtifactHandler(id.toMvnUrl()).getFile();
-                    try (Reader reader = new FileReader(file)) {
-                        return FeatureJSONReader.read(reader, file.toURI().toURL().toString());
+                    URL file = artifactManager.getArtifactHandler(id.toMvnUrl()).getLocalURL();
+                    try (Reader reader = new InputStreamReader(file.openStream(), "UTF-8")) {
+                        return FeatureJSONReader.read(reader, file.toString());
                     }
                 } catch (IOException e) {
                     throw new UncheckedIOException(e);
@@ -215,9 +217,9 @@ public class ModelConverterTest {
                 String url = in.getArgument(0).toString();
 
                 if (url.endsWith("simple_inherits.json")) {
-                    return new ArtifactHandler(url, new File(url));
+                    return new ArtifactHandler(url, new URL(url));
                 } else if ("mvn:generated/simple/1.0.0".equals(url)) {
-                    return new ArtifactHandler(url, new File(getClass().getResource("/simple.json").toURI()));
+                    return new ArtifactHandler(url, getClass().getResource("/simple.json"));
                 }
                 return null;
             }