jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1767220 - in /jackrabbit/commons/filevault/trunk/vault-core/src: main/java/org/apache/jackrabbit/vault/fs/io/ main/java/org/apache/jackrabbit/vault/packaging/ main/java/org/apache/jackrabbit/vault/packaging/impl/ test/java/org/apache/jackr...
Date Mon, 31 Oct 2016 06:29:35 GMT
Author: tripod
Date: Mon Oct 31 06:29:35 2016
New Revision: 1767220

URL: http://svn.apache.org/viewvc?rev=1767220&view=rev
Log:
JCRVLT-136 Add import option flags to enforce dependency checks

Added:
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/DependencyException.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/DependencyHandling.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestEnforcedDependencies.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_a-1.0.zip
    jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_a-2.0.zip
    jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_b-1.0.zip
    jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_c-1.0.zip
    jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_c-1.1.zip
    jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_c-2.0.zip
    jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_d-1.0.zip
    jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_e-1.0.zip
Modified:
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ImportOptions.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/JcrPackage.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/JcrPackageDefinition.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/JcrPackageManager.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/PackagingService.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageImpl.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageManagerImpl.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackagingImpl.java

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ImportOptions.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ImportOptions.java?rev=1767220&r1=1767219&r2=1767220&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ImportOptions.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/ImportOptions.java Mon Oct 31 06:29:35 2016
@@ -26,6 +26,7 @@ import org.apache.jackrabbit.vault.fs.ap
 import org.apache.jackrabbit.vault.fs.api.PathMapping;
 import org.apache.jackrabbit.vault.fs.api.ProgressTrackerListener;
 import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
+import org.apache.jackrabbit.vault.packaging.DependencyHandling;
 
 /**
  * Option that control the package import.
@@ -60,6 +61,8 @@ public class ImportOptions {
 
     private PathMapping pathMapping = null;
 
+    private DependencyHandling dependencyHandling = null;
+
     /**
      * Default constructor.
      */
@@ -88,6 +91,7 @@ public class ImportOptions {
             filter = base.filter;
             hookClassLoader = base.hookClassLoader;
             pathMapping = base.pathMapping;
+            dependencyHandling = base.dependencyHandling;
         }
     }
 
@@ -111,6 +115,7 @@ public class ImportOptions {
         ret.filter = filter;
         ret.hookClassLoader = hookClassLoader;
         ret.pathMapping = pathMapping;
+        ret.dependencyHandling = dependencyHandling;
         return ret;
     }
 
@@ -360,4 +365,22 @@ public class ImportOptions {
     public void setPathMapping(PathMapping pathMapping) {
         this.pathMapping = pathMapping;
     }
+
+    /**
+     * Defines how package dependencies affect package installation and un-installation.
+     * @return the dependency handling.
+     */
+    public DependencyHandling getDependencyHandling() {
+        return dependencyHandling;
+    }
+
+    /**
+     * Sets the dependency handling.
+     * @param dependencyHandling the dependency handling.
+     * @see #getDependencyHandling()
+     * @since 3.1.32
+     */
+    public void setDependencyHandling(DependencyHandling dependencyHandling) {
+        this.dependencyHandling = dependencyHandling;
+    }
 }
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/DependencyException.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/DependencyException.java?rev=1767220&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/DependencyException.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/DependencyException.java Mon Oct 31 06:29:35 2016
@@ -0,0 +1,39 @@
+/*
+ * 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.jackrabbit.vault.packaging;
+
+/**
+ * {@code DependencyException}...
+ */
+public class DependencyException extends PackageException {
+
+    public DependencyException() {
+    }
+
+    public DependencyException(String message) {
+        super(message);
+    }
+
+    public DependencyException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public DependencyException(Throwable cause) {
+        super(cause);
+    }
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/DependencyHandling.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/DependencyHandling.java?rev=1767220&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/DependencyHandling.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/DependencyHandling.java Mon Oct 31 06:29:35 2016
@@ -0,0 +1,53 @@
+/*
+ * 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.jackrabbit.vault.packaging;
+
+/**
+ * Defines how package dependencies influence package installation and un-installation.
+ */
+public enum DependencyHandling {
+
+    /**
+     * No dependency checks are enforced
+     */
+    IGNORE,
+
+    /**
+     * Dependency checks are performed but not enforced. If a dependency is present but not installed, it will be
+     * installed prior to installing the referencing issue. However the installation will proceed, even if the dependency is missing.
+     *
+     * Un-installation will automatically uninstall referencing packages.
+     */
+    BEST_EFFORT,
+
+    /**
+     * Dependency checks are performed but not enforced. If a dependency is present but not installed, it will be
+     * installed prior to installing the referencing issue. If a dependency is not present, installation fails.
+     *
+     * Un-installation will automatically uninstall referencing packages.
+     */
+    REQUIRED,
+
+    /**
+     * Full dependency checks are enforced. Packages with missing or uninstalled dependencies are not installed and
+     * packages that are dependencies of other packages cannot be un-installed.
+     */
+    STRICT,
+
+
+}

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/JcrPackage.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/JcrPackage.java?rev=1767220&r1=1767219&r2=1767220&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/JcrPackage.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/JcrPackage.java Mon Oct 31 06:29:35 2016
@@ -56,7 +56,6 @@ public interface JcrPackage extends Comp
      *         not valid.
      * @throws RepositoryException if an error occurrs
      */
-
     JcrPackageDefinition getDefinition() throws RepositoryException;
 
     /**
@@ -115,6 +114,23 @@ public interface JcrPackage extends Comp
             throws RepositoryException, PackageException, IOException;
 
     /**
+     * Returns the dependencies that are not resolved. If the {@link DependencyHandling} is set to strict, the package
+     * will not installed if any unresolved dependencies are listed.
+     * @return the array of unresolved dependencies.
+     * @throws RepositoryException if an error accessing the repository occurrs
+     * @since 3.1.32
+     */
+    Dependency[] getUnresolvedDependencies() throws RepositoryException;
+
+    /**
+     * Returns a list of the installed packages that this package depends on.
+     * @return the array of resolved dependencies
+     * @throws RepositoryException if an error accessing the repository occurrs
+     * @since 3.1.32
+     */
+    PackageId[] getResolvedDependencies() throws RepositoryException;
+
+    /**
      * Creates a snapshot of this package.
      *
      * @param opts export options

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/JcrPackageDefinition.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/JcrPackageDefinition.java?rev=1767220&r1=1767219&r2=1767220&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/JcrPackageDefinition.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/JcrPackageDefinition.java Mon Oct 31 06:29:35 2016
@@ -37,146 +37,146 @@ public interface JcrPackageDefinition {
     /**
      * Property name of the last unpacked date
      */
-    public static final String PN_LAST_UNPACKED = "lastUnpacked";
+    String PN_LAST_UNPACKED = "lastUnpacked";
 
     /**
      * Property name of the last unpacked user id
      */
-    public static final String PN_LAST_UNPACKED_BY = "lastUnpackedBy";
+    String PN_LAST_UNPACKED_BY = "lastUnpackedBy";
 
     /**
      * Property name of the creation date
      */
-    public static final String PN_CREATED = "jcr:created";
+    String PN_CREATED = "jcr:created";
 
     /**
      * Property name of the creation user id
      */
-    public static final String PN_CREATED_BY = "jcr:createdBy";
+    String PN_CREATED_BY = "jcr:createdBy";
 
     /**
      * Property name of the last modification date
      */
-    public static final String PN_LASTMODIFIED = "jcr:lastModified";
+    String PN_LASTMODIFIED = "jcr:lastModified";
 
     /**
      * Property name of the last modification user id
      */
-    public static final String PN_LASTMODIFIED_BY = "jcr:lastModifiedBy";
+    String PN_LASTMODIFIED_BY = "jcr:lastModifiedBy";
 
     /**
      * Property name of the last wrapped date
      * @since 2.2.22
      */
-    public static final String PN_LAST_WRAPPED = "lastWrapped";
+    String PN_LAST_WRAPPED = "lastWrapped";
 
     /**
      * Property name of the last wrapped user id
      * @since 2.2.22
      */
-    public static final String PN_LAST_WRAPPED_BY = "lastWrappedBy";
+    String PN_LAST_WRAPPED_BY = "lastWrappedBy";
 
     /**
      * Property name of the package description
      */
-    public static final String PN_DESCRIPTION = "jcr:description";
+    String PN_DESCRIPTION = "jcr:description";
 
     /**
      * Property name of the package version
      */
-    public static final String PN_VERSION = "version";
+    String PN_VERSION = "version";
 
     /**
      * Property name of the build count
      */
-    public static final String PN_BUILD_COUNT = "buildCount";
+    String PN_BUILD_COUNT = "buildCount";
 
     /**
      * Property name of the 'name'
      * @since 2.2
      */
-    public static final String PN_NAME = "name";
+    String PN_NAME = "name";
 
     /**
      * Property name of the 'group'
      * @since 2.2
      */
-    public static final String PN_GROUP = "group";
+    String PN_GROUP = "group";
 
     /**
      * Property name of the "requires root" flag
      */
-    public static final String PN_REQUIRES_ROOT = "requiresRoot";
+    String PN_REQUIRES_ROOT = "requiresRoot";
 
     /**
      * Property name of the "require restart" flag
      */
-    public static final String PN_REQUIRES_RESTART = "requiresRestart";
+    String PN_REQUIRES_RESTART = "requiresRestart";
 
     /**
      * Property name of the package dependencies
      */
-    public static final String PN_DEPENDENCIES = "dependencies";
+    String PN_DEPENDENCIES = "dependencies";
 
     /**
      * Property name of the sub packages (only used in snapshots)
      */
-    public static final String PN_SUB_PACKAGES = "subPackages";
+    String PN_SUB_PACKAGES = "subPackages";
 
     /**
      * Property name of the last unwrapped date
      */
-    public static final String PN_LAST_UNWRAPPED = "lastUnwrapped";
+    String PN_LAST_UNWRAPPED = "lastUnwrapped";
 
     /**
      * Property name of the last unwrapped user id
      */
-    public static final String PN_LAST_UNWRAPPED_BY = "lastUnwrappedBy";
+    String PN_LAST_UNWRAPPED_BY = "lastUnwrappedBy";
 
     /**
      * Property name of the access control handling mode
      */
-    public static final String PN_AC_HANDLING = "acHandling";
+    String PN_AC_HANDLING = "acHandling";
 
     /**
      * Property name of the cnd pattern filter
      */
-    public static final String PN_CND_PATTERN = "cndPattern";
+    String PN_CND_PATTERN = "cndPattern";
 
     /**
      * Node name of the filter node
      */
-    public static final String NN_FILTER = "filter";
+    String NN_FILTER = "filter";
 
     /**
      * Property name of the filter root
      */
-    public static final String PN_ROOT = "root";
+    String PN_ROOT = "root";
 
     /**
      * Property name of the filter root
      */
-    public static final String PN_MODE = "mode";
+    String PN_MODE = "mode";
 
     /**
      * Property name of the filter rules
      */
-    public static final String PN_RULES = "rules";
+    String PN_RULES = "rules";
 
     /**
      * Property name of the rule type
      */
-    public static final String PN_TYPE = "type";
+    String PN_TYPE = "type";
 
     /**
      * Property name of the rule pattern
      */
-    public static final String PN_PATTERN = "pattern";
+    String PN_PATTERN = "pattern";
 
     /**
      * Property name of the disable intermediate save flag
      */
-    public static final String PN_DISABLE_INTERMEDIATE_SAVE = "noIntermediateSaves";
+    String PN_DISABLE_INTERMEDIATE_SAVE = "noIntermediateSaves";
 
     /**
      * Returns the underlying node

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/JcrPackageManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/JcrPackageManager.java?rev=1767220&r1=1767219&r2=1767220&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/JcrPackageManager.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/JcrPackageManager.java Mon Oct 31 06:29:35 2016
@@ -84,6 +84,17 @@ public interface JcrPackageManager exten
     PackageId resolve(Dependency dependency, boolean onlyInstalled) throws RepositoryException;
 
     /**
+     * Returns the package ids of installed packages that depend on the given package.
+     *
+     * @param id the package id to search for
+     * @return the array of package ids.
+     * @throws RepositoryException if an error occurs
+     *
+     * @since 3.1.32
+     */
+    PackageId[] usage(PackageId id) throws RepositoryException;
+
+    /**
      * Uploads a package. The location is chosen from the installation path of
      * the package. if the package does not provide such a path, the nameHint
      * is respected and the package is placed below the package root.

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/PackagingService.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/PackagingService.java?rev=1767220&r1=1767219&r2=1767220&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/PackagingService.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/PackagingService.java Mon Oct 31 06:29:35 2016
@@ -22,10 +22,8 @@ import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
 import org.apache.jackrabbit.vault.packaging.impl.JcrPackageDefinitionImpl;
-import org.apache.jackrabbit.vault.packaging.impl.JcrPackageImpl;
 import org.apache.jackrabbit.vault.packaging.impl.JcrPackageManagerImpl;
 import org.apache.jackrabbit.vault.packaging.impl.PackageManagerImpl;
-import org.apache.jackrabbit.vault.util.JcrConstants;
 
 /**
  * Default access point to package managers for non OSGi clients.
@@ -80,15 +78,7 @@ public class PackagingService {
      */
     public static JcrPackage open(Node node, boolean allowInvalid)
             throws RepositoryException {
-        JcrPackage pack = new JcrPackageImpl(node);
-        if (pack.isValid()) {
-            return pack;
-        } else if (allowInvalid
-                && node.isNodeType(JcrConstants.NT_HIERARCHYNODE)
-                && node.hasProperty(JcrConstants.JCR_CONTENT + "/" + JcrConstants.JCR_DATA)) {
-            return pack;
-        } else {
-            return null;
-        }
+        JcrPackageManager pMgr = getPackageManager(node.getSession());
+        return pMgr.open(node, allowInvalid);
     }
 }
\ No newline at end of file

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageImpl.java?rev=1767220&r1=1767219&r2=1767220&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageImpl.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageImpl.java Mon Oct 31 06:29:35 2016
@@ -17,15 +17,16 @@
 
 package org.apache.jackrabbit.vault.packaging.impl;
 
-import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Calendar;
+import java.util.Arrays;
+import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Set;
 
 import javax.jcr.Binary;
 import javax.jcr.Node;
@@ -43,11 +44,14 @@ import org.apache.jackrabbit.vault.fs.io
 import org.apache.jackrabbit.vault.fs.io.MemoryArchive;
 import org.apache.jackrabbit.vault.fs.io.ZipArchive;
 import org.apache.jackrabbit.vault.packaging.CyclicDependencyException;
+import org.apache.jackrabbit.vault.packaging.Dependency;
+import org.apache.jackrabbit.vault.packaging.DependencyHandling;
 import org.apache.jackrabbit.vault.packaging.DependencyUtil;
 import org.apache.jackrabbit.vault.packaging.ExportOptions;
 import org.apache.jackrabbit.vault.packaging.JcrPackage;
 import org.apache.jackrabbit.vault.packaging.JcrPackageDefinition;
 import org.apache.jackrabbit.vault.packaging.JcrPackageManager;
+import org.apache.jackrabbit.vault.packaging.DependencyException;
 import org.apache.jackrabbit.vault.packaging.PackageException;
 import org.apache.jackrabbit.vault.packaging.PackageId;
 import org.apache.jackrabbit.vault.packaging.SubPackageHandling;
@@ -69,6 +73,11 @@ public class JcrPackageImpl implements J
     private static final Logger log = LoggerFactory.getLogger(JcrPackageImpl.class);
 
     /**
+     * our package manager
+     */
+    private final JcrPackageManagerImpl mgr;
+
+    /**
      * underlying node
      */
     private Node node;
@@ -83,17 +92,20 @@ public class JcrPackageImpl implements J
      */
     private JcrPackageDefinitionImpl def;
 
-    public JcrPackageImpl(Node node) throws RepositoryException {
+    public JcrPackageImpl(JcrPackageManagerImpl mgr, Node node) throws RepositoryException {
+        this.mgr = mgr;
         this.node = node;
     }
 
-    protected JcrPackageImpl(Node node, ZipVaultPackage pack) throws RepositoryException {
+    protected JcrPackageImpl(JcrPackageManagerImpl mgr, Node node, ZipVaultPackage pack) throws RepositoryException {
+        this.mgr = mgr;
         this.node = node;
         this.pack = pack;
     }
 
-    protected JcrPackageImpl(Node node, ZipVaultPackage pack, JcrPackageDefinitionImpl def)
+    protected JcrPackageImpl(JcrPackageManagerImpl mgr, Node node, ZipVaultPackage pack, JcrPackageDefinitionImpl def)
             throws RepositoryException {
+        this.mgr = mgr;
         this.node = node;
         this.pack = pack;
         this.def = def;
@@ -184,82 +196,6 @@ public class JcrPackageImpl implements J
     }
 
     /**
-     * Creates a new jcr vault package.
-     *
-     * @param parent the parent node
-     * @param pid the package id of the new package.
-     * @param pack the underlying zip package or null.
-     * @param autoSave if {@code true} the changes are persisted immediately
-     * @return the created jcr vault package.
-     * @throws RepositoryException if an repository error occurs
-     * @throws IOException if an I/O error occurs
-     *
-     * @since 2.3.0
-     */
-    public static JcrPackage createNew(Node parent, PackageId pid, VaultPackage pack, boolean autoSave)
-            throws RepositoryException, IOException {
-        Node node = parent.addNode(Text.getName(pid.getInstallationPath() + ".zip"), JcrConstants.NT_FILE);
-        Node content = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
-        content.addMixin(NT_VLT_PACKAGE);
-        Node defNode = content.addNode(NN_VLT_DEFINITION);
-        JcrPackageDefinition def = new JcrPackageDefinitionImpl(defNode);
-        def.set(JcrPackageDefinition.PN_NAME, pid.getName(), false);
-        def.set(JcrPackageDefinition.PN_GROUP, pid.getGroup(), false);
-        def.set(JcrPackageDefinition.PN_VERSION, pid.getVersionString(), false);
-        def.touch(null, false);
-        content.setProperty(JcrConstants.JCR_LASTMODIFIED, Calendar.getInstance());
-        content.setProperty(JcrConstants.JCR_MIMETYPE, MIME_TYPE);
-        InputStream in = new ByteArrayInputStream(new byte[0]);
-        try {
-            if (pack != null && pack.getFile() != null) {
-                in = FileUtils.openInputStream(pack.getFile());
-            }
-            // stay jcr 1.0 compatible
-            //noinspection deprecation
-            content.setProperty(JcrConstants.JCR_DATA, in);
-            if (pack != null) {
-                def.unwrap(pack, true, false);
-            }
-            if (autoSave) {
-                parent.getSession().save();
-            }
-        } finally {
-            IOUtils.closeQuietly(in);
-        }
-        return new JcrPackageImpl(node, (ZipVaultPackage) pack);
-    }
-    /**
-     * Creates a new jcr vault package.
-     *
-     * @param parent the parent node
-     * @param pid the package id of the new package.
-     * @param bin the binary containing the zip
-     * @param archive the archive with the meta data
-     * @return the created jcr vault package.
-     * @throws RepositoryException if an repository error occurs
-     * @throws IOException if an I/O error occurs
-     *
-     * @since 3.1
-     */
-    public static JcrPackage createNew(Node parent, PackageId pid, Binary bin, MemoryArchive archive)
-            throws RepositoryException, IOException {
-        Node node = parent.addNode(Text.getName(pid.getInstallationPath() + ".zip"), JcrConstants.NT_FILE);
-        Node content = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
-        content.addMixin(NT_VLT_PACKAGE);
-        Node defNode = content.addNode(NN_VLT_DEFINITION);
-        JcrPackageDefinitionImpl def = new JcrPackageDefinitionImpl(defNode);
-        def.set(JcrPackageDefinition.PN_NAME, pid.getName(), false);
-        def.set(JcrPackageDefinition.PN_GROUP, pid.getGroup(), false);
-        def.set(JcrPackageDefinition.PN_VERSION, pid.getVersionString(), false);
-        def.touch(null, false);
-        content.setProperty(JcrConstants.JCR_LASTMODIFIED, Calendar.getInstance());
-        content.setProperty(JcrConstants.JCR_MIMETYPE, MIME_TYPE);
-        content.setProperty(JcrConstants.JCR_DATA, bin);
-        def.unwrap(archive, false);
-        return new JcrPackageImpl(node);
-    }
-
-    /**
      * {@inheritDoc}
      */
     public boolean verifyId(boolean autoFix, boolean autoSave) throws RepositoryException {
@@ -394,9 +330,16 @@ public class JcrPackageImpl implements J
         extract(opts, true, false);
     }
 
+
+    private void extract(ImportOptions options, boolean createSnapshot, boolean replaceSnapshot)
+            throws RepositoryException, PackageException, IOException {
+        extract(new HashSet<PackageId>(), options, createSnapshot, replaceSnapshot);
+    }
+
     /**
      * internally extracts the package.
      *
+     * @param processed the set of processed dependencies
      * @param options the import options
      * @param createSnapshot {@code true} if a snapshot should be created
      * @param replaceSnapshot {@code true} if a snapshot should be replaced
@@ -404,9 +347,17 @@ public class JcrPackageImpl implements J
      * @throws PackageException if a package error occurs
      * @throws IOException if an I/O error occurs
      */
-    private void extract(ImportOptions options, boolean createSnapshot, boolean replaceSnapshot)
+    private void extract(Set<PackageId> processed, ImportOptions options, boolean createSnapshot, boolean replaceSnapshot)
             throws RepositoryException, PackageException, IOException {
         getPackage();
+        if (def != null) {
+            processed.add(def.getId());
+        }
+
+        if (options.getDependencyHandling() != null && options.getDependencyHandling() != DependencyHandling.IGNORE) {
+            installDependencies(processed, options, createSnapshot, replaceSnapshot);
+        }
+
         // get a copy of the import options (bug 35164)
         ImportOptions opts = options.copy();
         // check for disable intermediate saves (GRANITE-1047)
@@ -433,7 +384,7 @@ public class JcrPackageImpl implements J
         List<JcrPackageImpl> subPacks = new LinkedList<JcrPackageImpl>();
         for (String path: subPackages) {
             if (s.nodeExists(path)) {
-                JcrPackageImpl p = new JcrPackageImpl(s.getNode(path));
+                JcrPackageImpl p = new JcrPackageImpl(mgr, s.getNode(path));
                 if (!p.isValid()) {
                     // check if package was included as pure .zip or .jar
                     try {
@@ -535,6 +486,120 @@ public class JcrPackageImpl implements J
     /**
      * {@inheritDoc}
      */
+    @Override
+    public Dependency[] getUnresolvedDependencies() throws RepositoryException {
+        JcrPackageDefinition def = getDefinition();
+        if (def == null) {
+            return Dependency.EMPTY;
+        }
+        List<Dependency> unresolved = new LinkedList<Dependency>();
+        for (Dependency dep: def.getDependencies()) {
+            if (mgr.resolve(dep, true) == null) {
+                unresolved.add(dep);
+            };
+        }
+        return unresolved.toArray(new Dependency[unresolved.size()]);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public PackageId[] getResolvedDependencies() throws RepositoryException {
+        JcrPackageDefinition def = getDefinition();
+        if (def == null) {
+            return PackageId.EMPTY;
+        }
+        List<PackageId> resolved = new LinkedList<PackageId>();
+        for (Dependency dep: def.getDependencies()) {
+            PackageId id = mgr.resolve(dep, true);
+            if (id != null) {
+                resolved.add(id);
+            };
+        }
+        return resolved.toArray(new PackageId[resolved.size()]);
+    }
+
+    /**
+     * Checks if all the package dependencies are resolved
+     * @param opts install options
+     */
+    private void installDependencies(Set<PackageId> processed, ImportOptions opts, boolean createSnapshot, boolean replaceSnapshot)
+            throws PackageException, RepositoryException, IOException {
+        List<Dependency> unresolved = new LinkedList<Dependency>();
+        List<JcrPackageImpl> uninstalled = new LinkedList<JcrPackageImpl>();
+        for (Dependency dep: def.getDependencies()) {
+            // resolve to installed and uninstalled packages
+            PackageId id = mgr.resolve(dep, false);
+            if (id == null) {
+                unresolved.add(dep);
+            } else {
+                JcrPackageImpl pack = (JcrPackageImpl) mgr.open(id);
+                if (!pack.isInstalled()) {
+                    unresolved.add(dep);
+                    uninstalled.add(pack);
+                }
+            }
+        }
+        // if non unresolved, then we're good
+        if (unresolved.size() == 0) {
+            return;
+        }
+        // if the package is not installed at all, abort for required and strict handling
+        if ((opts.getDependencyHandling() == DependencyHandling.STRICT && unresolved.size() > 0)
+                || (opts.getDependencyHandling() == DependencyHandling.REQUIRED && unresolved.size() > uninstalled.size())) {
+            String msg = String.format("Refusing to install package %s. required dependencies missing: %s", def.getId(), unresolved);
+            log.error(msg);
+            throw new DependencyException(msg);
+        }
+
+        for (JcrPackageImpl pack: uninstalled) {
+            if (pack.isInstalled()) {
+                continue;
+            }
+            PackageId packageId = pack.getDefinition().getId();
+            if (processed.contains(packageId)) {
+                if (opts.getDependencyHandling() == DependencyHandling.BEST_EFFORT) {
+                    continue;
+                }
+                String msg = String.format("Unable to install package %s. dependency has as cycling reference to %s", def.getId(), packageId);
+                log.error(msg);
+                throw new CyclicDependencyException(msg);
+            }
+            pack.extract(processed, opts, createSnapshot, replaceSnapshot);
+        }
+    }
+
+    /**
+     * Checks if all no other package depend on us.
+     * @param processed set of already uninstalled packages.
+     * @param opts install options
+     */
+    private void uninstallUsages(Set<PackageId> processed, ImportOptions opts)
+            throws PackageException, RepositoryException, IOException {
+        PackageId[] usage = mgr.usage(getDefinition().getId());
+        if (usage.length > 0 && opts.getDependencyHandling() == DependencyHandling.STRICT) {
+            String msg = String.format("Refusing to uninstall package %s. it is still used by: %s", def.getId(), Arrays.toString(usage));
+            log.error(msg);
+            throw new DependencyException(msg);
+        }
+        for (PackageId id: usage) {
+            JcrPackageImpl pack = (JcrPackageImpl) mgr.open(id);
+            if (pack == null || !pack.isInstalled()) {
+                continue;
+            }
+            PackageId packageId = pack.getDefinition().getId();
+            if (processed.contains(packageId)) {
+                // ignore cyclic...
+                continue;
+            }
+            pack.uninstall(processed, opts);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public JcrPackage snapshot(ExportOptions opts, boolean replace)
             throws RepositoryException, PackageException, IOException {
         return snapshot(opts, replace, null);
@@ -568,7 +633,7 @@ public class JcrPackageImpl implements J
         String path = id.getInstallationPath();
         String parentPath = Text.getRelativeParent(path, 1);
         Node folder = packMgr.mkdir(parentPath, true);
-        JcrPackage snap = JcrPackageImpl.createNew(folder, id, null, true);
+        JcrPackage snap = mgr.createNew(folder, id, null, true);
         JcrPackageDefinitionImpl snapDef = (JcrPackageDefinitionImpl) snap.getDefinition();
         JcrPackageDefinitionImpl myDef = (JcrPackageDefinitionImpl) getDefinition();
         snapDef.setId(id, false);
@@ -609,7 +674,7 @@ public class JcrPackageImpl implements J
         PackageId id = getSnapshotId();
         Node packNode = getPackageNode(id);
         if (packNode != null) {
-            JcrPackageImpl snap = new JcrPackageImpl(packNode);
+            JcrPackageImpl snap = new JcrPackageImpl(mgr, packNode);
             if (snap.isValid()) {
                 return snap;
             }
@@ -636,10 +701,25 @@ public class JcrPackageImpl implements J
                 id.getVersion());
     }
 
+
     /**
      * {@inheritDoc}
      */
     public void uninstall(ImportOptions opts) throws RepositoryException, PackageException, IOException {
+        uninstall(new HashSet<PackageId>(), opts);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    private void uninstall(Set<PackageId> processed, ImportOptions opts) throws RepositoryException, PackageException, IOException {
+        if (def != null) {
+            processed.add(def.getId());
+        }
+        if (opts.getDependencyHandling() != null && opts.getDependencyHandling() != DependencyHandling.IGNORE) {
+            uninstallUsages(processed, opts);
+        }
+
         JcrPackage snap = getSnapshot();
         if (snap == null) {
             if (opts.isStrict()) {

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageManagerImpl.java?rev=1767220&r1=1767219&r2=1767220&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageManagerImpl.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/JcrPackageManagerImpl.java Mon Oct 31 06:29:35 2016
@@ -17,6 +17,7 @@
 
 package org.apache.jackrabbit.vault.packaging.impl;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -24,9 +25,12 @@ import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.util.Calendar;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Properties;
+import java.util.Set;
+import java.util.TreeSet;
 
 import javax.jcr.Binary;
 import javax.jcr.ItemExistsException;
@@ -104,6 +108,7 @@ public class JcrPackageManagerImpl exten
         initNodeTypes();
     }
 
+    @Override
     public JcrPackage open(PackageId id) throws RepositoryException {
         String path = id.getInstallationPath();
         String[] exts = new String[]{"", ".zip", ".jar"};
@@ -115,6 +120,7 @@ public class JcrPackageManagerImpl exten
         return null;
     }
 
+    @Override
     public JcrPackage open(Node node) throws RepositoryException {
         return open(node, false);
     }
@@ -122,8 +128,9 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public JcrPackage open(Node node, boolean allowInvalid) throws RepositoryException {
-        JcrPackage pack = new JcrPackageImpl(node);
+        JcrPackage pack = new JcrPackageImpl(this, node);
         if (pack.isValid()) {
             return pack;
         } else if (allowInvalid
@@ -138,6 +145,7 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public PackageId resolve(Dependency dependency, boolean onlyInstalled) throws RepositoryException {
         if (!getPackageRoot().hasNode(dependency.getGroup())) {
             return null;
@@ -150,7 +158,7 @@ public class JcrPackageManagerImpl exten
             if (".snapshot".equals(child.getName())) {
                 continue;
             }
-            JcrPackageImpl pack = new JcrPackageImpl(child);
+            JcrPackageImpl pack = new JcrPackageImpl(this, child);
             if (pack.isValid()) {
                 if (onlyInstalled && !pack.isInstalled()) {
                     continue;
@@ -170,6 +178,27 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
+    public PackageId[] usage(PackageId id) throws RepositoryException {
+        TreeSet<PackageId> usages = new TreeSet<PackageId>();
+        for (JcrPackage p: listPackages()) {
+            if (!p.isInstalled()) {
+                continue;
+            }
+            for (Dependency dep: p.getDefinition().getDependencies()) {
+                if (dep.matches(id)) {
+                    usages.add(p.getDefinition().getId());
+                    break;
+                }
+            }
+        }
+        return usages.toArray(new PackageId[usages.size()]);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
     public JcrPackage upload(InputStream in, boolean replace) throws RepositoryException, IOException {
         return upload(in, replace, false);
     }
@@ -177,6 +206,7 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public JcrPackage upload(InputStream in, boolean replace, boolean strict)
             throws RepositoryException, IOException {
 
@@ -227,7 +257,7 @@ public class JcrPackageManagerImpl exten
         JcrPackageDefinitionImpl.State state = null;
 
         if (parent.hasNode(name)) {
-            JcrPackage oldPackage = new JcrPackageImpl(parent.getNode(name));
+            JcrPackage oldPackage = new JcrPackageImpl(this, parent.getNode(name));
             JcrPackageDefinitionImpl oldDef = (JcrPackageDefinitionImpl) oldPackage.getDefinition();
             if (oldDef != null) {
                 state = oldDef.getState();
@@ -241,7 +271,7 @@ public class JcrPackageManagerImpl exten
         }
         JcrPackage jcrPack = null;
         try {
-            jcrPack = JcrPackageImpl.createNew(parent, pid, bin, archive);
+            jcrPack = createNew(parent, pid, bin, archive);
             if (jcrPack != null) {
                 JcrPackageDefinitionImpl def = (JcrPackageDefinitionImpl) jcrPack.getDefinition();
                 if (state != null) {
@@ -262,6 +292,7 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public JcrPackage upload(File file, boolean isTmpFile, boolean replace, String nameHint)
             throws RepositoryException, IOException {
         return upload(file, isTmpFile, replace, nameHint, false);
@@ -270,6 +301,7 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public JcrPackage upload(File file, boolean isTmpFile, boolean replace, String nameHint, boolean strict)
             throws RepositoryException, IOException {
 
@@ -307,7 +339,7 @@ public class JcrPackageManagerImpl exten
         JcrPackageDefinitionImpl.State state = null;
 
         if (parent.hasNode(name)) {
-            JcrPackage oldPackage = new JcrPackageImpl(parent.getNode(name));
+            JcrPackage oldPackage = new JcrPackageImpl(this, parent.getNode(name));
             JcrPackageDefinitionImpl oldDef = (JcrPackageDefinitionImpl) oldPackage.getDefinition();
             if (oldDef != null) {
                 state = oldDef.getState();
@@ -321,7 +353,7 @@ public class JcrPackageManagerImpl exten
         }
         JcrPackage jcrPack = null;
         try {
-            jcrPack = JcrPackageImpl.createNew(parent, pid, pack, false);
+            jcrPack = createNew(parent, pid, pack, false);
             if (jcrPack != null) {
                 JcrPackageDefinitionImpl def = (JcrPackageDefinitionImpl) jcrPack.getDefinition();
                 if (state != null) {
@@ -341,17 +373,19 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public JcrPackage create(Node folder, String name)
             throws RepositoryException, IOException {
         if (folder == null) {
             folder = getPackageRoot();
         }
-        return JcrPackageImpl.createNew(folder, new PackageId(name), null, true);
+        return createNew(folder, new PackageId(name), null, true);
     }
 
     /**
      * {@inheritDoc}
      */
+    @Override
     public JcrPackage create(String group, String name)
             throws RepositoryException, IOException {
         return create(group, name, null);
@@ -360,6 +394,7 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public JcrPackage create(String group, String name, String version)
             throws RepositoryException, IOException {
         // sanitize name
@@ -372,16 +407,91 @@ public class JcrPackageManagerImpl exten
         }
         PackageId pid = new PackageId(group, name, version);
         Node folder = mkdir(Text.getRelativeParent(pid.getInstallationPath(), 1), false);
+        return createNew(folder, pid, null, true);
+    }
+
+    /**
+     * Creates a new jcr vault package.
+     *
+     * @param parent the parent node
+     * @param pid the package id of the new package.
+     * @param pack the underlying zip package or null.
+     * @param autoSave if {@code true} the changes are persisted immediately
+     * @return the created jcr vault package.
+     * @throws RepositoryException if an repository error occurs
+     * @throws IOException if an I/O error occurs
+     *
+     * @since 2.3.0
+     */
+    public JcrPackage createNew(Node parent, PackageId pid, VaultPackage pack, boolean autoSave)
+            throws RepositoryException, IOException {
+        Node node = parent.addNode(Text.getName(pid.getInstallationPath() + ".zip"), JcrConstants.NT_FILE);
+        Node content = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
+        content.addMixin(JcrPackage.NT_VLT_PACKAGE);
+        Node defNode = content.addNode(JcrPackage.NN_VLT_DEFINITION);
+        JcrPackageDefinition def = new JcrPackageDefinitionImpl(defNode);
+        def.set(JcrPackageDefinition.PN_NAME, pid.getName(), false);
+        def.set(JcrPackageDefinition.PN_GROUP, pid.getGroup(), false);
+        def.set(JcrPackageDefinition.PN_VERSION, pid.getVersionString(), false);
+        def.touch(null, false);
+        content.setProperty(JcrConstants.JCR_LASTMODIFIED, Calendar.getInstance());
+        content.setProperty(JcrConstants.JCR_MIMETYPE, JcrPackage.MIME_TYPE);
+        InputStream in = new ByteArrayInputStream(new byte[0]);
         try {
-            return JcrPackageImpl.createNew(folder, pid, null, false);
+            if (pack != null && pack.getFile() != null) {
+                in = FileUtils.openInputStream(pack.getFile());
+            }
+            // stay jcr 1.0 compatible
+            //noinspection deprecation
+            content.setProperty(JcrConstants.JCR_DATA, in);
+            if (pack != null) {
+                def.unwrap(pack, true, false);
+            }
+            if (autoSave) {
+                parent.getSession().save();
+            }
         } finally {
-            session.save();
+            IOUtils.closeQuietly(in);
         }
+        return new JcrPackageImpl(this, node, (ZipVaultPackage) pack);
+    }
+
+    /**
+     * Creates a new jcr vault package.
+     *
+     * @param parent the parent node
+     * @param pid the package id of the new package.
+     * @param bin the binary containing the zip
+     * @param archive the archive with the meta data
+     * @return the created jcr vault package.
+     * @throws RepositoryException if an repository error occurs
+     * @throws IOException if an I/O error occurs
+     *
+     * @since 3.1
+     */
+    public JcrPackage createNew(Node parent, PackageId pid, Binary bin, MemoryArchive archive)
+            throws RepositoryException, IOException {
+        Node node = parent.addNode(Text.getName(pid.getInstallationPath() + ".zip"), JcrConstants.NT_FILE);
+        Node content = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
+        content.addMixin(JcrPackage.NT_VLT_PACKAGE);
+        Node defNode = content.addNode(JcrPackage.NN_VLT_DEFINITION);
+        JcrPackageDefinitionImpl def = new JcrPackageDefinitionImpl(defNode);
+        def.set(JcrPackageDefinition.PN_NAME, pid.getName(), false);
+        def.set(JcrPackageDefinition.PN_GROUP, pid.getGroup(), false);
+        def.set(JcrPackageDefinition.PN_VERSION, pid.getVersionString(), false);
+        def.touch(null, false);
+        content.setProperty(JcrConstants.JCR_LASTMODIFIED, Calendar.getInstance());
+        content.setProperty(JcrConstants.JCR_MIMETYPE, JcrPackage.MIME_TYPE);
+        content.setProperty(JcrConstants.JCR_DATA, bin);
+        def.unwrap(archive, false);
+        return new JcrPackageImpl(this, node);
     }
 
+
     /**
      * {@inheritDoc}
      */
+    @Override
     public void remove(JcrPackage pack) throws RepositoryException {
         JcrPackage snap = pack.getSnapshot();
         if (snap != null) {
@@ -394,6 +504,7 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public JcrPackage rename(JcrPackage pack, String group, String name)
             throws PackageException, RepositoryException {
         return rename(pack, group, name, null);
@@ -402,6 +513,7 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public JcrPackage rename(JcrPackage pack, String group, String name, String version)
             throws PackageException, RepositoryException {
         if (!pack.isValid()) {
@@ -446,6 +558,7 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public void assemble(JcrPackage pack, ProgressTrackerListener listener)
             throws PackageException, RepositoryException, IOException {
         pack.verifyId(true, true);
@@ -455,6 +568,7 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public void assemble(Node packNode, JcrPackageDefinition definition,
                          ProgressTrackerListener listener)
             throws PackageException, RepositoryException, IOException {
@@ -508,6 +622,7 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public void assemble(JcrPackageDefinition definition,
                          ProgressTrackerListener listener, OutputStream out)
             throws IOException, RepositoryException, PackageException {
@@ -527,6 +642,7 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public void rewrap(JcrPackage pack, ProgressTrackerListener listener)
             throws PackageException, RepositoryException, IOException {
         VaultPackage src = ((JcrPackageImpl) pack).getPackage(true);
@@ -565,6 +681,7 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public Node getPackageRoot() throws RepositoryException {
         return getPackageRoot(false);
     }
@@ -637,6 +754,7 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public Node getPackageRoot(boolean noCreate) throws RepositoryException {
         if (packRoot == null) {
             if (session.nodeExists(PACKAGE_ROOT_PATH)) {
@@ -671,6 +789,7 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public List<JcrPackage> listPackages() throws RepositoryException {
         return listPackages(null);
     }
@@ -678,6 +797,7 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public List<JcrPackage> listPackages(WorkspaceFilter filter) throws RepositoryException {
         Node root = getPackageRoot(true);
         if (root == null) {
@@ -693,6 +813,7 @@ public class JcrPackageManagerImpl exten
     /**
      * {@inheritDoc}
      */
+    @Override
     public List<JcrPackage> listPackages(String group, boolean built) throws RepositoryException {
         Node pRoot = getPackageRoot(true);
         if (pRoot == null) {
@@ -746,7 +867,7 @@ public class JcrPackageManagerImpl exten
                 if (".snapshot".equals(child.getName())) {
                     continue;
                 }
-                JcrPackageImpl pack = new JcrPackageImpl(child);
+                JcrPackageImpl pack = new JcrPackageImpl(this, child);
                 if (pack.isValid()) {
                     // skip packages with illegal names
                     JcrPackageDefinition jDef = pack.getDefinition();

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackagingImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackagingImpl.java?rev=1767220&r1=1767219&r2=1767220&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackagingImpl.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackagingImpl.java Mon Oct 31 06:29:35 2016
@@ -27,12 +27,11 @@ import org.apache.jackrabbit.vault.packa
 import org.apache.jackrabbit.vault.packaging.JcrPackageManager;
 import org.apache.jackrabbit.vault.packaging.PackageManager;
 import org.apache.jackrabbit.vault.packaging.Packaging;
-import org.apache.jackrabbit.vault.util.JcrConstants;
 
 /**
  * {@code PackagingImpl}...
  */
-@Component(metatype = false, immediate = true)
+@Component(immediate = true)
 @Service(value = Packaging.class)
 public class PackagingImpl implements Packaging {
 
@@ -66,15 +65,7 @@ public class PackagingImpl implements Pa
      * {@inheritDoc}
      */
     public JcrPackage open(Node node, boolean allowInvalid) throws RepositoryException {
-        JcrPackage pack = new JcrPackageImpl(node);
-        if (pack.isValid()) {
-            return pack;
-        } else if (allowInvalid
-                && node.isNodeType(JcrConstants.NT_HIERARCHYNODE)
-                && node.hasProperty(JcrConstants.JCR_CONTENT + "/" + JcrConstants.JCR_DATA)) {
-            return pack;
-        } else {
-            return null;
-        }
+        JcrPackageManager pMgr = getPackageManager(node.getSession());
+        return pMgr.open(node, allowInvalid);
     }
 }
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestEnforcedDependencies.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestEnforcedDependencies.java?rev=1767220&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestEnforcedDependencies.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestEnforcedDependencies.java Mon Oct 31 06:29:35 2016
@@ -0,0 +1,474 @@
+/*
+ * 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.jackrabbit.vault.packaging.integration;
+
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.vault.fs.io.ImportOptions;
+import org.apache.jackrabbit.vault.packaging.CyclicDependencyException;
+import org.apache.jackrabbit.vault.packaging.Dependency;
+import org.apache.jackrabbit.vault.packaging.DependencyException;
+import org.apache.jackrabbit.vault.packaging.DependencyHandling;
+import org.apache.jackrabbit.vault.packaging.JcrPackage;
+import org.apache.jackrabbit.vault.packaging.PackageException;
+import org.apache.jackrabbit.vault.packaging.PackageId;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests that cover installation and uninstallation with enforced dependency checks.
+ */
+public class TestEnforcedDependencies extends IntegrationTestBase {
+
+    /**
+     * Test package A-1.0. Depends on B and C-1.X
+     */
+    private static String TEST_PACKAGE_A_10 = "testpackages/test_a-1.0.zip";
+
+    /**
+     * Test package A-2.0. Depends on B and C-2.X
+     */
+    private static String TEST_PACKAGE_A_20 = "testpackages/test_a-2.0.zip";
+
+    /**
+     * Test package B-1.0. Depends on C
+     */
+    private static String TEST_PACKAGE_B_10 = "testpackages/test_b-1.0.zip";
+
+    /**
+     * Test package C-1.0
+     */
+    private static String TEST_PACKAGE_C_10 = "testpackages/test_c-1.0.zip";
+
+    /**
+     * Test package C-1.1
+     */
+    private static String TEST_PACKAGE_C_11 = "testpackages/test_c-1.1.zip";
+
+    /**
+     * Test package C-2.0
+     */
+    private static String TEST_PACKAGE_C_20 = "testpackages/test_c-2.0.zip";
+
+    /**
+     * Test package D-1.0. Depends on B and E
+     */
+    private static String TEST_PACKAGE_D_10 = "testpackages/test_d-1.0.zip";
+
+    /**
+     * Test package E-1.0. Depends on D
+     */
+    private static String TEST_PACKAGE_E_10 = "testpackages/test_e-1.0.zip";
+
+    /**
+     * Tests if dependencies are ignored by default
+     */
+    @Test
+    public void testIgnoredDependencies() throws RepositoryException, IOException, PackageException {
+        JcrPackage a1 = installPackage(TEST_PACKAGE_A_10);
+        assertProperty("/tmp/a/version", "1.0");
+        JcrPackage a2= installPackage(TEST_PACKAGE_A_20);
+        assertProperty("/tmp/a/version", "2.0");
+        JcrPackage b1 = installPackage(TEST_PACKAGE_B_10);
+        assertProperty("/tmp/b/version", "1.0");
+        JcrPackage c1 = installPackage(TEST_PACKAGE_C_10);
+        assertProperty("/tmp/c/version", "1.0");
+
+        c1.uninstall(getDefaultOptions());
+        assertNodeMissing("/tmp/c");
+
+        b1.uninstall(getDefaultOptions());
+        assertNodeMissing("/tmp/b");
+
+        a2.uninstall(getDefaultOptions());
+        assertProperty("/tmp/a/version", "1.0");
+
+        a1.uninstall(getDefaultOptions());
+        assertNodeMissing("/tmp/a");
+    }
+
+    /**
+     * Test unresolved calculation
+     */
+    @Test
+    public void testUnresolved() throws IOException, RepositoryException {
+        JcrPackage a1 = packMgr.upload(getStream(TEST_PACKAGE_A_10), false);
+        assertNotNull(a1);
+        Dependency[] deps = a1.getUnresolvedDependencies();
+        assertEquals("package must report unresolved dependencies", "my_packages:test_b,my_packages:test_c:[1.0,2.0)", Dependency.toString(deps));
+
+    }
+
+    /**
+     * Test if installing B fails if C is missing.
+     */
+    @Test
+    public void testInstallDepMissing() throws IOException, RepositoryException, PackageException {
+        JcrPackage b1 = packMgr.upload(getStream(TEST_PACKAGE_B_10), false);
+        assertNotNull(b1);
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.STRICT);
+        try {
+            b1.install(opts);
+            fail("Installing with missing dependency must fail.");
+        } catch (DependencyException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Test if installing A fails if C is missing.
+     */
+    @Test
+    public void testInstallDepMissingRequired() throws IOException, RepositoryException, PackageException {
+        JcrPackage b1 = packMgr.upload(getStream(TEST_PACKAGE_B_10), false);
+        assertNotNull(b1);
+
+        JcrPackage a1 = packMgr.upload(getStream(TEST_PACKAGE_A_10), false);
+        assertNotNull(a1);
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.REQUIRED);
+        try {
+            a1.install(opts);
+            fail("Installing with missing dependency must fail.");
+        } catch (DependencyException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Test if installing B fails if C is loaded but not installed
+     */
+    @Test
+    public void testInstallDepUninstalled() throws IOException, RepositoryException, PackageException {
+        packMgr.upload(getStream(TEST_PACKAGE_C_10), false);
+        assertNodeMissing("/tmp/c/");
+        JcrPackage b1 = packMgr.upload(getStream(TEST_PACKAGE_B_10), false);
+        assertNotNull(b1);
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.STRICT);
+
+        try {
+            b1.install(opts);
+            fail("Installing with uninstalled dependency must fail.");
+        } catch (DependencyException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Test if installing B automatically installs C
+     */
+    @Test
+    public void testInstallDepInstallsRequired() throws IOException, RepositoryException, PackageException {
+        packMgr.upload(getStream(TEST_PACKAGE_C_10), false);
+        assertNodeMissing("/tmp/c/");
+        JcrPackage b1 = packMgr.upload(getStream(TEST_PACKAGE_B_10), false);
+        assertNotNull(b1);
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.REQUIRED);
+
+        b1.install(opts);
+        assertProperty("/tmp/b/version", "1.0");
+        assertProperty("/tmp/c/version", "1.0");
+    }
+
+    /**
+     * Test if installing A-2.0 automatically installs B and C-2.0
+     */
+    @Test
+    public void testInstallDepInstallsAll() throws IOException, RepositoryException, PackageException {
+        packMgr.upload(getStream(TEST_PACKAGE_C_10), false);
+        packMgr.upload(getStream(TEST_PACKAGE_C_11), false);
+        packMgr.upload(getStream(TEST_PACKAGE_C_20), false);
+        packMgr.upload(getStream(TEST_PACKAGE_B_10), false);
+        assertNodeMissing("/tmp/b/");
+        assertNodeMissing("/tmp/c/");
+        JcrPackage a2 = packMgr.upload(getStream(TEST_PACKAGE_A_20), false);
+        assertNotNull(a2);
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.REQUIRED);
+
+        a2.install(opts);
+        assertProperty("/tmp/a/version", "2.0");
+        assertProperty("/tmp/b/version", "1.0");
+        assertProperty("/tmp/c/version", "2.0");
+    }
+
+    /**
+     * Test if installing D automatically installs B and C
+     */
+    @Test
+    public void testInstallDeep() throws IOException, RepositoryException, PackageException {
+        packMgr.upload(getStream(TEST_PACKAGE_C_10), false);
+        packMgr.upload(getStream(TEST_PACKAGE_B_10), false);
+        assertNodeMissing("/tmp/b/");
+        assertNodeMissing("/tmp/c/");
+        JcrPackage d1 = packMgr.upload(getStream(TEST_PACKAGE_D_10), false);
+        assertNotNull(d1);
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.BEST_EFFORT);
+
+        d1.install(opts);
+        assertProperty("/tmp/d/version", "1.0");
+        assertProperty("/tmp/b/version", "1.0");
+        assertProperty("/tmp/c/version", "1.0");
+    }
+
+    /**
+     * Test if installing D with E causes cyclic error for REQUIRED
+     */
+    @Test
+    public void testInstallCyclicFails() throws IOException, RepositoryException, PackageException {
+        packMgr.upload(getStream(TEST_PACKAGE_B_10), false);
+        packMgr.upload(getStream(TEST_PACKAGE_C_10), false);
+        packMgr.upload(getStream(TEST_PACKAGE_E_10), false);
+        JcrPackage d1 = packMgr.upload(getStream(TEST_PACKAGE_D_10), false);
+        assertNotNull(d1);
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.REQUIRED);
+
+        try {
+            d1.install(opts);
+            fail("installing D -> E -> D should cause cyclic dependency exception.");
+        } catch (CyclicDependencyException e) {
+            // ok
+        }
+    }
+
+    /**
+     * Test if installing D with E does not cause cyclic error for BEST_EFFORT
+     */
+    @Test
+    public void testInstallCyclicSucceeds() throws IOException, RepositoryException, PackageException {
+        packMgr.upload(getStream(TEST_PACKAGE_B_10), false);
+        packMgr.upload(getStream(TEST_PACKAGE_C_10), false);
+        packMgr.upload(getStream(TEST_PACKAGE_E_10), false);
+        JcrPackage d1 = packMgr.upload(getStream(TEST_PACKAGE_D_10), false);
+        assertNotNull(d1);
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.BEST_EFFORT);
+
+        d1.install(opts);
+        assertProperty("/tmp/b/version", "1.0");
+        assertProperty("/tmp/c/version", "1.0");
+        assertProperty("/tmp/d/version", "1.0");
+        assertProperty("/tmp/e/version", "1.0");
+    }
+
+    /**
+     * Test if installing A-1.0 automatically installs B and C-1.1
+     */
+    @Test
+    public void testInstallDepInstallsCorrectVersion() throws IOException, RepositoryException, PackageException {
+        packMgr.upload(getStream(TEST_PACKAGE_C_10), false);
+        packMgr.upload(getStream(TEST_PACKAGE_C_11), false);
+        packMgr.upload(getStream(TEST_PACKAGE_C_20), false);
+        packMgr.upload(getStream(TEST_PACKAGE_B_10), false);
+        assertNodeMissing("/tmp/b/");
+        assertNodeMissing("/tmp/c/");
+        JcrPackage b1 = packMgr.upload(getStream(TEST_PACKAGE_A_10), false);
+        assertNotNull(b1);
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.REQUIRED);
+
+        b1.install(opts);
+        assertProperty("/tmp/a/version", "1.0");
+        assertProperty("/tmp/b/version", "1.0");
+        assertProperty("/tmp/c/version", "1.1");
+    }
+
+    /**
+     * Test if installing besteffort works
+     */
+    @Test
+    public void testInstallDepInstallsBestEffort() throws IOException, RepositoryException, PackageException {
+        packMgr.upload(getStream(TEST_PACKAGE_C_10), false);
+        assertNodeMissing("/tmp/c/");
+        JcrPackage b1 = packMgr.upload(getStream(TEST_PACKAGE_A_10), false);
+        assertNotNull(b1);
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.BEST_EFFORT);
+
+        b1.install(opts);
+        assertProperty("/tmp/a/version", "1.0");
+        assertProperty("/tmp/c/version", "1.0");
+    }
+
+    /**
+     * Test if installing B succeeds if C is installed
+     */
+    @Test
+    public void testInstallDepInstalled() throws IOException, RepositoryException, PackageException {
+        installPackage(TEST_PACKAGE_C_10);
+        assertProperty("/tmp/c/version", "1.0");
+        JcrPackage b1 = packMgr.upload(getStream(TEST_PACKAGE_B_10), false);
+        assertNotNull(b1);
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.STRICT);
+        b1.install(opts);
+        assertProperty("/tmp/b/version", "1.0");
+    }
+
+    /**
+     * Test if installing A fails if C has the wrong version
+     */
+    @Test
+    public void testInstallWrongVersion() throws IOException, RepositoryException, PackageException {
+        installPackage(TEST_PACKAGE_C_10);
+        assertProperty("/tmp/c/version", "1.0");
+
+        JcrPackage a2 = packMgr.upload(getStream(TEST_PACKAGE_A_20), false);
+        assertNotNull(a2);
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.STRICT);
+
+        try {
+            a2.install(opts);
+            fail("Installing with wrong installed version dependency must fail.");
+        } catch (DependencyException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Test if installing A succeeds if C has correct version
+     */
+    @Test
+    public void testInstallCorrectVersion() throws IOException, RepositoryException, PackageException {
+        installPackage(TEST_PACKAGE_B_10);
+        assertProperty("/tmp/b/version", "1.0");
+        installPackage(TEST_PACKAGE_C_11);
+        assertProperty("/tmp/c/version", "1.1");
+
+        JcrPackage a1 = packMgr.upload(getStream(TEST_PACKAGE_A_10), false);
+        assertNotNull(a1);
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.STRICT);
+
+        a1.install(opts);
+        assertProperty("/tmp/a/version", "1.0");
+    }
+
+    /**
+     * Test if un-installing C fails if B is still installed
+     */
+    @Test
+    public void testUninstallStrict() throws IOException, RepositoryException, PackageException {
+        JcrPackage c1 = installPackage(TEST_PACKAGE_C_10);
+        assertProperty("/tmp/c/version", "1.0");
+        installPackage(TEST_PACKAGE_B_10);
+        assertProperty("/tmp/b/version", "1.0");
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.STRICT);
+
+        try {
+            c1.uninstall(opts);
+            fail("Uninstalling must fail if another package still requires it.");
+        } catch (DependencyException e) {
+            // expected
+        }
+    }
+
+    /**
+     * Test if un-installing C auto-uninstalls A and B for BEST_EFFORT
+     */
+    @Test
+    public void testUninstallBestEffort() throws IOException, RepositoryException, PackageException {
+        installPackage(TEST_PACKAGE_A_10);
+        installPackage(TEST_PACKAGE_B_10);
+        JcrPackage c1 = installPackage(TEST_PACKAGE_C_10);
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.BEST_EFFORT);
+
+        c1.uninstall(opts);
+        assertNodeMissing("/tmp/a");
+        assertNodeMissing("/tmp/b");
+        assertNodeMissing("/tmp/c");
+    }
+
+    /**
+     * Test if un-installing C auto-uninstalls A and B for REQUIRED
+     */
+    @Test
+    public void testUninstallRequired() throws IOException, RepositoryException, PackageException {
+        installPackage(TEST_PACKAGE_A_10);
+        installPackage(TEST_PACKAGE_B_10);
+        JcrPackage c1 = installPackage(TEST_PACKAGE_C_10);
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.REQUIRED);
+
+        c1.uninstall(opts);
+        assertNodeMissing("/tmp/a");
+        assertNodeMissing("/tmp/b");
+        assertNodeMissing("/tmp/c");
+    }
+
+    /**
+     * Test if uninstalling D with E does not causes cyclic error
+     */
+    @Test
+    public void testUnInstallCyclicSucceeds() throws IOException, RepositoryException, PackageException {
+        installPackage(TEST_PACKAGE_D_10);
+        JcrPackage e1 = installPackage(TEST_PACKAGE_E_10);
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.REQUIRED);
+
+        e1.uninstall(opts);
+        assertNodeMissing("/tmp/e");
+        assertNodeMissing("/tmp/d");
+    }
+
+
+    /**
+     * Tests package manager usage method
+     */
+    @Test
+    public void testUsage() throws RepositoryException, IOException, PackageException {
+        installPackage(TEST_PACKAGE_A_20);
+        installPackage(TEST_PACKAGE_B_10);
+        JcrPackage c1 = installPackage(TEST_PACKAGE_C_20);
+
+        PackageId[] usage = packMgr.usage(c1.getDefinition().getId());
+        assertEquals("correct usage", "my_packages:test_a:2.0,my_packages:test_b:1.0", PackageId.toString(usage));
+    }
+
+
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_a-1.0.zip
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_a-1.0.zip?rev=1767220&view=auto
==============================================================================
Binary files jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_a-1.0.zip (added) and jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_a-1.0.zip Mon Oct 31 06:29:35 2016 differ

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_a-2.0.zip
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_a-2.0.zip?rev=1767220&view=auto
==============================================================================
Binary files jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_a-2.0.zip (added) and jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_a-2.0.zip Mon Oct 31 06:29:35 2016 differ

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_b-1.0.zip
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_b-1.0.zip?rev=1767220&view=auto
==============================================================================
Binary files jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_b-1.0.zip (added) and jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_b-1.0.zip Mon Oct 31 06:29:35 2016 differ

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_c-1.0.zip
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_c-1.0.zip?rev=1767220&view=auto
==============================================================================
Binary files jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_c-1.0.zip (added) and jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_c-1.0.zip Mon Oct 31 06:29:35 2016 differ

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_c-1.1.zip
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_c-1.1.zip?rev=1767220&view=auto
==============================================================================
Binary files jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_c-1.1.zip (added) and jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_c-1.1.zip Mon Oct 31 06:29:35 2016 differ

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_c-2.0.zip
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_c-2.0.zip?rev=1767220&view=auto
==============================================================================
Binary files jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_c-2.0.zip (added) and jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_c-2.0.zip Mon Oct 31 06:29:35 2016 differ

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_d-1.0.zip
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_d-1.0.zip?rev=1767220&view=auto
==============================================================================
Binary files jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_d-1.0.zip (added) and jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_d-1.0.zip Mon Oct 31 06:29:35 2016 differ

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_e-1.0.zip
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_e-1.0.zip?rev=1767220&view=auto
==============================================================================
Binary files jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_e-1.0.zip (added) and jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/test_e-1.0.zip Mon Oct 31 06:29:35 2016 differ



Mime
View raw message