sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject [sling-org-apache-sling-installer-factory-packages] branch master updated: SLING-6657 allow to configure the dependency handling
Date Sat, 07 Jul 2018 15:00:31 GMT
This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-installer-factory-packages.git


The following commit(s) were added to refs/heads/master by this push:
     new 3c2e812  SLING-6657 allow to configure the dependency handling
3c2e812 is described below

commit 3c2e81294d09c0c2addafce101b7cbbbeafce212
Author: Konrad Windszus <kwin@apache.org>
AuthorDate: Sat Jul 7 17:00:05 2018 +0200

    SLING-6657 allow to configure the dependency handling
---
 .../factory/packages/impl/PackageTransformer.java       | 17 ++++++++++++-----
 .../packages/impl/PackageTransformerConfiguration.java  |  3 +++
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/sling/installer/factory/packages/impl/PackageTransformer.java
b/src/main/java/org/apache/sling/installer/factory/packages/impl/PackageTransformer.java
index 23e1cf2..8fe3481 100644
--- a/src/main/java/org/apache/sling/installer/factory/packages/impl/PackageTransformer.java
+++ b/src/main/java/org/apache/sling/installer/factory/packages/impl/PackageTransformer.java
@@ -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 {
diff --git a/src/main/java/org/apache/sling/installer/factory/packages/impl/PackageTransformerConfiguration.java
b/src/main/java/org/apache/sling/installer/factory/packages/impl/PackageTransformerConfiguration.java
index f2b527b..d6bdc1e 100644
--- a/src/main/java/org/apache/sling/installer/factory/packages/impl/PackageTransformerConfiguration.java
+++ b/src/main/java/org/apache/sling/installer/factory/packages/impl/PackageTransformerConfiguration.java
@@ -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;
 }


Mime
View raw message