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/07/03 15:44:35 UTC

[sling-org-apache-sling-feature-cpconverter] branch master updated: SLING-8529 - Avoid flattening of subpackages during convertion in featuremodel

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-org-apache-sling-feature-cpconverter.git


The following commit(s) were added to refs/heads/master by this push:
     new 3545d26  SLING-8529 - Avoid flattening of subpackages during convertion in featuremodel
3545d26 is described below

commit 3545d26c4020c2015d0218316316a6251f157b17
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Wed Jul 3 17:44:28 2019 +0200

    SLING-8529 - Avoid flattening of subpackages during convertion in
    featuremodel
    
    fixed broken paths
---
 .../cpconverter/vltpkg/VaultPackageAssembler.java  |  6 +-
 .../ContentPackage2FeatureModelConverterTest.java  | 95 ++++++++++++++--------
 2 files changed, 62 insertions(+), 39 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/cpconverter/vltpkg/VaultPackageAssembler.java b/src/main/java/org/apache/sling/feature/cpconverter/vltpkg/VaultPackageAssembler.java
index 803c420..51d2107 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/vltpkg/VaultPackageAssembler.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/vltpkg/VaultPackageAssembler.java
@@ -46,8 +46,8 @@ import org.apache.jackrabbit.vault.packaging.VaultPackage;
 import org.apache.sling.feature.cpconverter.ContentPackage2FeatureModelConverter;
 import org.apache.sling.feature.cpconverter.handlers.EntryHandler;
 import org.codehaus.plexus.archiver.Archiver;
-import org.codehaus.plexus.archiver.jar.JarArchiver;
 import org.codehaus.plexus.archiver.util.DefaultFileSet;
+import org.codehaus.plexus.archiver.zip.ZipArchiver;
 
 public class VaultPackageAssembler implements EntryHandler {
 
@@ -201,13 +201,13 @@ public class VaultPackageAssembler implements EntryHandler {
 
         for (String resource : INCLUDE_RESOURCES) {
             try (InputStream input = getClass().getResourceAsStream(resource)) {
-                addEntry(ROOT_DIR + resource, input);
+                addEntry(ROOT_DIR + '/' + resource, input);
             }
         }
 
         // create the target archiver
 
-        Archiver archiver = new JarArchiver();
+        Archiver archiver = new ZipArchiver();
         archiver.setIncludeEmptyDirs(true);
 
         String destFileName = storingDirectory.getName().substring(0, storingDirectory.getName().lastIndexOf('-'));
diff --git a/src/test/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverterTest.java b/src/test/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverterTest.java
index ec076ce..617a6c2 100644
--- a/src/test/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverterTest.java
+++ b/src/test/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverterTest.java
@@ -124,7 +124,10 @@ public class ContentPackage2FeatureModelConverterTest {
                           "asd.sample:asd.retail.all:slingosgifeature:0.0.1",
                           Arrays.asList("org.apache.felix:org.apache.felix.framework:6.0.1"),
                           Arrays.asList("org.apache.sling.commons.log.LogManager.factory.config~asd-retail"),
-                          Arrays.asList("asd.sample:asd.retail.all:zip:cp2fm-converted:0.0.1"));
+                          Arrays.asList("asd.sample:asd.retail.apps:zip:cp2fm-converted:0.0.1",
+                                        "asd.sample:Asd.Retail.ui.content:zip:cp2fm-converted:0.0.1",
+                                        "asd:Asd.Retail.config:zip:cp2fm-converted:0.0.1",
+                                        "asd.sample:asd.retail.all:zip:cp2fm-converted:0.0.1"));
         verifyFeatureFile(outputDirectory,
                           "asd.retail.all-author.json",
                           "asd.sample:asd.retail.all:slingosgifeature:author:0.0.1",
@@ -152,23 +155,43 @@ public class ContentPackage2FeatureModelConverterTest {
         assertEquals("asd.retail.all-author.json", runModes.getProperty("author"));
         assertEquals("asd.retail.all-publish.json", runModes.getProperty("publish"));
 
-        ZipFile zipFile = new ZipFile(new File(outputDirectory, "asd/sample/asd.retail.all/0.0.1/asd.retail.all-0.0.1-cp2fm-converted.zip"));
-        for (String expectedEntry : new String[] {
-                "jcr_root/content/asd/.content.xml",
-                "jcr_root/content/asd/resources.xml",
-                "jcr_root/apps/.content.xml",
-                "META-INF/vault/properties.xml",
-                "META-INF/vault/config.xml",
-                "META-INF/vault/settings.xml",
-                "META-INF/vault/filter.xml",
-                "META-INF/vault/definition/.content.xml",
-                "jcr_root/etc/packages/asd/test-bundles.zip",
-                "jcr_root/etc/packages/asd/test-configurations.zip",
-                "jcr_root/etc/packages/asd/test-content.zip",
-                }) {
-            assertNotNull(zipFile.getEntry(expectedEntry));
-        }
-        zipFile.close();
+        verifyContentPackage(new File(outputDirectory, "asd/Asd.Retail.config/0.0.1/Asd.Retail.config-0.0.1-cp2fm-converted.zip"),
+                             "META-INF/vault/settings.xml",
+                             "META-INF/vault/properties.xml",
+                             "META-INF/vault/config.xml",
+                             "META-INF/vault/filter.xml",
+                             "jcr_root/settings.xml",
+                             "jcr_root/config.xml",
+                             "jcr_root/definition/.content.xml",
+                             "jcr_root/apps/.content.xml");
+        verifyContentPackage(new File(outputDirectory, "asd/sample/Asd.Retail.ui.content/0.0.1/Asd.Retail.ui.content-0.0.1-cp2fm-converted.zip"),
+                             "META-INF/vault/settings.xml",
+                             "META-INF/vault/properties.xml",
+                             "META-INF/vault/config.xml",
+                             "META-INF/vault/filter.xml",
+                             "META-INF/vault/filter-plugin-generated.xml",
+                             "jcr_root/settings.xml",
+                             "jcr_root/content/asd/.content.xml",
+                             "jcr_root/content/asd/resources.xml",
+                             "jcr_root/config.xml",
+                             "jcr_root/definition/.content.xml");
+        verifyContentPackage(new File(outputDirectory, "asd/sample/asd.retail.apps/0.0.1/asd.retail.apps-0.0.1-cp2fm-converted.zip"),
+                             "META-INF/vault/settings.xml",
+                             "META-INF/vault/properties.xml",
+                             "META-INF/vault/config.xml",
+                             "META-INF/vault/filter.xml",
+                             "META-INF/vault/filter-plugin-generated.xml",
+                             "jcr_root/settings.xml",
+                             "jcr_root/config.xml",
+                             "jcr_root/definition/.content.xml");
+        verifyContentPackage(new File(outputDirectory, "asd/sample/asd.retail.all/0.0.1/asd.retail.all-0.0.1-cp2fm-converted.zip"),
+                             "META-INF/vault/settings.xml",
+                             "META-INF/vault/properties.xml",
+                             "META-INF/vault/config.xml",
+                             "META-INF/vault/filter.xml",
+                             "jcr_root/settings.xml",
+                             "jcr_root/config.xml",
+                             "jcr_root/definition/.content.xml");
     }
 
     private void verifyFeatureFile(File outputDirectory,
@@ -229,6 +252,15 @@ public class ContentPackage2FeatureModelConverterTest {
         assertTrue("POM file " + pomFile + " does not exist", pomFile.exists());
     }
 
+    private void verifyContentPackage(File contentPackage, String...expectedEntries) throws Exception {
+        try (ZipFile zipFile = new ZipFile(contentPackage)) {
+            for (String expectedEntry : expectedEntries) {
+                assertNotNull("Expected entry not found: " + expectedEntry + " in file " + contentPackage,
+                              zipFile.getEntry(expectedEntry));
+            }
+        }
+    }
+
     @Test(expected = IllegalArgumentException.class)
     public void verifyFilteringOutUndesiredPackages() throws Exception {
         RegexBasedResourceFilter resourceFilter = new RegexBasedResourceFilter();
@@ -286,7 +318,10 @@ public class ContentPackage2FeatureModelConverterTest {
                           "${project.groupId}:${project.artifactId}:slingosgifeature:asd.test.all-1.0.0:${project.version}",
                           Arrays.asList("org.apache.felix:org.apache.felix.framework:6.0.1"),
                           Arrays.asList("org.apache.sling.commons.log.LogManager.factory.config~asd-retail"),
-                          Arrays.asList("asd.sample:asd.retail.all:zip:cp2fm-converted:0.0.1"));
+                          Arrays.asList("asd.sample:asd.retail.apps:zip:cp2fm-converted:0.0.1",
+                                        "asd.sample:Asd.Retail.ui.content:zip:cp2fm-converted:0.0.1",
+                                        "asd:Asd.Retail.config:zip:cp2fm-converted:0.0.1",
+                                        "asd.sample:asd.retail.all:zip:cp2fm-converted:0.0.1"));
         verifyFeatureFile(outputDirectory,
                           "asd.retail.all-author.json",
                           "${project.groupId}:${project.artifactId}:slingosgifeature:asd.test.all-1.0.0-author:${project.version}",
@@ -300,23 +335,11 @@ public class ContentPackage2FeatureModelConverterTest {
                           Arrays.asList("org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended~asd-retail"),
                           Collections.emptyList());
 
-        ZipFile zipFile = new ZipFile(new File(outputDirectory, "asd/sample/asd.retail.all/0.0.1/asd.retail.all-0.0.1-cp2fm-converted.zip"));
-        for (String expectedEntry : new String[] {
-                "jcr_root/content/asd/.content.xml",
-                "jcr_root/content/asd/resources.xml",
-                "jcr_root/apps/.content.xml",
-                "META-INF/vault/properties.xml",
-                "META-INF/vault/config.xml",
-                "META-INF/vault/settings.xml",
-                "META-INF/vault/filter.xml",
-                "META-INF/vault/definition/.content.xml",
-                "jcr_root/etc/packages/asd/test-bundles.zip",
-                "jcr_root/etc/packages/asd/test-configurations.zip",
-                "jcr_root/etc/packages/asd/test-content.zip",
-                }) {
-            assertNotNull(zipFile.getEntry(expectedEntry));
-        }
-        zipFile.close();
+        verifyContentPackage(new File(outputDirectory, "asd/sample/asd.retail.all/0.0.1/asd.retail.all-0.0.1-cp2fm-converted.zip"),
+                             "META-INF/vault/properties.xml",
+                             "META-INF/vault/config.xml",
+                             "META-INF/vault/settings.xml",
+                             "META-INF/vault/filter.xml");
     }
 
     @Test