This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch issue/SLING-12029 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-extension-content.git
commit e678ce62293141c5d976d946e0befcc00ecefa52 Author: Robert Munteanu <romb...@apache.org> AuthorDate: Wed Sep 20 11:04:43 2023 +0200 SLING-12029 - Make strictMode configurable Make strictMode configurable and document the way to configure it. --- README.md | 2 ++ .../apache/sling/feature/extension/content/ContentHandler.java | 9 ++++++--- .../sling/feature/extension/content/ContentHandlerTest.java | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 749b28b..8fea7fc 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,5 @@ To influence the package installation order the following format must be used The default start order is the maximum integer value (i.e. the package is processed after all packages with an explicit start-order). All content-packages from the model are registered (externally) in a [`FSPackageRegistry`](https://jackrabbit.apache.org/filevault/apidocs/org/apache/jackrabbit/vault/packaging/registry/impl/FSPackageRegistry.html) and scheduled for installation with execution plans (given via OSGi configuration) which automatically get executed during repository start by [ExecutionPlanRepoInitializer](https://github.com/apache/sling-org-apache-sling-jcr-packageinit/blob/master/src/main/java/org/apache/s [...] + +Strict package mode installation can be enabled for all packages by setting the `org.apache.sling.feature.extension.content.useStrictMode` system property to true. \ No newline at end of file diff --git a/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java b/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java index 87c952d..eaaffbd 100644 --- a/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java +++ b/src/main/java/org/apache/sling/feature/extension/content/ContentHandler.java @@ -54,7 +54,7 @@ public class ContentHandler implements ExtensionHandler { private static final String REGISTRY_FOLDER = "packageregistry"; - private static ExecutionPlanBuilder buildExecutionPlan(Collection<Artifact> artifacts, Set<PackageId> satisfiedPackages, LauncherPrepareContext prepareContext, File registryHome) throws Exception { + private static ExecutionPlanBuilder buildExecutionPlan(Collection<Artifact> artifacts, Set<PackageId> satisfiedPackages, LauncherPrepareContext prepareContext, File registryHome, boolean useStrictMode) throws Exception { List<File> packageReferences = new ArrayList<>(); @@ -79,7 +79,7 @@ public class ContentHandler implements ExtensionHandler { try { PackageId pid = registry.registerExternal(pkgFile, false); ImportOptions importOptions = new ImportOptions(); - importOptions.setStrict(true); + importOptions.setStrict(useStrictMode); PackageTaskOptions options = new ImportOptionsPackageTaskOption(importOptions); builder.addTask().with(pid).withOptions(options).with(Type.EXTRACT); } catch (PackageExistsException ex) { @@ -97,6 +97,9 @@ public class ContentHandler implements ExtensionHandler { File registryHome = getRegistryHomeDir(context); if (extension.getType() == ExtensionType.ARTIFACTS && extension.getName().equals(Extension.EXTENSION_NAME_CONTENT_PACKAGES)) { + + boolean useStrictMode = Boolean.getBoolean(getClass().getPackageName()+ ".useStrictMode"); + Map<Integer, Collection<Artifact>> orderedArtifacts = new TreeMap<>(); for (final Artifact a : extension.getArtifacts()) { int order; @@ -112,7 +115,7 @@ public class ContentHandler implements ExtensionHandler { Set<PackageId> satisfiedPackages = new HashSet<>(); for (Object key : orderedArtifacts.keySet()) { Collection<Artifact> artifacts = orderedArtifacts.get(key); - ExecutionPlanBuilder builder = buildExecutionPlan(artifacts, satisfiedPackages, context, registryHome); + ExecutionPlanBuilder builder = buildExecutionPlan(artifacts, satisfiedPackages, context, registryHome, useStrictMode); ByteArrayOutputStream baos = new ByteArrayOutputStream(); builder.save(baos); executionPlans.add(baos.toString("UTF-8")); diff --git a/src/test/java/org/apache/sling/feature/extension/content/ContentHandlerTest.java b/src/test/java/org/apache/sling/feature/extension/content/ContentHandlerTest.java index 64ae766..589f90d 100644 --- a/src/test/java/org/apache/sling/feature/extension/content/ContentHandlerTest.java +++ b/src/test/java/org/apache/sling/feature/extension/content/ContentHandlerTest.java @@ -115,7 +115,7 @@ public class ContentHandlerTest { "<executionPlan version=\"1.0\">\n" + " <task cmd=\"extract\" packageId=\"my_packages:test_c:1.0\">\n" + " <options type=\"ImportOptions\">\n" + - " <isStrict>true</isStrict>\n" + + " <isStrict>false</isStrict>\n" + " <autoSaveThreshold>-1</autoSaveThreshold>\n" + " <nonRecursive>false</nonRecursive>\n" + " <dryRun>false</dryRun>\n" + @@ -123,7 +123,7 @@ public class ContentHandlerTest { " </task>\n" + " <task cmd=\"extract\" packageId=\"my_packages:test_b:1.0\">\n" + " <options type=\"ImportOptions\">\n" + - " <isStrict>true</isStrict>\n" + + " <isStrict>false</isStrict>\n" + " <autoSaveThreshold>-1</autoSaveThreshold>\n" + " <nonRecursive>false</nonRecursive>\n" + " <dryRun>false</dryRun>\n" + @@ -137,7 +137,7 @@ public class ContentHandlerTest { "<executionPlan version=\"1.0\">\n" + " <task cmd=\"extract\" packageId=\"my_packages:test_a:1.0\">\n" + " <options type=\"ImportOptions\">\n" + - " <isStrict>true</isStrict>\n" + + " <isStrict>false</isStrict>\n" + " <autoSaveThreshold>-1</autoSaveThreshold>\n" + " <nonRecursive>false</nonRecursive>\n" + " <dryRun>false</dryRun>\n" +