SLING-6657 allow to configure the dependency handling
authorKonrad Windszus <kwin@apache.org>
Sat, 7 Jul 2018 15:00:05 +0000 (17:00 +0200)
committerKonrad Windszus <kwin@apache.org>
Sat, 7 Jul 2018 15:00:05 +0000 (17:00 +0200)
src/main/java/org/apache/sling/installer/factory/packages/impl/PackageTransformer.java
src/main/java/org/apache/sling/installer/factory/packages/impl/PackageTransformerConfiguration.java

index 23e1cf2..8fe3481 100644 (file)
@@ -34,6 +34,7 @@ import org.apache.jackrabbit.vault.fs.io.Archive;
 import org.apache.jackrabbit.vault.fs.io.ImportOptions;
 import org.apache.jackrabbit.vault.fs.io.ZipStreamArchive;
 import org.apache.jackrabbit.vault.packaging.Dependency;
+import org.apache.jackrabbit.vault.packaging.DependencyHandling;
 import org.apache.jackrabbit.vault.packaging.JcrPackage;
 import org.apache.jackrabbit.vault.packaging.JcrPackageManager;
 import org.apache.jackrabbit.vault.packaging.PackageException;
@@ -305,16 +306,20 @@ public class PackageTransformer implements ResourceTransformer, InstallTaskFacto
                     return;
                 }
 
-                // check if dependencies are installed
-                for (final Dependency d : pkg.getDefinition().getDependencies()) {
-                    if (pkgMgr.resolve(d, true) == null) {
-                        logger.info("Delaying installation of {} due to missing dependency {}.", pkgId, d);
-                        return;
+                // is dependency checking necessary?
+                if (configuration.dependencyHandling() == DependencyHandling.REQUIRED || configuration.dependencyHandling() == DependencyHandling.STRICT) {
+                    // check if dependencies are installed/available
+                    for (final Dependency d : pkg.getDefinition().getDependencies()) {
+                        if (pkgMgr.resolve(d, configuration.dependencyHandling() == DependencyHandling.STRICT ? true : false) == null) {
+                            logger.info("Delaying installation of {} due to missing dependency {}.", pkgId, d);
+                            return;
+                        }
                     }
                 }
 
                 // finally, install package
                 final ImportOptions opts = new ImportOptions();
+                opts.setDependencyHandling(configuration.dependencyHandling());
                 if (configuration.shouldCreateSnapshots()) {
                     pkg.install(opts);
                     ctx.log("Content package installed: {}", resource);
@@ -357,6 +362,7 @@ public class PackageTransformer implements ResourceTransformer, InstallTaskFacto
                 // we always have to do that, as there is no possibility to figure out whether the same package has already been installed
                 // https://issues.apache.org/jira/browse/JCRVLT-188
                 final ImportOptions opts = new ImportOptions();
+                opts.setDependencyHandling(configuration.dependencyHandling());
                 pkgMgr.extract(archive, opts, true);
             } finally {
                 archive.close();
@@ -395,6 +401,7 @@ public class PackageTransformer implements ResourceTransformer, InstallTaskFacto
             try {
                 if (pkg != null) {
                     final ImportOptions opts = new ImportOptions();
+                    opts.setDependencyHandling(configuration.dependencyHandling());
                     pkg.uninstall(opts);
                 }
             } finally {
index f2b527b..d6bdc1e 100644 (file)
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.installer.factory.packages.impl;
 
+import org.apache.jackrabbit.vault.packaging.DependencyHandling;
 import org.osgi.service.metatype.annotations.AttributeDefinition;
 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
 
@@ -29,4 +30,6 @@ public @interface PackageTransformerConfiguration {
     boolean shouldCreateHollowPackages() default false;
     @AttributeDefinition(name = "Observation Manager's User Data", description = "Sets the user data on the observation manager (only affects the session used for package installation) to the given value. Leave empty to not set it. Can be used to check in EventListeners whether an event was caused by package installation/uninstallation.")
     String observationManagerUserData() default "";
+    @AttributeDefinition(name = "Dependency Handling", description = "Sets the dependency handling for package installation. Must have one of the values 'IGNORE', 'BEST_EFFORT', 'REQUIRED' or 'STRICT'.")
+    DependencyHandling dependencyHandling() default DependencyHandling.STRICT;
 }