jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1855285 - in /jackrabbit/commons/filevault/trunk/vault-core/src: main/java/org/apache/jackrabbit/vault/packaging/impl/ main/java/org/apache/jackrabbit/vault/packaging/registry/impl/ test/java/org/apache/jackrabbit/vault/packaging/integration/
Date Tue, 12 Mar 2019 05:45:57 GMT
Author: tripod
Date: Tue Mar 12 05:45:57 2019
New Revision: 1855285

URL: http://svn.apache.org/viewvc?rev=1855285&view=rev
Log:
JCRVLT-332 - adding support to JcrPackageRegistry to resolve dependencies from FsPackReg (closes
#41)

Added:
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestCrossRegistryDependencies.java
Modified:
    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/PackagingImpl.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/registry/impl/JcrPackageRegistry.java

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=1855285&r1=1855284&r2=1855285&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
Tue Mar 12 05:45:57 2019
@@ -73,6 +73,7 @@ import org.apache.jackrabbit.vault.packa
 import org.apache.jackrabbit.vault.packaging.VaultPackage;
 import org.apache.jackrabbit.vault.packaging.Version;
 import org.apache.jackrabbit.vault.packaging.events.PackageEvent;
+import org.apache.jackrabbit.vault.packaging.registry.RegisteredPackage;
 import org.apache.jackrabbit.vault.packaging.registry.impl.JcrPackageRegistry;
 import org.apache.jackrabbit.vault.packaging.registry.impl.JcrRegisteredPackage;
 import org.apache.jackrabbit.vault.util.JcrConstants;
@@ -757,17 +758,17 @@ public class JcrPackageImpl implements J
             return;
         }
         List<Dependency> unresolved = new LinkedList<Dependency>();
-        List<JcrPackageImpl> uninstalled = new LinkedList<JcrPackageImpl>();
+        List<RegisteredPackage> uninstalled = new LinkedList<RegisteredPackage>();
         for (Dependency dep: def.getDependencies()) {
             // resolve to installed and uninstalled packages
             PackageId id = mgr.resolve(dep, false);
             if (id == null) {
                 unresolved.add(dep);
             } else {
-                JcrRegisteredPackage pack = (JcrRegisteredPackage) mgr.open(id);
+                RegisteredPackage pack = (RegisteredPackage) mgr.open(id);
                 if (pack != null && !pack.isInstalled()) {
                     unresolved.add(dep);
-                    uninstalled.add((JcrPackageImpl) pack.getJcrPackage());
+                    uninstalled.add(pack);
                 }
             }
         }
@@ -783,11 +784,11 @@ public class JcrPackageImpl implements J
             throw new DependencyException(msg);
         }
 
-        for (JcrPackageImpl pack: uninstalled) {
+        for (RegisteredPackage pack: uninstalled) {
             if (pack.isInstalled()) {
                 continue;
             }
-            PackageId packageId = pack.getDefinition().getId();
+            PackageId packageId = pack.getId();
             if (processed.contains(packageId)) {
                 if (opts.getDependencyHandling() == DependencyHandling.BEST_EFFORT) {
                     continue;
@@ -796,7 +797,14 @@ public class JcrPackageImpl implements J
                 log.error(msg);
                 throw new CyclicDependencyException(msg);
             }
-            pack.extract(processed, opts, createSnapshot, replaceSnapshot);
+            if (pack instanceof JcrRegisteredPackage) {
+                JcrPackage jcrPackage = ((JcrRegisteredPackage)pack).getJcrPackage();
+                ((JcrPackageImpl)jcrPackage).extract(processed, opts, createSnapshot, replaceSnapshot);
+            } else {
+                String msg = String.format("Unable to install package %s. dependency not
found in JcrPackageRegistry %s", def.getId(), packageId);
+                log.error(msg);
+                throw new DependencyException(msg);
+            }
         }
     }
 

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=1855285&r1=1855284&r2=1855285&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
Tue Mar 12 05:45:57 2019
@@ -28,9 +28,11 @@ import org.apache.jackrabbit.vault.packa
 import org.apache.jackrabbit.vault.packaging.PackageManager;
 import org.apache.jackrabbit.vault.packaging.Packaging;
 import org.apache.jackrabbit.vault.packaging.events.impl.PackageEventDispatcher;
+import org.apache.jackrabbit.vault.packaging.registry.PackageRegistry;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
 import org.osgi.service.metatype.annotations.AttributeDefinition;
 import org.osgi.service.metatype.annotations.Designate;
 import org.osgi.service.metatype.annotations.ObjectClassDefinition;
@@ -55,6 +57,12 @@ public class PackagingImpl implements Pa
 
     @Reference
     private PackageEventDispatcher eventDispatcher;
+    
+    // In case a PackageRegistry is exposed as OSGi Service this will be considered
+    // as base registry to fall back for dependency checks - currently only FSPackageRegistry
is exposed as such
+    // currently no support for multiple registered PackageRegistries (OSGi Framework will
will pick first found)
+    @Reference (cardinality = ReferenceCardinality.OPTIONAL)
+    private PackageRegistry baseRegistry = null;
 
     /**
      * package manager is a singleton
@@ -98,6 +106,7 @@ public class PackagingImpl implements Pa
     public JcrPackageManager getPackageManager(Session session) {
         JcrPackageManagerImpl mgr = new JcrPackageManagerImpl(session, packageRoots);
         mgr.setDispatcher(eventDispatcher);
+        mgr.getInternalRegistry().setBaseRegistry(baseRegistry);
         return mgr;
     }
 

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/registry/impl/JcrPackageRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/registry/impl/JcrPackageRegistry.java?rev=1855285&r1=1855284&r2=1855285&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/registry/impl/JcrPackageRegistry.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/registry/impl/JcrPackageRegistry.java
Tue Mar 12 05:45:57 2019
@@ -27,8 +27,6 @@ import java.util.List;
 import java.util.Properties;
 import java.util.Set;
 import java.util.TreeSet;
-import java.util.UUID;
-
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.jcr.Binary;
@@ -63,8 +61,6 @@ import org.apache.jackrabbit.vault.packa
 import org.apache.jackrabbit.vault.packaging.impl.JcrPackageManagerImpl;
 import org.apache.jackrabbit.vault.packaging.impl.PackagePropertiesImpl;
 import org.apache.jackrabbit.vault.packaging.impl.ZipVaultPackage;
-import org.apache.jackrabbit.vault.packaging.registry.DependencyReport;
-import org.apache.jackrabbit.vault.packaging.registry.ExecutionPlanBuilder;
 import org.apache.jackrabbit.vault.packaging.registry.PackageRegistry;
 import org.apache.jackrabbit.vault.packaging.registry.RegisteredPackage;
 import org.apache.jackrabbit.vault.util.InputStreamPump;
@@ -115,6 +111,11 @@ public class JcrPackageRegistry extends
      * the package root prefix of the primary root path.
      */
     private final String primaryPackRootPathPrefix;
+    
+    /**
+     * Fallback Registry can be registered if present in the system to be able to look up
presatisfied dependencies
+     */
+    private PackageRegistry baseRegistry = null;
 
 
     /**
@@ -135,6 +136,13 @@ public class JcrPackageRegistry extends
     }
 
     /**
+     * Sets fallback PackageRegistry for dependency lookup
+     * @param baseRegisry
+     */
+    public void setBaseRegistry(@Nullable PackageRegistry baseRegisry) {
+        this.baseRegistry = baseRegisry;
+    }
+    /**
      * Sets the event dispatcher
      * @param dispatcher the dispatcher.
      */
@@ -241,6 +249,9 @@ public class JcrPackageRegistry extends
     public RegisteredPackage open(@Nonnull PackageId id) throws IOException {
         try {
             Node node = getPackageNode(id);
+            if (node == null && baseRegistry != null) {
+                return baseRegistry.open(id);
+            }
             return node == null ? null : new JcrRegisteredPackage(open(node, false));
         } catch (RepositoryException e) {
             throw new IOException(e);
@@ -250,7 +261,11 @@ public class JcrPackageRegistry extends
     @Override
     public boolean contains(@Nonnull PackageId id) throws IOException {
         try {
-            return getPackageNode(id) != null;
+            boolean result = getPackageNode(id) != null;
+            if (result == false && baseRegistry != null) {
+                result = baseRegistry.contains(id);
+            }
+            return result;
         } catch (RepositoryException e) {
             throw new IOException(e);
         }
@@ -319,6 +334,9 @@ public class JcrPackageRegistry extends
                         }
                     }
                 }
+            } 
+            if (bestId == null && baseRegistry != null) {
+                bestId = baseRegistry.resolve(dependency, onlyInstalled);
             }
             return bestId;
         } catch (RepositoryException e) {

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestCrossRegistryDependencies.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestCrossRegistryDependencies.java?rev=1855285&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestCrossRegistryDependencies.java
(added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestCrossRegistryDependencies.java
Tue Mar 12 05:45:57 2019
@@ -0,0 +1,76 @@
+/*
+ * 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.File;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.vault.fs.io.ImportOptions;
+import org.apache.jackrabbit.vault.packaging.DependencyHandling;
+import org.apache.jackrabbit.vault.packaging.PackageId;
+import org.apache.jackrabbit.vault.packaging.registry.impl.FSPackageRegistry;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test dependencies of JCR Packages on packages registered in FS Package registry
+ */
+public class TestCrossRegistryDependencies extends IntegrationTestBase {
+
+    private static final File DIR_REGISTRY_HOME = new File("target/registry");
+
+    private static final Logger log = LoggerFactory.getLogger(TestCrossRegistryDependencies.class);
+
+    private FSPackageRegistry fsregistry;
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        super.setUp();
+        if (DIR_REGISTRY_HOME.exists()) {
+            FileUtils.cleanDirectory(DIR_REGISTRY_HOME);
+        } else {
+            DIR_REGISTRY_HOME.mkdir();
+        }
+        fsregistry = new FSPackageRegistry(DIR_REGISTRY_HOME);
+        packMgr.getInternalRegistry().setBaseRegistry(fsregistry);
+
+        PackageId idB = fsregistry.register(getStream(TEST_PACKAGE_B_10), false);
+        PackageId idC = fsregistry.register(getStream(TEST_PACKAGE_C_10), false);
+        
+        ImportOptions opts = new ImportOptions();
+        opts.setDependencyHandling(DependencyHandling.STRICT);
+
+        fsregistry.installPackage(admin, fsregistry.open(idB), opts, true);
+        fsregistry.installPackage(admin, fsregistry.open(idC), opts, true);
+
+
+    }
+    
+    @Test
+    public void testCrossDependency() throws Exception {
+        PackageId idA = packMgr.getInternalRegistry().register(getStream(TEST_PACKAGE_A_10),
false);
+        ImportOptions opts = getDefaultOptions();
+        opts.setDependencyHandling(DependencyHandling.STRICT);
+        packMgr.open(idA).install(opts);
+
+    }
+
+}
\ No newline at end of file



Mime
View raw message