You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by da...@apache.org on 2018/09/20 16:23:23 UTC

[sling-org-apache-sling-feature-modelconverter] branch master updated: Make model converter work with feature and feature.io 1.3.0-SNAPSHOT

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-modelconverter.git


The following commit(s) were added to refs/heads/master by this push:
     new c6c88f9  Make model converter work with feature and feature.io 1.3.0-SNAPSHOT
c6c88f9 is described below

commit c6c88f9d4ebaf842aedfdfd6f0605abcbc685eed
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Thu Sep 20 18:22:31 2018 +0200

    Make model converter work with feature and feature.io 1.3.0-SNAPSHOT
---
 pom.xml                                            |  4 ++--
 .../modelconverter/FeatureToProvisioning.java      | 17 +++++++------
 .../modelconverter/ProvisioningToFeature.java      | 28 ++++------------------
 .../feature/modelconverter/ModelConverterTest.java | 11 ++++-----
 src/test/resources/simple_inherits.json            |  9 ++++---
 5 files changed, 24 insertions(+), 45 deletions(-)

diff --git a/pom.xml b/pom.xml
index 34c7e40..fab614c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -129,7 +129,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.feature</artifactId>
-            <version>0.1.2</version>
+            <version>0.1.3-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
@@ -141,7 +141,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.feature.io</artifactId>
-            <version>0.1.2</version>
+            <version>0.1.3-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
diff --git a/src/main/java/org/apache/sling/feature/modelconverter/FeatureToProvisioning.java b/src/main/java/org/apache/sling/feature/modelconverter/FeatureToProvisioning.java
index 9b2cd8a..4301b00 100644
--- a/src/main/java/org/apache/sling/feature/modelconverter/FeatureToProvisioning.java
+++ b/src/main/java/org/apache/sling/feature/modelconverter/FeatureToProvisioning.java
@@ -51,7 +51,6 @@ import org.apache.sling.feature.io.ArtifactHandler;
 import org.apache.sling.feature.io.ArtifactManager;
 import org.apache.sling.feature.io.IOUtils;
 import org.apache.sling.feature.io.json.FeatureJSONReader;
-import org.apache.sling.feature.io.json.FeatureJSONReader.SubstituteVariables;
 import org.apache.sling.provisioning.model.Artifact;
 import org.apache.sling.provisioning.model.Configuration;
 import org.apache.sling.provisioning.model.Feature;
@@ -76,8 +75,8 @@ public class FeatureToProvisioning {
             }
         }
 
-        org.apache.sling.feature.Feature feature = IOUtils.getFeature(inputFile.getAbsolutePath(), am, SubstituteVariables.NONE);
-        if (feature.getIncludes().size() > 0) {
+        org.apache.sling.feature.Feature feature = IOUtils.getFeature(inputFile.getAbsolutePath(), am);
+        if (feature.getInclude() != null) {
             feature = handleIncludes(feature, additionalInputFiles, am);
         }
 
@@ -89,7 +88,7 @@ public class FeatureToProvisioning {
             featureName = feature.getId().getArtifactId();
         }
 
-        String runMode = (String) feature.getVariables().remove(PROVISIONING_RUNMODES);
+        String runMode = feature.getVariables().remove(PROVISIONING_RUNMODES);
         String[] runModes = null;
         if (runMode != null) {
             runModes = runMode.split(",");
@@ -104,7 +103,7 @@ public class FeatureToProvisioning {
         Map<ArtifactId, org.apache.sling.feature.Feature> features = new HashMap<>();
 
         for (File f : additionalFiles) {
-            org.apache.sling.feature.Feature af = IOUtils.getFeature(f.getAbsolutePath(), am, SubstituteVariables.NONE);
+            org.apache.sling.feature.Feature af = IOUtils.getFeature(f.getAbsolutePath(), am);
             features.put(af.getId(), af);
         }
 
@@ -121,7 +120,7 @@ public class FeatureToProvisioning {
                 try {
                     ArtifactHandler ah = am.getArtifactHandler(id.toMvnUrl());
                     if (ah != null) {
-                        org.apache.sling.feature.Feature feat = IOUtils.getFeature(ah.getUrl(), am, SubstituteVariables.NONE);
+                        org.apache.sling.feature.Feature feat = IOUtils.getFeature(ah.getUrl(), am);
                         if (feat != null) {
                             // Cache it
                             features.put(feat.getId(), feat);
@@ -143,7 +142,7 @@ public class FeatureToProvisioning {
 
         for(final File file : files) {
             try (final FileReader r = new FileReader(file)) {
-                final org.apache.sling.feature.Feature f = FeatureJSONReader.read(r, file.getAbsolutePath(), SubstituteVariables.NONE);
+                final org.apache.sling.feature.Feature f = FeatureJSONReader.read(r, file.getAbsolutePath());
                 features.put(f.getId(), f);
             }
         }
@@ -161,7 +160,7 @@ public class FeatureToProvisioning {
                 try {
                     ArtifactHandler ah = am.getArtifactHandler(id.toMvnUrl());
                     if (ah != null) {
-                        org.apache.sling.feature.Feature feat = IOUtils.getFeature(ah.getUrl(), am, SubstituteVariables.NONE);
+                        org.apache.sling.feature.Feature feat = IOUtils.getFeature(ah.getUrl(), am);
                         if (feat != null) {
                             // Cache it
                             features.put(feat.getId(), feat);
@@ -212,7 +211,7 @@ public class FeatureToProvisioning {
             final ArtifactId id = bundle.getId();
             final Artifact newBundle = new Artifact(id.getGroupId(), id.getArtifactId(), id.getVersion(), id.getClassifier(), id.getType());
 
-            Object configs = bundle.getMetadata().getObject("configurations");
+            Object configs = bundle.getMetadata().get("configurations");
             if (configs instanceof List) {
                 for (Object config : (List<?>) configs) {
                     if (config instanceof org.apache.sling.feature.Configuration) {
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 75a5887..474ef75 100644
--- a/src/main/java/org/apache/sling/feature/modelconverter/ProvisioningToFeature.java
+++ b/src/main/java/org/apache/sling/feature/modelconverter/ProvisioningToFeature.java
@@ -29,7 +29,6 @@ import org.apache.sling.feature.io.ArtifactHandler;
 import org.apache.sling.feature.io.ArtifactManager;
 import org.apache.sling.feature.io.ArtifactManagerConfig;
 import org.apache.sling.feature.io.IOUtils;
-import org.apache.sling.feature.io.json.ApplicationJSONWriter;
 import org.apache.sling.feature.io.json.FeatureJSONWriter;
 import org.apache.sling.provisioning.model.Artifact;
 import org.apache.sling.provisioning.model.ArtifactGroup;
@@ -105,17 +104,11 @@ public class ProvisioningToFeature {
             boolean includeModelInfo, String propsFile) {
         final Model model = createModel(files, runModes, false, includeModelInfo);
 
-        if ( createApp ) {
-            final Application app = buildApplication(model, propsFile);
-
-            writeApplication(app, outputFile);
-        } else {
-            final List<org.apache.sling.feature.Feature> features = buildFeatures(model, null, Collections.emptyMap());
-            int index = 1;
-            for(final org.apache.sling.feature.Feature feature : features) {
-                writeFeature(feature, outputFile, features.size() > 1 ? index : 0);
-                index++;
-            }
+        final List<org.apache.sling.feature.Feature> features = buildFeatures(model, null, Collections.emptyMap());
+        int index = 1;
+        for(final org.apache.sling.feature.Feature feature : features) {
+            writeFeature(feature, outputFile, features.size() > 1 ? index : 0);
+            index++;
         }
     }
 
@@ -506,17 +499,6 @@ public class ProvisioningToFeature {
         }
     }
 
-    private static void writeApplication(final Application app, final String out) {
-        LOGGER.info("Writing application...");
-        final File file = new File(out);
-        try ( final FileWriter writer = new FileWriter(file)) {
-            ApplicationJSONWriter.write(writer, app);
-        } catch ( final IOException ioe) {
-            LOGGER.error("Unable to write application to {} : {}", out, ioe.getMessage(), ioe);
-            System.exit(1);
-        }
-    }
-
     private static void writeFeature(final org.apache.sling.feature.Feature f, String out, final int index) {
         if ( index > 0 ) {
             final int lastDot = out.lastIndexOf('.');
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 9f042fd..30cb7b1 100644
--- a/src/test/java/org/apache/sling/feature/modelconverter/ModelConverterTest.java
+++ b/src/test/java/org/apache/sling/feature/modelconverter/ModelConverterTest.java
@@ -25,7 +25,6 @@ import org.apache.sling.feature.io.ArtifactHandler;
 import org.apache.sling.feature.io.ArtifactManager;
 import org.apache.sling.feature.io.ArtifactManagerConfig;
 import org.apache.sling.feature.io.IOUtils;
-import org.apache.sling.feature.io.json.FeatureJSONReader.SubstituteVariables;
 import org.apache.sling.provisioning.model.Artifact;
 import org.apache.sling.provisioning.model.ArtifactGroup;
 import org.apache.sling.provisioning.model.Configuration;
@@ -203,7 +202,7 @@ public class ModelConverterTest {
                 if (url.endsWith("simple_inherits.json")) {
                     return new ArtifactHandler(url, new File(url));
                 } else if ("mvn:generated/simple/1.0.0".equals(url)) {
-                    return new ArtifactHandler(url, new File(getClass().getResource("/simple2.json").toURI()));
+                    return new ArtifactHandler(url, new File(getClass().getResource("/simple.json").toURI()));
                 }
                 return null;
             }
@@ -253,8 +252,8 @@ public class ModelConverterTest {
         File outFile = files.get(0);
 
         String expectedFile = new File(getClass().getResource(expectedJSON).toURI()).getAbsolutePath();
-        org.apache.sling.feature.Feature expected = IOUtils.getFeature(expectedFile, artifactManager, SubstituteVariables.NONE);
-        org.apache.sling.feature.Feature actual = IOUtils.getFeature(outFile.getAbsolutePath(), artifactManager, SubstituteVariables.NONE);
+        org.apache.sling.feature.Feature expected = IOUtils.getFeature(expectedFile, artifactManager);
+        org.apache.sling.feature.Feature actual = IOUtils.getFeature(outFile.getAbsolutePath(), artifactManager);
         assertFeaturesEqual(expected, actual);
     }
 
@@ -351,8 +350,8 @@ public class ModelConverterTest {
         File outFile = files.get(0);
 
         String expectedFile = new File(getClass().getResource(expectedJSON).toURI()).getAbsolutePath();
-        org.apache.sling.feature.Feature expected = IOUtils.getFeature(expectedFile, artifactManager, SubstituteVariables.NONE);
-        org.apache.sling.feature.Feature actual = IOUtils.getFeature(outFile.getAbsolutePath(), artifactManager, SubstituteVariables.NONE);
+        org.apache.sling.feature.Feature expected = IOUtils.getFeature(expectedFile, artifactManager);
+        org.apache.sling.feature.Feature actual = IOUtils.getFeature(outFile.getAbsolutePath(), artifactManager);
         assertFeaturesEqual(expected, actual);
     }
 
diff --git a/src/test/resources/simple_inherits.json b/src/test/resources/simple_inherits.json
index 02c4e20..d9d02e9 100644
--- a/src/test/resources/simple_inherits.json
+++ b/src/test/resources/simple_inherits.json
@@ -1,10 +1,9 @@
 {
   "id":"generated:simple-inherits:1.0.0",
-  "includes": [
-       {
-           "id": "generated:simple:1.0.0"
-       }
-   ],
+  "include":
+  {
+      "id": "generated:simple:1.0.0"
+  },
   "bundles":[
       "org.apache.sling/org.apache.sling.commons.log/5.1.0"
   ]