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/08/01 07:51:33 UTC

[sling-org-apache-sling-feature-cpconverter] branch SLING-8608 created (now c673c93)

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

simonetripodi pushed a change to branch SLING-8608
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-cpconverter.git.


      at c673c93  SLING-8608 - Fail the conversion if the resulting attached content-package is MIXED type

This branch includes the following new commits:

     new c673c93  SLING-8608 - Fail the conversion if the resulting attached content-package is MIXED type

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[sling-org-apache-sling-feature-cpconverter] 01/01: SLING-8608 - Fail the conversion if the resulting attached content-package is MIXED type

Posted by si...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit c673c939065975fcc8a4f397e045d6ebf0f5cfb8
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Thu Aug 1 09:51:19 2019 +0200

    SLING-8608 - Fail the conversion if the resulting attached
    content-package is MIXED type
    
    initial checkin
---
 .../ContentPackage2FeatureModelConverter.java      | 25 +++++++--
 .../vltpkg/DefaultPackagesEventsEmitter.java       | 37 +------------
 .../cpconverter/vltpkg/VaultPackageUtils.java      | 63 ++++++++++++++++++++++
 3 files changed, 86 insertions(+), 39 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java b/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
index ec874b3..8c84da4 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/ContentPackage2FeatureModelConverter.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sling.feature.cpconverter;
 
+import static org.apache.sling.feature.cpconverter.vltpkg.VaultPackageUtils.detectPackageType;
 import static java.util.Objects.requireNonNull;
 
 import java.io.File;
@@ -36,6 +37,7 @@ import org.apache.jackrabbit.vault.packaging.CyclicDependencyException;
 import org.apache.jackrabbit.vault.packaging.Dependency;
 import org.apache.jackrabbit.vault.packaging.PackageId;
 import org.apache.jackrabbit.vault.packaging.PackageProperties;
+import org.apache.jackrabbit.vault.packaging.PackageType;
 import org.apache.jackrabbit.vault.packaging.VaultPackage;
 import org.apache.sling.feature.ArtifactId;
 import org.apache.sling.feature.cpconverter.acl.AclManager;
@@ -156,7 +158,7 @@ public class ContentPackage2FeatureModelConverter extends BaseVaultPackageScanne
             idPackageMapping.put(pack.getId(), pack);
 
             // analyze sub-content packages in order to filter out
-            // possible outdated conflictring packages
+            // possible outdated conflicting packages
             recollectorVaultPackageScanner.traverse(pack);
 
             logger.info("content-package '{}' successfully read!", contentPackage);
@@ -196,7 +198,7 @@ public class ContentPackage2FeatureModelConverter extends BaseVaultPackageScanne
 
                 // deploy the new zip content-package to the local mvn bundles dir
 
-                artifactsDeployer.deploy(new FileArtifactWriter(contentPackageArchive), packageId);
+                deployCheckedContentPackageArchive(contentPackageArchive, packageId);
 
                 featuresManager.addArtifact(null, packageId);
 
@@ -271,7 +273,7 @@ public class ContentPackage2FeatureModelConverter extends BaseVaultPackageScanne
 
         // deploy the new content-package to the local mvn bundles dir and attach it to the feature
 
-        artifactsDeployer.deploy(new FileArtifactWriter(contentPackageArchive), packageId);
+        deployCheckedContentPackageArchive(contentPackageArchive, packageId);
 
         featuresManager.addArtifact(null, packageId);
 
@@ -281,6 +283,23 @@ public class ContentPackage2FeatureModelConverter extends BaseVaultPackageScanne
         emitter.endSubPackage();
     }
 
+    private void deployCheckedContentPackageArchive(File contentPackageArchive, ArtifactId packageId) throws Exception {
+        try (VaultPackage vaultPackage = open(contentPackageArchive)) {
+            PackageType packageType = detectPackageType(vaultPackage);
+            if (PackageType.MIXED == packageType) {
+                throw new Exception("Generated content-package '"
+                                    + packageId
+                                    + "' located in file "
+                                    + contentPackageArchive
+                                    + " is of MIXED type");
+            }
+        }
+
+        // deploy the new content-package to the local mvn bundles dir and attach it to the feature
+
+        artifactsDeployer.deploy(new FileArtifactWriter(contentPackageArchive), packageId);
+    }
+
     protected boolean isSubContentPackageIncluded(String path) {
         return subContentPackages.containsValue(path);
     }
diff --git a/src/main/java/org/apache/sling/feature/cpconverter/vltpkg/DefaultPackagesEventsEmitter.java b/src/main/java/org/apache/sling/feature/cpconverter/vltpkg/DefaultPackagesEventsEmitter.java
index 30d1d49..bdc3c31 100644
--- a/src/main/java/org/apache/sling/feature/cpconverter/vltpkg/DefaultPackagesEventsEmitter.java
+++ b/src/main/java/org/apache/sling/feature/cpconverter/vltpkg/DefaultPackagesEventsEmitter.java
@@ -17,6 +17,7 @@
 package org.apache.sling.feature.cpconverter.vltpkg;
 
 import static java.util.stream.Collectors.joining;
+import static org.apache.sling.feature.cpconverter.vltpkg.VaultPackageUtils.detectPackageType;
 
 import java.io.File;
 import java.io.FileWriter;
@@ -26,10 +27,7 @@ import java.io.Writer;
 import java.util.Date;
 import java.util.Stack;
 
-import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
-import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
 import org.apache.jackrabbit.vault.packaging.PackageId;
-import org.apache.jackrabbit.vault.packaging.PackageType;
 import org.apache.jackrabbit.vault.packaging.VaultPackage;
 
 /**
@@ -114,37 +112,4 @@ public final class DefaultPackagesEventsEmitter implements PackagesEventsEmitter
         endPackage();
     }
 
-    private static PackageType detectPackageType(VaultPackage vaultPackage) {
-        PackageType packageType = vaultPackage.getPackageType();
-        if (packageType != null) {
-            return packageType;
-        }
-
-        // borrowed from org.apache.jackrabbit.vault.fs.io.AbstractExporter
-        WorkspaceFilter filter = vaultPackage.getMetaInf().getFilter();
-
-        boolean hasApps = false;
-        boolean hasOther = false;
-        for (PathFilterSet p : filter.getFilterSets()) {
-            if ("cleanup".equals(p.getType())) {
-                continue;
-            }
-            String root = p.getRoot();
-            if ("/apps".equals(root)
-                    || root.startsWith("/apps/")
-                    || "/libs".equals(root)
-                    || root.startsWith("/libs/")) {
-                hasApps = true;
-            } else {
-                hasOther = true;
-            }
-        }
-        if (hasApps && !hasOther) {
-            return PackageType.APPLICATION;
-        } else if (hasOther && !hasApps) {
-            return PackageType.CONTENT;
-        }
-        return PackageType.MIXED;
-    }
-
 }
diff --git a/src/main/java/org/apache/sling/feature/cpconverter/vltpkg/VaultPackageUtils.java b/src/main/java/org/apache/sling/feature/cpconverter/vltpkg/VaultPackageUtils.java
new file mode 100644
index 0000000..70be3df
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/cpconverter/vltpkg/VaultPackageUtils.java
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+package org.apache.sling.feature.cpconverter.vltpkg;
+
+import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
+import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
+import org.apache.jackrabbit.vault.packaging.PackageType;
+import org.apache.jackrabbit.vault.packaging.VaultPackage;
+
+public class VaultPackageUtils {
+
+    private VaultPackageUtils() {
+        // this class must not be instantiated from outside
+    }
+
+    public static PackageType detectPackageType(VaultPackage vaultPackage) {
+        PackageType packageType = vaultPackage.getPackageType();
+        if (packageType != null) {
+            return packageType;
+        }
+
+        // borrowed from org.apache.jackrabbit.vault.fs.io.AbstractExporter
+        WorkspaceFilter filter = vaultPackage.getMetaInf().getFilter();
+
+        boolean hasApps = false;
+        boolean hasOther = false;
+        for (PathFilterSet p : filter.getFilterSets()) {
+            if ("cleanup".equals(p.getType())) {
+                continue;
+            }
+            String root = p.getRoot();
+            if ("/apps".equals(root)
+                    || root.startsWith("/apps/")
+                    || "/libs".equals(root)
+                    || root.startsWith("/libs/")) {
+                hasApps = true;
+            } else {
+                hasOther = true;
+            }
+        }
+        if (hasApps && !hasOther) {
+            return PackageType.APPLICATION;
+        } else if (hasOther && !hasApps) {
+            return PackageType.CONTENT;
+        }
+        return PackageType.MIXED;
+    }
+
+}