SLING-8623 - adding option to drop packageType.CONTENT packages(active by default via CLI)
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..ae8d5c7 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.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;
@@ -79,6 +81,8 @@
private PackagesEventsEmitter emitter;
+ private boolean dropContent;
+
public ContentPackage2FeatureModelConverter() {
this(false);
}
@@ -133,6 +137,12 @@
this.emitter = emitter;
return this;
}
+
+ public ContentPackage2FeatureModelConverter setDropContent(boolean dropContent) {
+ this.dropContent = dropContent;
+ return this;
+ }
+
public void convert(File...contentPackages) throws Exception {
requireNonNull(contentPackages , "Null content-package(s) can not be converted.");
@@ -156,7 +166,7 @@
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,9 +206,7 @@
// deploy the new zip content-package to the local mvn bundles dir
- artifactsDeployer.deploy(new FileArtifactWriter(contentPackageArchive), packageId);
-
- featuresManager.addArtifact(null, packageId);
+ processContentPackageArchive(contentPackageArchive, packageId);
// finally serialize the Feature Model(s) file(s)
@@ -270,10 +278,7 @@
File contentPackageArchive = clonedPackage.createPackage();
// deploy the new content-package to the local mvn bundles dir and attach it to the feature
-
- artifactsDeployer.deploy(new FileArtifactWriter(contentPackageArchive), packageId);
-
- featuresManager.addArtifact(null, packageId);
+ processContentPackageArchive(contentPackageArchive, packageId);
// restore the previous assembler
mainPackageAssembler = handler;
@@ -281,6 +286,18 @@
emitter.endSubPackage();
}
+ private void processContentPackageArchive(File contentPackageArchive, ArtifactId packageId) throws Exception {
+ try (VaultPackage vaultPackage = open(contentPackageArchive)) {
+ PackageType packageType = detectPackageType(vaultPackage);
+ // don't deploy & add content-packages of type content to featuremodel if dropContent is set
+ if (PackageType.CONTENT != packageType || !dropContent) {
+ // deploy the new content-package to the local mvn bundles dir and attach it to the feature
+ artifactsDeployer.deploy(new FileArtifactWriter(contentPackageArchive), packageId);
+ featuresManager.addArtifact(null, 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.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 @@
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;
+ }
+
+}