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

cziegeler pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-installer-factory-configuration.git


The following commit(s) were added to refs/heads/master by this push:
     new 56b518b  SLING-7787 : Support official JSON format for configurations
56b518b is described below

commit 56b518bd9156b8c2021941ab37314452bd7d924a
Author: Carsten Ziegeler <czieg...@adobe.com>
AuthorDate: Sat Aug 11 14:55:40 2018 +0200

    SLING-7787 : Support official JSON format for configurations
---
 .../configuration/impl/ConfigTaskCreator.java      | 36 ++++++++--------------
 1 file changed, 13 insertions(+), 23 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
 
b/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
index dd7d796..36e8067 100644
--- 
a/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
+++ 
b/src/main/java/org/apache/sling/installer/factories/configuration/impl/ConfigTaskCreator.java
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.installer.factories.configuration.impl;
 
+import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.List;
@@ -276,20 +277,17 @@ public class ConfigTaskCreator
     private TransformationResult[] checkConfiguration(final RegisteredResource 
resource) {
         final String lastIdPart = getResourceId(resource.getURL());
 
-        final String pid;
         // remove extension if known
-        if ( isConfigExtension(getExtension(lastIdPart)) ) {
-            final int lastDot = lastIdPart.lastIndexOf('.');
-            pid = lastIdPart.substring(0, lastDot);
-        } else {
-            pid = lastIdPart;
-        }
+        final String pid = removeConfigExtension(lastIdPart);
 
         // split pid and factory pid alias
         final Map<String, Object> attr = new HashMap<>();
         final String factoryPid;
         final String configPid;
-        int n = pid.indexOf('-');
+        int n = pid.indexOf('~');
+        if ( n == -1 ) {
+            n = pid.indexOf('-');
+        }
         if (n > 0) {
             configPid = pid.substring(n + 1);
             factoryPid = pid.substring(0, n);
@@ -340,22 +338,14 @@ public class ConfigTaskCreator
         this.latch = null;
     }
 
-    /**
-     * Compute the extension
-     */
-    private static String getExtension(final String url) {
-        final int pos = url.lastIndexOf('.');
-        return (pos < 0 ? "" : url.substring(pos+1));
-    }
-
-    private static boolean isConfigExtension(final String extension) {
-        if ( extension.equals("cfg")
-                || extension.equals("config")
-                || extension.equals("xml")
-                || extension.equals("properties")) {
-            return true;
+    private static final List<String> EXTENSIONS = Arrays.asList(".config", 
".properties", ".cfg", ".cfg.json");
+    private static String removeConfigExtension(final String id) {
+        for(final String ext : EXTENSIONS) {
+            if ( id.endsWith(ext) ) {
+                return id.substring(0, id.length() - ext.length());
+            }
         }
-        return false;
+        return id;
     }
 
     /**

Reply via email to