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/03 14:23:19 UTC

[sling-whiteboard] branch master updated: Handle runmodes for configurations that have ':' in their name

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-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 28176d8  Handle runmodes for configurations that have ':' in their name
28176d8 is described below

commit 28176d8649f11a16366d963eb8f9bc8316225236
Author: David Bosschaert <da...@gmail.com>
AuthorDate: Tue Apr 3 15:22:47 2018 +0100

    Handle runmodes for configurations that have ':' in their name
---
 .../modelconverter/impl/FeatureToProvisioning.java |  2 +-
 .../modelconverter/impl/ProvisioningToFeature.java | 34 ++++++++--------------
 .../modelconverter/impl/ModelConverterTest.java    | 22 ++++++++++----
 .../src/test/resources/launchpad.json              |  4 +--
 4 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/featuremodel/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/FeatureToProvisioning.java b/featuremodel/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/FeatureToProvisioning.java
index dd6d830..9327df6 100644
--- a/featuremodel/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/FeatureToProvisioning.java
+++ b/featuremodel/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/FeatureToProvisioning.java
@@ -157,7 +157,7 @@ public class FeatureToProvisioning {
                 c = new Configuration(cfg.getName(), cfg.getFactoryPid());
             } else {
                 String pid = cfg.getPid();
-                pid = pid.replaceAll("[.][.](\\S+)", ":$1");
+                pid = pid.replaceAll("[.][.](\\w+)", ":$1");
                 int rmIdx = pid.indexOf(".runmodes.");
                 if (rmIdx > 0) {
                     String rm = pid.substring(rmIdx + ".runmodes.".length());
diff --git a/featuremodel/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/ProvisioningToFeature.java b/featuremodel/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/ProvisioningToFeature.java
index 6af4aa3..5f87e1f 100644
--- a/featuremodel/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/ProvisioningToFeature.java
+++ b/featuremodel/feature-modelconverter/src/main/java/org/apache/sling/feature/modelconverter/impl/ProvisioningToFeature.java
@@ -427,32 +427,22 @@ public class ProvisioningToFeature {
             }
 
             for(final Configuration cfg : runMode.getConfigurations()) {
-                final org.apache.sling.feature.Configuration newCfg;
-                if ( cfg.getFactoryPid() != null ) {
-                    String pid = cfg.getPid();
-                    if (pid.startsWith(":")) {
-                        // The configurator doesn't accept colons ':' in it's keys, so replace these
-                        pid = ".." + pid.substring(1);
-                    }
+                String pid = cfg.getPid();
+                if (pid.startsWith(":")) {
+                    // The configurator doesn't accept colons ':' in it's keys, so replace these
+                    pid = ".." + pid.substring(1);
+                }
 
-                    String[] runModeNames = runMode.getNames();
-                    if (runModeNames != null) {
-                        pid = pid + ".runmodes." + String.join(".", runModeNames);
-                    }
+                final String[] runModeNames = runMode.getNames();
+                if (runModeNames != null) {
+                    pid = pid + ".runmodes." + String.join(".", runModeNames);
+                    pid = pid.replaceAll("[:]", "..");
+                }
 
+                final org.apache.sling.feature.Configuration newCfg;
+                if ( cfg.getFactoryPid() != null ) {
                     newCfg = new org.apache.sling.feature.Configuration(cfg.getFactoryPid(), pid);
                 } else {
-                    String pid = cfg.getPid();
-                    if (pid.startsWith(":")) {
-                        // The configurator doesn't accept colons ':' in it's keys, so replace these
-                        pid = ".." + pid.substring(1);
-                    }
-
-                    String[] runModeNames = runMode.getNames();
-                    if (runModeNames != null) {
-                        pid = pid + ".runmodes." + String.join(".", runModeNames);
-                    }
-
                     newCfg = new org.apache.sling.feature.Configuration(pid);
                 }
                 final Enumeration<String> keys = cfg.getProperties().keys();
diff --git a/featuremodel/feature-modelconverter/src/test/java/org/apache/sling/feature/modelconverter/impl/ModelConverterTest.java b/featuremodel/feature-modelconverter/src/test/java/org/apache/sling/feature/modelconverter/impl/ModelConverterTest.java
index 249d9dc..72e0c08 100644
--- a/featuremodel/feature-modelconverter/src/test/java/org/apache/sling/feature/modelconverter/impl/ModelConverterTest.java
+++ b/featuremodel/feature-modelconverter/src/test/java/org/apache/sling/feature/modelconverter/impl/ModelConverterTest.java
@@ -48,6 +48,7 @@ import java.io.IOException;
 import java.net.URISyntaxException;
 import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -70,18 +71,26 @@ public class ModelConverterTest {
 
     @Before
     public void setup() throws Exception {
-        tempDir = Files.createTempDirectory(getClass().getSimpleName());
+        String tmpDir = System.getProperty("test.prov.files.tempdir");
+        if (tmpDir != null) {
+            tempDir = Paths.get(tmpDir);
+            System.out.println("*** Using directory for generated files: " + tempDir);
+        } else {
+            tempDir = Files.createTempDirectory(getClass().getSimpleName());
+        }
         artifactManager = ArtifactManager.getArtifactManager(
                 new ArtifactManagerConfig());
     }
 
     @After
     public void tearDown() throws Exception {
-        // Delete the temp dir again
-        Files.walk(tempDir)
-            .sorted(Comparator.reverseOrder())
-            .map(Path::toFile)
-            .forEach(File::delete);
+        if(System.getProperty("test.prov.files.tempdir") == null) {
+            // Delete the temp dir again
+            Files.walk(tempDir)
+                .sorted(Comparator.reverseOrder())
+                .map(Path::toFile)
+                .forEach(File::delete);
+        }
     }
 
     @Test
@@ -151,6 +160,7 @@ public class ModelConverterTest {
     }
 
     public void testConvertFromProvModelRoundTrip(File orgProvModel) throws Exception {
+        System.out.println("*** Roundtrip converting: " + orgProvModel.getName());
         String genJSONPrefix = orgProvModel.getName() + ".json";
         String genTxtPrefix = orgProvModel.getName() + ".txt";
         String genSuffix = ".generated";
diff --git a/featuremodel/feature-modelconverter/src/test/resources/launchpad.json b/featuremodel/feature-modelconverter/src/test/resources/launchpad.json
index 0dd9318..2fa94b3 100644
--- a/featuremodel/feature-modelconverter/src/test/resources/launchpad.json
+++ b/featuremodel/feature-modelconverter/src/test/resources/launchpad.json
@@ -18,10 +18,10 @@
     "..bootstrap":{
       "..bootstrap":"uninstall com.google.guava 15.0.0\n"
     },
-    "..bootstrap.runmodes.:standalone":{
+    "..bootstrap.runmodes...standalone":{
       "..bootstrap":"uninstall org.apache.felix.http.bridge\nuninstall org.apache.felix.http.api\n"
     },
-    "org.apache.testing.ConfigPid.factory-configuration.runmodes.:standalone":{
+    "org.apache.testing.ConfigPid.factory-configuration.runmodes...standalone":{
       "key1":"val1"
     }
   }

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