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/04/27 10:01:36 UTC

[sling-org-apache-sling-feature-modelconverter] 18/40: Change how runmodes in configuration are handled in the feature model

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

commit f8d3703e0c8ee24bbbb909858febc3ff891731ca
Author: David Bosschaert <da...@gmail.com>
AuthorDate: Thu Mar 22 14:45:20 2018 +0000

    Change how runmodes in configuration are handled in the feature model
    
    With this commit, the runmodes can be specified with a configuration
    using the ".runmodes." property. The value is a comma-separated string.
---
 .../modelconverter/impl/FeatureToProvisioning.java | 14 ++---
 .../modelconverter/impl/ProvisioningToFeature.java | 19 +------
 .../modelconverter/impl/ModelConverterTest.java    | 64 ++++++----------------
 src/test/resources/oak.json                        | 24 ++++----
 4 files changed, 34 insertions(+), 87 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/modelconverter/impl/FeatureToProvisioning.java b/src/main/java/org/apache/sling/feature/modelconverter/impl/FeatureToProvisioning.java
index 28cdff9..aded77c 100644
--- a/src/main/java/org/apache/sling/feature/modelconverter/impl/FeatureToProvisioning.java
+++ b/src/main/java/org/apache/sling/feature/modelconverter/impl/FeatureToProvisioning.java
@@ -162,16 +162,10 @@ public class FeatureToProvisioning {
                 c.getProperties().put(key, cfg.getProperties().get(key));
             }
 
-            // Remove these if they got in
-            c.getProperties().remove(org.apache.sling.feature.Configuration.PROP_ARTIFACT);
-
-            // Check if the configuration has an associated runmode via the bundle that it belongs to
-            org.apache.sling.feature.Artifact bundle = configBundleMap.get(cfg);
-            String[] runModes;
-            if (bundle != null) {
-                runModes = getRunModes(bundle);
-            } else {
-                runModes = null;
+            String[] runModes = null;
+            Object rm = c.getProperties().remove(".runmodes.");
+            if (rm instanceof String) {
+                runModes = ((String) rm).split(",");
             }
             f.getOrCreateRunMode(runModes).getConfigurations().add(c);
         }
diff --git a/src/main/java/org/apache/sling/feature/modelconverter/impl/ProvisioningToFeature.java b/src/main/java/org/apache/sling/feature/modelconverter/impl/ProvisioningToFeature.java
index 5d0ac7c..d34d471 100644
--- a/src/main/java/org/apache/sling/feature/modelconverter/impl/ProvisioningToFeature.java
+++ b/src/main/java/org/apache/sling/feature/modelconverter/impl/ProvisioningToFeature.java
@@ -439,24 +439,7 @@ public class ProvisioningToFeature {
 
                 String[] runModeNames = runMode.getNames();
                 if (runModeNames != null) {
-                    // If this configuration is associated with a runmode other than null, attach it to a bundle
-                    // that has the same runmodes
-                    Artifact art = null;
-                    for (ArtifactGroup group : runMode.getArtifactGroups()) {
-                        if (art != null)
-                            break;
-
-                        for (Artifact artifact : group) {
-                            art = artifact;
-                            break;
-                        }
-                    }
-                    if (art == null) {
-                        throw new IllegalStateException("Should have at least one artifact in runmodes " +
-                                Arrays.toString(runModeNames) + " to attach configuration to");
-                    }
-
-                    newCfg.getProperties().put(org.apache.sling.feature.Configuration.PROP_ARTIFACT, art.toMvnUrl());
+                    newCfg.getProperties().put(".runmodes.", String.join(",", runModeNames));
                 }
 
                 configurations.add(newCfg);
diff --git a/src/test/java/org/apache/sling/feature/modelconverter/impl/ModelConverterTest.java b/src/test/java/org/apache/sling/feature/modelconverter/impl/ModelConverterTest.java
index 2c0567c..fb8b571 100644
--- a/src/test/java/org/apache/sling/feature/modelconverter/impl/ModelConverterTest.java
+++ b/src/test/java/org/apache/sling/feature/modelconverter/impl/ModelConverterTest.java
@@ -93,11 +93,6 @@ public class ModelConverterTest {
     }
 
     @Test
-    public void testBootRoundTrip() throws Exception {
-        testConvertFromProvModelRoundTrip("/boot.txt");
-    }
-
-    @Test
     public void testOakToProvModel() throws Exception {
         testConvertToProvisioningModel("/oak.json", "/oak.txt");
     }
@@ -108,11 +103,6 @@ public class ModelConverterTest {
     }
 
     @Test
-    public void testOakRoundTrip() throws Exception {
-        testConvertFromProvModelRoundTrip("/oak.txt");
-    }
-
-    @Test
     public void testRepoinitToProvModel() throws Exception {
         testConvertToProvisioningModel("/repoinit.json", "/repoinit.txt");
     }
@@ -123,20 +113,30 @@ public class ModelConverterTest {
     }
 
     @Test
-    public void testRepoinitRoundtrip() throws Exception {
-        testConvertFromProvModelRoundTrip("/repoinit.txt");
+    public void testProvModelRoundtripFolder() throws Exception {
+        String dir = System.getProperty("test.prov.files.dir");
+        File filesDir;
+        if (dir != null) {
+            filesDir = new File(dir);
+        } else {
+            filesDir = new File(getClass().getResource("/repoinit.txt").toURI()).
+                getParentFile();
+        }
+
+        for (File f : filesDir.listFiles((d, n) -> n.endsWith(".txt"))) {
+            testConvertFromProvModelRoundTrip(f);
+        }
     }
 
-    public void testConvertFromProvModelRoundTrip(String orgProvModel) throws Exception {
-        File inFile = new File(getClass().getResource(orgProvModel).toURI());
-        File outJSONFile = new File(tempDir.toFile(), orgProvModel + ".json.generated");
-        File outProvFile = new File(tempDir.toFile(), orgProvModel + ".txt.generated");
+    public void testConvertFromProvModelRoundTrip(File orgProvModel) throws Exception {
+        File outJSONFile = new File(tempDir.toFile(), orgProvModel.getName() + ".json.generated");
+        File outProvFile = new File(tempDir.toFile(), orgProvModel.getName() + ".txt.generated");
 
-        ProvisioningToFeature.convert(inFile, outJSONFile.getAbsolutePath());
+        ProvisioningToFeature.convert(orgProvModel, outJSONFile.getAbsolutePath());
         FeatureToProvisioning.convert(outJSONFile, outProvFile.getAbsolutePath(),
                 artifactManager);
 
-        Model expected = readProvisioningModel(inFile);
+        Model expected = readProvisioningModel(orgProvModel);
         Model actual = readProvisioningModel(outProvFile);
         assertModelsEqual(expected, actual);
     }
@@ -239,34 +239,6 @@ public class ModelConverterTest {
     }
 
     private void assertConfigProps(org.apache.sling.feature.Configuration expected, org.apache.sling.feature.Configuration actual, Bundles exBundles, Bundles acBundles) {
-        // If the configuration is associated with an artifact, it's considered equal
-        // if both artifacts have the same runmode (as the configuration is really
-        // associated with the runmode.
-        Object art = expected.getProperties().remove(org.apache.sling.feature.Configuration.PROP_ARTIFACT);
-        if (art instanceof String) {
-            String expectedArtifact = (String) art;
-            String actualArtifact = (String) actual.getProperties().remove(org.apache.sling.feature.Configuration.PROP_ARTIFACT);
-
-            String expectedRunmodes = null;
-            for(Iterator<org.apache.sling.feature.Artifact> it = exBundles.iterator(); it.hasNext(); ) {
-                org.apache.sling.feature.Artifact a = it.next();
-                if (a.getId().toMvnId().equals(expectedArtifact)) {
-                    expectedRunmodes = a.getMetadata().get("run-modes");
-                }
-            }
-
-            boolean found = false;
-            for(Iterator<org.apache.sling.feature.Artifact> it = acBundles.iterator(); it.hasNext(); ) {
-                org.apache.sling.feature.Artifact a = it.next();
-                if (a.getId().toMvnId().equals(actualArtifact)) {
-                    found = true;
-                    assertEquals(expectedRunmodes, a.getMetadata().get("run-modes"));
-                    break;
-                }
-            }
-            assertTrue(found);
-        }
-
         assertTrue("Configurations not equal: " + expected.getProperties() + " vs " + actual.getProperties(),
                 configPropsEqual(expected.getProperties(), actual.getProperties()));
     }
diff --git a/src/test/resources/oak.json b/src/test/resources/oak.json
index ab50c29..4ba64cb 100644
--- a/src/test/resources/oak.json
+++ b/src/test/resources/oak.json
@@ -33,23 +33,12 @@
         {
             "id": "org.apache.jackrabbit/oak-segment-tar/${oak.version}",
             "start-level": 15,
-            "run-modes": "oak_tar",
-            "configurations": {
-                "org.apache.jackrabbit.oak.segment.SegmentNodeStoreService": {
-                    "name": "Default NodeStore"
-                }
-            }
+            "run-modes": "oak_tar"
         },
         {
             "id": "org.mongodb/mongo-java-driver/3.4.1",
             "start-level": 15,
-            "run-modes": "oak_mongo",
-            "configurations": {
-                "org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService": {
-                    "mongouri": "mongodb://localhost:27017",
-                    "db": "sling"
-                }
-            }
+            "run-modes": "oak_mongo"
         },
         {
             "id": "com.h2database/h2-mvstore/1.4.196",
@@ -96,6 +85,15 @@
             "enabledActions": ["org.apache.jackrabbit.oak.spi.security.user.action.AccessControlAction"],
             "userPrivilegeNames": ["jcr:all"],
             "groupPrivilegeNames": ["jcr:read"]
+        },
+        "org.apache.jackrabbit.oak.segment.SegmentNodeStoreService": {
+            ".runmodes.": "oak_tar", 
+            "name": "Default NodeStore"
+        },
+        "org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService": {
+            ".runmodes.": "oak_mongo", 
+            "mongouri": "mongodb://localhost:27017",
+            "db": "sling"
         }
     }
 }

-- 
To stop receiving notification emails like this one, please contact
davidb@apache.org.