You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by si...@apache.org on 2019/03/03 23:22:40 UTC

[sling-whiteboard] branch master updated: [cp2fm] added sub-packages support, handled *.config files

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

simonetripodi 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 a89db2f  [cp2fm] added sub-packages support, handled *.config files
a89db2f is described below

commit a89db2fee0969a26cde5e31836c2edc3b886d084
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Mon Mar 4 00:22:29 2019 +0100

    [cp2fm] added sub-packages support, handled *.config files
---
 content-package-2-feature-model/pom.xml            | 12 +++++++-
 .../ContentPackage2FeatureModelConverter.java      | 16 ++++++++---
 ...Handler.java => ConfigurationEntryHandler.java} | 33 +++++++++++++++++++---
 .../cp2fm/handlers/ContentPackageEntryHandler.java |  6 +++-
 .../org.apache.sling.cp2fm.spi.EntryHandler        |  1 +
 5 files changed, 58 insertions(+), 10 deletions(-)

diff --git a/content-package-2-feature-model/pom.xml b/content-package-2-feature-model/pom.xml
index 842e796..6c2f643 100644
--- a/content-package-2-feature-model/pom.xml
+++ b/content-package-2-feature-model/pom.xml
@@ -84,7 +84,7 @@
     <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
-      <version>1.3.2</version>
+      <version>2.6</version>
       <scope>provided</scope>
     </dependency>
 
@@ -144,6 +144,16 @@
       <artifactId>osgi.core</artifactId>
       <scope>provided</scope>
     </dependency>
+
+    <!--
+     | Handle .config files
+    -->
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.configadmin</artifactId>
+      <version>1.9.12</version>
+      <scope>provided</scope>
+    </dependency>
   </dependencies>
 
   <build>
diff --git a/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverter.java b/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverter.java
index 5f846b3..ec4354a 100644
--- a/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverter.java
+++ b/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/ContentPackage2FeatureModelConverter.java
@@ -164,7 +164,7 @@ public final class ContentPackage2FeatureModelConverter {
         }
     }
 
-    private void process(Archive archive) throws IOException {
+    public void process(Archive archive) throws IOException {
         try {
             archive.open(strictValidation);
 
@@ -185,8 +185,11 @@ public final class ContentPackage2FeatureModelConverter {
         }
 
         VaultInputSource inputSource = archive.getInputSource(entry);
-        String sourceSystemId = inputSource.getSystemId();
-        logger.info("Found {} entry", sourceSystemId);
+        String id = inputSource.getSystemId();
+
+        if (id == null || id.isEmpty()) {
+            id = entry.getName();
+        }
 
         boolean found = false;
 
@@ -194,9 +197,14 @@ public final class ContentPackage2FeatureModelConverter {
         dance : while (entryHandlersIterator.hasNext()) {
             EntryHandler entryHandler = entryHandlersIterator.next();
 
-            if (entryHandler.matches(sourceSystemId)) {
+            if (entryHandler.matches(id)) {
+                logger.info("Processing entry {}...", id);
+
                 found = true;
                 entryHandler.handle(archive, entry, this);
+
+                logger.info("Entry {} successfully processed.", id);
+
                 break dance;
             }
         }
diff --git a/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/ContentPackageEntryHandler.java b/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/ConfigurationEntryHandler.java
similarity index 51%
copy from content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/ContentPackageEntryHandler.java
copy to content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/ConfigurationEntryHandler.java
index bef0787..7582414 100644
--- a/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/ContentPackageEntryHandler.java
+++ b/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/ConfigurationEntryHandler.java
@@ -17,20 +17,45 @@
 package org.apache.sling.cp2fm.handlers;
 
 import java.io.IOException;
+import java.io.InputStream;
+import java.util.Dictionary;
+import java.util.Enumeration;
 
+import org.apache.felix.cm.file.ConfigurationHandler;
 import org.apache.jackrabbit.vault.fs.io.Archive;
 import org.apache.jackrabbit.vault.fs.io.Archive.Entry;
 import org.apache.sling.cp2fm.ContentPackage2FeatureModelConverter;
+import org.apache.sling.feature.Configuration;
 
-public final class ContentPackageEntryHandler extends AbstractRegexEntryHandler {
+public final class ConfigurationEntryHandler extends AbstractRegexEntryHandler {
 
-    public ContentPackageEntryHandler() {
-        super("jcr_root/etc/packages/.+\\.zip");
+    public ConfigurationEntryHandler() {
+        super(".+\\.config");
     }
 
     @Override
+    @SuppressWarnings("unchecked")
     public void handle(Archive archive, Entry entry, ContentPackage2FeatureModelConverter converter) throws IOException {
-        logger.info("Processing sub-content package {}...", entry.getName());
+        String name = entry.getName().substring(0, entry.getName().lastIndexOf('.'));
+
+        logger.info("Processing configuration '{}'.", name);
+
+        Configuration configuration = new Configuration(name);
+
+        Dictionary<String, Object> parsedConfiguration;
+
+        try (InputStream input = archive.openInputStream(entry)) {
+            parsedConfiguration = ConfigurationHandler.read(input);
+        }
+
+        Enumeration<String> keys = parsedConfiguration.keys();
+        while (keys.hasMoreElements()) {
+            String key = keys.nextElement();
+            Object value = parsedConfiguration.get(key);
+            configuration.getProperties().put(key, value);
+        }
+
+        converter.getTargetFeature().getConfigurations().add(configuration);
     }
 
 }
diff --git a/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/ContentPackageEntryHandler.java b/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/ContentPackageEntryHandler.java
index bef0787..0280a67 100644
--- a/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/ContentPackageEntryHandler.java
+++ b/content-package-2-feature-model/src/main/java/org/apache/sling/cp2fm/handlers/ContentPackageEntryHandler.java
@@ -20,6 +20,7 @@ import java.io.IOException;
 
 import org.apache.jackrabbit.vault.fs.io.Archive;
 import org.apache.jackrabbit.vault.fs.io.Archive.Entry;
+import org.apache.jackrabbit.vault.fs.io.ZipStreamArchive;
 import org.apache.sling.cp2fm.ContentPackage2FeatureModelConverter;
 
 public final class ContentPackageEntryHandler extends AbstractRegexEntryHandler {
@@ -30,7 +31,10 @@ public final class ContentPackageEntryHandler extends AbstractRegexEntryHandler
 
     @Override
     public void handle(Archive archive, Entry entry, ContentPackage2FeatureModelConverter converter) throws IOException {
-        logger.info("Processing sub-content package {}...", entry.getName());
+        logger.info("Processing sub-content package '{}'...", entry.getName());
+
+        Archive subArchive = new ZipStreamArchive(archive.openInputStream(entry));
+        converter.process(subArchive);
     }
 
 }
diff --git a/content-package-2-feature-model/src/main/resources/META-INF/services/org.apache.sling.cp2fm.spi.EntryHandler b/content-package-2-feature-model/src/main/resources/META-INF/services/org.apache.sling.cp2fm.spi.EntryHandler
index e112b9f..b441426 100644
--- a/content-package-2-feature-model/src/main/resources/META-INF/services/org.apache.sling.cp2fm.spi.EntryHandler
+++ b/content-package-2-feature-model/src/main/resources/META-INF/services/org.apache.sling.cp2fm.spi.EntryHandler
@@ -1,2 +1,3 @@
 org.apache.sling.cp2fm.handlers.BundleEntryHandler
+org.apache.sling.cp2fm.handlers.ConfigurationEntryHandler
 org.apache.sling.cp2fm.handlers.ContentPackageEntryHandler