jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1738154 - in /jackrabbit/commons/filevault/trunk/vault-core/src: main/java/org/apache/jackrabbit/vault/packaging/impl/ test/java/org/apache/jackrabbit/vault/packaging/integration/ test/resources/org/apache/jackrabbit/vault/packaging/integr...
Date Thu, 07 Apr 2016 17:24:09 GMT
Author: tripod
Date: Thu Apr  7 17:24:08 2016
New Revision: 1738154

URL: http://svn.apache.org/viewvc?rev=1738154&view=rev
Log:
JCRVLT-113 Skip installation of sub packages if newer version is already present and installed

this closes #5

Added:
    jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/subtest_extract_contains_newer_version.zip
    jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/subtest_extract_contains_older_version.zip
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/test/java/org/apache/jackrabbit/vault/packaging/integration/TestSubPackages.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=1738154&r1=1738153&r2=1738154&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
Thu Apr  7 17:24:08 2016
@@ -47,10 +47,12 @@ import org.apache.jackrabbit.vault.packa
 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.PackageException;
 import org.apache.jackrabbit.vault.packaging.PackageId;
 import org.apache.jackrabbit.vault.packaging.SubPackageHandling;
 import org.apache.jackrabbit.vault.packaging.VaultPackage;
+import org.apache.jackrabbit.vault.packaging.Version;
 import org.apache.jackrabbit.vault.util.JcrConstants;
 import org.apache.jackrabbit.vault.util.Text;
 import org.slf4j.Logger;
@@ -441,7 +443,36 @@ public class JcrPackageImpl implements J
                     }
                 }
                 if (p.isValid()) {
-                    subPacks.add(p);
+                    PackageId pId = p.getPackage().getId();
+                    String pName = pId.getName();
+                    Version pVersion = pId.getVersion();
+
+                    // get the list of packages available in the same group
+                    JcrPackageManager pkgMgr = new JcrPackageManagerImpl(s);            
       
+                    List<JcrPackage> listPackages = pkgMgr.listPackages(pId.getGroup(),
true);
+
+                    // keep some status variable if a more recent is found in the next loop
+                    boolean foundMoreRecent = false;
+                    JcrPackage foundPackage = null;
+
+                    // loop in the list of packages returned previously by package manager
+                    for (JcrPackage listedPackage: listPackages) {
+                        PackageId listedPackageId = listedPackage.getPackage().getId();
+                        // check that the listed package is actually from same name (so normally
only version would differ)
+                        // if that package is valid, installed, and the version is more recent
than the one in our sub package
+                        // then we can stop the loop here
+                        if (listedPackageId.getName().equals(pName) && listedPackage.isValid()
&& listedPackage.isInstalled() && listedPackageId.getVersion().compareTo(pVersion)
== 1) {
+                            foundMoreRecent = true; 
+                            foundPackage = listedPackage;
+                            break;
+                        }
+                    }
+                    // if a more recent version of that subpackage was found we don't need
to add it to the list of sub packages to eventually extract later on.
+                    if (foundMoreRecent) {
+                        log.info("Skipping "+path+" installation due to newer version present
and installed at "+foundPackage.getNode().getPath());
+                    } else {
+                        subPacks.add(p);
+                    }
                 }
             }
         }

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestSubPackages.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestSubPackages.java?rev=1738154&r1=1738153&r2=1738154&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestSubPackages.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestSubPackages.java
Thu Apr  7 17:24:08 2016
@@ -26,7 +26,9 @@ import org.apache.jackrabbit.vault.packa
 import org.apache.jackrabbit.vault.packaging.PackageException;
 import org.junit.Test;
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 /**
  * Tests that covers sub packages. the package "my_packages:subtest" contains 2 sub packages
@@ -237,5 +239,30 @@ public class TestSubPackages extends Int
 
     }
 
+    /**
+     * Installs 2 packages that contains same sub packages with different version
+     */
+    @Test
+    public void testSkipOlderVersionInstallation() throws RepositoryException, IOException,
PackageException {
+        JcrPackage packNewer = packMgr.upload(getStream("testpackages/subtest_extract_contains_newer_version.zip"),
false);
+        assertNotNull(packNewer);
+
+        // install package that contains newer version of the sub package first
+        ImportOptions opts = getDefaultOptions();
+        opts.setNonRecursive(false);
+        packNewer.install(opts);
+
+        // check for sub packages version 1.0.1 exists
+        assertNodeExists("/etc/packages/my_packages/subtest_test_version-1.0.1.zip");
+        assertTrue(packMgr.open(admin.getNode("/etc/packages/my_packages/subtest_test_version-1.0.1.zip")).isInstalled());
+        assertNodeExists("/tmp/b");
+
+        JcrPackage packOlder = packMgr.upload(getStream("testpackages/subtest_extract_contains_older_version.zip"),
false);
+        packOlder.install(opts);
+        assertNodeExists("/etc/packages/my_packages/subtest_test_version-1.0.zip");
+        assertFalse(packMgr.open(admin.getNode("/etc/packages/my_packages/subtest_test_version-1.0.zip")).isInstalled());
+        assertNodeMissing("/tmp/a");
+
+    }
 
 }
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/subtest_extract_contains_newer_version.zip
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/subtest_extract_contains_newer_version.zip?rev=1738154&view=auto
==============================================================================
Binary files jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/subtest_extract_contains_newer_version.zip
(added) and jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/subtest_extract_contains_newer_version.zip
Thu Apr  7 17:24:08 2016 differ

Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/subtest_extract_contains_older_version.zip
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/subtest_extract_contains_older_version.zip?rev=1738154&view=auto
==============================================================================
Binary files jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/subtest_extract_contains_older_version.zip
(added) and jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/integration/testpackages/subtest_extract_contains_older_version.zip
Thu Apr  7 17:24:08 2016 differ



Mime
View raw message