jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1726322 - in /jackrabbit/commons/filevault/trunk/vault-core/src: main/java/org/apache/jackrabbit/vault/packaging/ main/java/org/apache/jackrabbit/vault/packaging/impl/ test/java/org/apache/jackrabbit/vault/packaging/integration/
Date Fri, 22 Jan 2016 21:47:45 GMT
Author: tripod
Date: Fri Jan 22 21:47:44 2016
New Revision: 1726322

URL: http://svn.apache.org/viewvc?rev=1726322&view=rev
Log:
JCRVLT-89 JcrPackageImpl.uninstall() throws exception if snapshot is missing

Modified:
    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/impl/JcrPackageImpl.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageInstall.java

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=1726322&r1=1726321&r2=1726322&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
Fri Jan 22 21:47:44 2016
@@ -147,6 +147,7 @@ public interface JcrPackage extends Comp
      * @throws PackageException if an error during packaging occurs or if no
      *         snapshot is available.
      * @throws IllegalStateException if the package is not valid.
+     * @throws PackageException if no snapshot is present and {@link ImportOptions#isStrict()}
is {@code true}.
      * @throws IOException if an I/O error occurs
      *
      * @since 2.3.14

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=1726322&r1=1726321&r2=1726322&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
Fri Jan 22 21:47:44 2016
@@ -606,43 +606,53 @@ public class JcrPackageImpl implements J
     public void uninstall(ImportOptions opts) throws RepositoryException, PackageException,
IOException {
         JcrPackage snap = getSnapshot();
         if (snap == null) {
-            throw new PackageException("Unable to uninstall package. No snapshot present.");
-        }
-        if (opts.getListener() != null) {
-            opts.getListener().onMessage(ProgressTrackerListener.Mode.TEXT, "Uninstalling
package from snapshot " + snap.getDefinition().getId(), "");
-        }
-        Session s = getNode().getSession();
-        // check for recursive uninstall
-        if (!opts.isNonRecursive()) {
-            Node defNode = snap.getDefNode();
-            LinkedList<PackageId> subPackages = new LinkedList<PackageId>();
-            if (defNode.hasProperty(JcrPackageDefinition.PN_SUB_PACKAGES)) {
-                Value[] subIds = defNode.getProperty(JcrPackageDefinition.PN_SUB_PACKAGES).getValues();
-                for (Value v: subIds) {
-                    // reverse installation order
-                    subPackages.addLast(PackageId.fromString(v.getString()));
-                }
+            if (opts.isStrict()) {
+                throw new PackageException("Unable to uninstall package. No snapshot present.");
             }
-            if (subPackages.size() > 0) {
-                JcrPackageManagerImpl packMgr = new JcrPackageManagerImpl(s);
-                for (PackageId id: subPackages) {
-                    JcrPackage pack = packMgr.open(id);
-                    if (pack != null) {
-                        if (pack.getSnapshot() == null) {
-                            log.warn("Unable to uninstall sub package {}. Snapshot missing.",
id);
-                        } else {
-                            pack.uninstall(opts);
+            log.warn("Unable to revert package content {}. Snapshot missing.", getDefinition().getId());
+            if (opts.getListener() != null) {
+                opts.getListener().onMessage(ProgressTrackerListener.Mode.TEXT, "Unable to
revert package content. Snapshot missing.", "");
+            }
+
+        } else {
+            Session s = getNode().getSession();
+            // check for recursive uninstall
+            if (!opts.isNonRecursive()) {
+                Node defNode = snap.getDefNode();
+                LinkedList<PackageId> subPackages = new LinkedList<PackageId>();
+                if (defNode.hasProperty(JcrPackageDefinition.PN_SUB_PACKAGES)) {
+                    Value[] subIds = defNode.getProperty(JcrPackageDefinition.PN_SUB_PACKAGES).getValues();
+                    for (Value v : subIds) {
+                        // reverse installation order
+                        subPackages.addLast(PackageId.fromString(v.getString()));
+                    }
+                }
+                if (subPackages.size() > 0) {
+                    JcrPackageManagerImpl packMgr = new JcrPackageManagerImpl(s);
+                    for (PackageId id : subPackages) {
+                        JcrPackage pack = packMgr.open(id);
+                        if (pack != null) {
+                            if (pack.getSnapshot() == null) {
+                                log.warn("Unable to uninstall sub package {}. Snapshot missing.",
id);
+                            } else {
+                                pack.uninstall(opts);
+                            }
                         }
                     }
+
                 }
+            }
 
+            if (opts.getListener() != null) {
+                opts.getListener().onMessage(ProgressTrackerListener.Mode.TEXT, "Uninstalling
package from snapshot " + snap.getDefinition().getId(), "");
             }
+            // override import mode
+            opts.setImportMode(ImportMode.REPLACE);
+            snap.extract(opts);
+            snap.getNode().remove();
+            s.save();
         }
-        // override import mode
-        opts.setImportMode(ImportMode.REPLACE);
-        snap.extract(opts);
-        snap.getNode().remove();
-        s.save();
+
         // revert installed flags on this package
         JcrPackageDefinitionImpl def = (JcrPackageDefinitionImpl) getDefinition();
         def.clearLastUnpacked(true);

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageInstall.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageInstall.java?rev=1726322&r1=1726321&r2=1726322&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageInstall.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageInstall.java
Fri Jan 22 21:47:44 2016
@@ -24,13 +24,13 @@ import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.derby.impl.load.Import;
 import org.apache.jackrabbit.vault.fs.io.ImportOptions;
 import org.apache.jackrabbit.vault.packaging.InstallContext;
 import org.apache.jackrabbit.vault.packaging.JcrPackage;
 import org.apache.jackrabbit.vault.packaging.PackageException;
 import org.apache.jackrabbit.vault.packaging.PackageId;
 import org.apache.tika.io.IOUtils;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -306,9 +306,74 @@ public class TestPackageInstall extends
         assertEquals("child order", "jcr:content,toolbar,products,services,company,events,support,community,blog,",
names.toString());
     }
 
+    /**
+     * Installs a package that and checks if snapshot is created
+     */
+    @Test
+    public void testSnapshotExists() throws RepositoryException, IOException, PackageException
{
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+
+        assertNodeExists("/etc/packages/my_packages/.snapshot/tmp.zip");
+        assertNodeExists("/tmp/foo/bar/tobi");
+    }
+
+    /**
+     * Installs and uninstalls a package that and checks if the content is reverted.
+     */
+    @Test
+    public void testUninstall() throws RepositoryException, IOException, PackageException
{
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp.zip"), false);
+        assertNotNull(pack);
+        pack.install(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/tobi");
+
+        pack.uninstall(getDefaultOptions());
+        assertNodeMissing("/tmp/foo/bar/tobi");
+    }
+
+    /**
+     * Uninstalls a package that has no snapshot (JCRVLT-89)
+     */
+    @Test
+    public void testUninstallNoSnapshot() throws RepositoryException, IOException, PackageException
{
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp.zip"), false);
+        assertNotNull(pack);
+
+        // extract should not generate snapshots
+        pack.extract(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/tobi");
+        assertNodeMissing("/etc/packages/my_packages/.snapshot/tmp.zip");
+
+        pack.uninstall(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/tobi");
+    }
+
+    /**
+     * Checks if uninstalling a package in strict mode with no snapshot fails (JCRVLT-89).
+     */
+    @Test
+    public void testUninstallNoSnapshotStrict() throws RepositoryException, IOException,
PackageException {
+        JcrPackage pack = packMgr.upload(getStream("testpackages/tmp.zip"), false);
+        assertNotNull(pack);
+
+        // extract should not generate snapshots
+        pack.extract(getDefaultOptions());
+        assertNodeExists("/tmp/foo/bar/tobi");
+        assertNodeMissing("/etc/packages/my_packages/.snapshot/tmp.zip");
+
+        ImportOptions opts = getDefaultOptions();
+        opts.setStrict(true);
+        try {
+            pack.uninstall(opts);
+            fail("uninstalling a package with no snapshot should fail in strict mode.");
+        } catch (PackageException e) {
+            // ok
+        }
+    }
+
     // todo: upload with version
-    // todo: install / uninstall
-    // todo: sub packages
     // todo: rename
 
 }
\ No newline at end of file



Mime
View raw message