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

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


The following commit(s) were added to refs/heads/master by this push:
     new ac2e379  SLING-9041 - adjusting regexp for named capturing groups for 
runmode … (#25)
ac2e379 is described below

commit ac2e379b57e5a8907665c4f6a110a1490719fc19
Author: Dominik Süß <[email protected]>
AuthorDate: Thu Jan 30 18:01:13 2020 +0100

    SLING-9041 - adjusting regexp for named capturing groups for runmode … (#25)
    
    * SLING-9041 - adjusting regexp for named capturing groups for runmode and 
pid and adjusting the matching logic to be used for pid detection as well.
    
    * SLING-9041 - adding testpermutations with .config.xml varations
---
 .../AbstractConfigurationEntryHandler.java         | 84 +++++++++++-----------
 .../handlers/ConfigurationEntryHandlerTest.java    |  4 ++
 ...ermapping.impl.ServiceUserMapperImpl.config.xml | 21 ++++++
 ...ing.impl.ServiceUserMapperImpl.empty.config.xml | 19 +++++
 4 files changed, 87 insertions(+), 41 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractConfigurationEntryHandler.java
 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractConfigurationEntryHandler.java
index 59413cd..5cb874c 100644
--- 
a/src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractConfigurationEntryHandler.java
+++ 
b/src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractConfigurationEntryHandler.java
@@ -29,45 +29,59 @@ abstract class AbstractConfigurationEntryHandler extends 
AbstractRegexEntryHandl
     private static final String REPOINIT_PID = 
"org.apache.sling.jcr.repoinit.RepositoryInitializer";
 
     public AbstractConfigurationEntryHandler(String extension) {
-        super("/jcr_root/(?:apps|libs)/.+/config(\\.([^/]+))?/.+\\." + 
extension);
+        
super("/jcr_root/(?:apps|libs)/.+/config(\\.(?<runmode>[^/]+))?/(?<pid>.*)\\." 
+ extension);
     }
 
     @Override
     public final void handle(String path, Archive archive, Entry entry, 
ContentPackage2FeatureModelConverter converter) throws Exception {
-        String pid = entry.getName().substring(0, 
entry.getName().lastIndexOf('.'));
-
-        String factoryPid = null;
-        String id;
-        int n = pid.indexOf('~');
-        if (n == -1) {
-            n = pid.indexOf('-');
-        }
-        if (n > 0) {
-            factoryPid = pid.substring(0, n);
-            id = factoryPid.concat("~").concat(pid.substring(n + 1));
-        } else {
-            id = pid;
-        }
-
-        logger.info("Processing configuration '{}'.", id);
-
-        Dictionary<String, Object> configurationProperties;
-        try (InputStream input = archive.openInputStream(entry)) {
-            configurationProperties = parseConfiguration(id, input);
-        }
-
-        if (configurationProperties == null) {
-            logger.info("{} entry does not contain a valid OSGi configuration, 
treating it as a regular resource", path);
-            converter.getMainPackageAssembler().addEntry(path, archive, entry);
-            return;
-        }
 
         Matcher matcher = getPattern().matcher(path);
+        
         String runMode = null;
         // we are pretty sure it matches, here
         if (matcher.matches()) {
+            
+            String pid = matcher.group("pid");
+    
+            String factoryPid = null;
+            String id;
+            int n = pid.indexOf('~');
+            if (n == -1) {
+                n = pid.indexOf('-');
+            }
+            if (n > 0) {
+                factoryPid = pid.substring(0, n);
+                id = factoryPid.concat("~").concat(pid.substring(n + 1));
+            } else {
+                id = pid;
+            }
+    
+            logger.info("Processing configuration '{}'.", id);
+    
+            Dictionary<String, Object> configurationProperties;
+            try (InputStream input = archive.openInputStream(entry)) {
+                configurationProperties = parseConfiguration(id, input);
+            }
+    
+            if (configurationProperties == null) {
+                logger.info("{} entry does not contain a valid OSGi 
configuration, treating it as a regular resource", path);
+                converter.getMainPackageAssembler().addEntry(path, archive, 
entry);
+                return;
+            }
             // there is a specified RunMode
-            runMode = matcher.group(2);
+            runMode = matcher.group("runmode");
+            
+            if (REPOINIT_PID.equals(factoryPid)) {
+                String[] scripts = (String[]) 
configurationProperties.get("scripts");
+                if (scripts != null) {
+                    String text = String.join("\n", scripts);
+                    
converter.getFeaturesManager().addOrAppendRepoInitExtension(text, runMode);
+                } else {
+                    // any repoinit configuration with empty scripts may be 
igored - filereferences are not supported at that point
+                }
+            } else {
+                converter.getFeaturesManager().addConfiguration(runMode, id, 
configurationProperties);
+            }
         } else {
             throw new IllegalStateException("Something went terribly wrong: 
pattern '"
                                             + getPattern().pattern()
@@ -75,18 +89,6 @@ abstract class AbstractConfigurationEntryHandler extends 
AbstractRegexEntryHandl
                                             + path
                                             + "' but it does not, currently");
         }
-        
-        if (REPOINIT_PID.equals(factoryPid)) {
-            String[] scripts = (String[]) 
configurationProperties.get("scripts");
-            if (scripts != null) {
-                String text = String.join("\n", scripts);
-                
converter.getFeaturesManager().addOrAppendRepoInitExtension(text, runMode);
-            } else {
-                // any repoinit configuration with empty scripts may be igored 
- filereferences are not supported at that point
-            }
-        } else {
-            converter.getFeaturesManager().addConfiguration(runMode, id, 
configurationProperties);
-        }
     }
 
     protected abstract Dictionary<String, Object> parseConfiguration(String 
name, InputStream input) throws Exception;
diff --git 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigurationEntryHandlerTest.java
 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigurationEntryHandlerTest.java
index f71cc2d..7351f22 100644
--- 
a/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigurationEntryHandlerTest.java
+++ 
b/src/test/java/org/apache/sling/feature/cpconverter/handlers/ConfigurationEntryHandlerTest.java
@@ -143,6 +143,10 @@ public class ConfigurationEntryHandlerTest {
             { path + EXPECTED_PID + ".empty.xml", 1, new 
XmlConfigurationEntryHandler(), null },
             { path + EXPECTED_PID + ".xml", 1, new 
XmlConfigurationEntryHandler(), null },
 
+            { path + EXPECTED_PID + ".empty.config.xml", 1, new 
XmlConfigurationEntryHandler(), null },
+            { path + EXPECTED_PID + ".config.xml", 1, new 
XmlConfigurationEntryHandler(), null },
+
+            
             { path + EXPECTED_PID + ".empty.xml.cfg", 1, new 
PropertiesConfigurationEntryHandler(), null },
             { path + EXPECTED_PID + ".xml.cfg", 1, new 
PropertiesConfigurationEntryHandler(), null },
 
diff --git 
a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/apps/asd/config/org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.config.xml
 
b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/apps/asd/config/org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.config.xml
new file mode 100644
index 0000000..f23afc9
--- /dev/null
+++ 
b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/apps/asd/config/org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.config.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with this
+ work for additional information regarding copyright ownership. The ASF
+ licenses this file to You under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and limitations under
+ the License.
+-->
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"; 
xmlns:jcr="http://www.jcp.org/jcr/1.0";
+    jcr:primaryType="sling:OsgiConfig"
+    user.default="admin"
+    
user.mapping="[com.adobe.acs.acs-aem-samples-bundle=admin,com.adobe.acs.acs-aem-samples-bundle:sample-service=oauthservice]"/>
diff --git 
a/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/apps/asd/config/org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.empty.config.xml
 
b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/apps/asd/config/org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.empty.config.xml
new file mode 100644
index 0000000..6211b85
--- /dev/null
+++ 
b/src/test/resources/org/apache/sling/feature/cpconverter/handlers/jcr_root/apps/asd/config/org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.empty.config.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with this
+ work for additional information regarding copyright ownership. The ASF
+ licenses this file to You under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ License for the specific language governing permissions and limitations under
+ the License.
+-->
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0"; 
xmlns:jcr="http://www.jcp.org/jcr/1.0";
+    jcr:primaryType="sling:OsgiConfig"/>

Reply via email to