jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1800970 - in /jackrabbit/commons/filevault/trunk/vault-core/src: main/java/org/apache/jackrabbit/vault/fs/impl/ main/java/org/apache/jackrabbit/vault/packaging/impl/ test/java/org/apache/jackrabbit/vault/packaging/integration/
Date Thu, 06 Jul 2017 06:55:14 GMT
Author: tripod
Date: Thu Jul  6 06:55:14 2017
New Revision: 1800970

URL: http://svn.apache.org/viewvc?rev=1800970&view=rev
Log:
JCRVLT-188 Ensure that hollow packages still proivde PackageProperties and JcrPackageDefinition.

(this closes #11)

Added:
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/ArchiveWrapper.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/JcrPackageManagerImpl.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestArchiveExtraction.java

Added: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/ArchiveWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/ArchiveWrapper.java?rev=1800970&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/ArchiveWrapper.java
(added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/ArchiveWrapper.java
Thu Jul  6 06:55:14 2017
@@ -0,0 +1,93 @@
+/*
+ * 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.fs.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.apache.jackrabbit.vault.fs.api.VaultInputSource;
+import org.apache.jackrabbit.vault.fs.config.MetaInf;
+import org.apache.jackrabbit.vault.fs.io.Archive;
+
+/**
+ * Wrapper class that hides all implementation details from the underlying archive.
+ * this is mainly use to hide the {@link org.apache.jackrabbit.vault.fs.io.ZipArchive#getFile()}.
+ */
+public final class ArchiveWrapper implements Archive {
+
+    private final Archive archive;
+
+    public ArchiveWrapper(Archive archive) {
+        this.archive = archive;
+    }
+
+    @Override
+    public void open(boolean strict) throws IOException {
+        archive.open(strict);
+    }
+
+    @Override
+    @CheckForNull
+    public InputStream openInputStream(@Nullable Entry entry) throws IOException {
+        return archive.openInputStream(entry);
+    }
+
+    @Override
+    @CheckForNull
+    public VaultInputSource getInputSource(@Nullable Entry entry) throws IOException {
+        return archive.getInputSource(entry);
+    }
+
+    @Override
+    @CheckForNull
+    public Entry getJcrRoot() throws IOException {
+        return archive.getJcrRoot();
+    }
+
+    @Override
+    @Nonnull
+    public Entry getRoot() throws IOException {
+        return archive.getRoot();
+    }
+
+    @Override
+    @Nonnull
+    public MetaInf getMetaInf() {
+        return archive.getMetaInf();
+    }
+
+    @Override
+    @CheckForNull
+    public Entry getEntry(@Nonnull String path) throws IOException {
+        return archive.getEntry(path);
+    }
+
+    @Override
+    @CheckForNull
+    public Archive getSubArchive(@Nonnull String root, boolean asJcrRoot) throws IOException
{
+        return archive.getSubArchive(root, asJcrRoot);
+    }
+
+    @Override
+    public void close() {
+        archive.close();
+    }
+}
\ 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=1800970&r1=1800969&r2=1800970&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 Jul  6 06:55:14 2017
@@ -26,6 +26,7 @@ import java.util.Arrays;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Properties;
 import java.util.Set;
 
 import javax.annotation.CheckForNull;
@@ -48,6 +49,7 @@ import org.apache.jackrabbit.vault.fs.ap
 import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
 import org.apache.jackrabbit.vault.fs.api.ProgressTrackerListener;
 import org.apache.jackrabbit.vault.fs.api.VaultInputSource;
+import org.apache.jackrabbit.vault.fs.config.DefaultMetaInf;
 import org.apache.jackrabbit.vault.fs.io.AccessControlHandling;
 import org.apache.jackrabbit.vault.fs.io.Archive;
 import org.apache.jackrabbit.vault.fs.io.ImportOptions;
@@ -311,7 +313,8 @@ public class JcrPackageImpl implements J
         if (pack == null) {
             long size = -1;
             try {
-                size = getData().getLength();
+                Property data = getData();
+                size = data == null ? -1 : data.getLength();
             } catch (RepositoryException e) {
                 // ignore
             }
@@ -322,6 +325,14 @@ public class JcrPackageImpl implements J
                 } catch (Exception e) {
                     throw new IOException("Error while reading stream", e);
                 }
+                // workaround for shallow packages that don't have a meta-inf anymore (JCRVLT-188)
+                Properties props = archive.getMetaInf().getProperties();
+                if (props == null || props.isEmpty()) {
+                    JcrPackageDefinition def = getDefinition();
+                    if (def != null) {
+                        ((DefaultMetaInf) archive.getMetaInf()).setProperties(def.getMetaInf().getProperties());
+                    }
+                }
                 pack = new ZipVaultPackage(archive, true);
             } else {
                 File tmpFile = File.createTempFile("vaultpack", ".zip");

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=1800970&r1=1800969&r2=1800970&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
Thu Jul  6 06:55:14 2017
@@ -48,6 +48,7 @@ import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.vault.fs.api.ProgressTrackerListener;
 import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
 import org.apache.jackrabbit.vault.fs.config.MetaInf;
+import org.apache.jackrabbit.vault.fs.impl.ArchiveWrapper;
 import org.apache.jackrabbit.vault.fs.impl.SubPackageFilterArchive;
 import org.apache.jackrabbit.vault.fs.io.Archive;
 import org.apache.jackrabbit.vault.fs.io.ImportOptions;
@@ -323,11 +324,13 @@ public class JcrPackageManagerImpl exten
         if (!options.isNonRecursive()) {
             spfArchive = new SubPackageFilterArchive(archive);
             archive = spfArchive;
+        } else {
+            archive = new ArchiveWrapper(archive);
         }
         ZipVaultPackage pkg = new ZipVaultPackage(archive, true);
 
         PackageId pid = pkg.getId();
-        JcrPackage jcrPack = upload(pkg, replace, null, true, false);
+        JcrPackage jcrPack = upload(pkg, replace, null);
         jcrPack = new JcrPackageImpl(this, jcrPack.getNode(), pkg);
         jcrPack.extract(options);
 
@@ -366,10 +369,10 @@ public class JcrPackageManagerImpl exten
     public JcrPackage upload(File file, boolean isTmpFile, boolean replace, String nameHint,
boolean strict)
             throws RepositoryException, IOException {
         ZipVaultPackage pack = new ZipVaultPackage(file, isTmpFile, strict);
-        return upload(pack, replace, nameHint, strict, true);
+        return upload(pack, replace, nameHint);
     }
 
-    private JcrPackage upload(ZipVaultPackage pkg, boolean replace, String nameHint, boolean
strict, boolean store)
+    private JcrPackage upload(ZipVaultPackage pkg, boolean replace, String nameHint)
             throws RepositoryException, IOException {
 
         // open zip packages
@@ -416,7 +419,7 @@ public class JcrPackageManagerImpl exten
         }
         JcrPackage jcrPack = null;
         try {
-            jcrPack = createNew(parent, pid, store ? pkg : null, false);
+            jcrPack = createNew(parent, pid, pkg, false);
             JcrPackageDefinitionImpl def = (JcrPackageDefinitionImpl) jcrPack.getDefinition();
             if (state != null) {
                 def.setState(state);

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestArchiveExtraction.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestArchiveExtraction.java?rev=1800970&r1=1800969&r2=1800970&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestArchiveExtraction.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestArchiveExtraction.java
Thu Jul  6 06:55:14 2017
@@ -37,6 +37,7 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -97,6 +98,10 @@ public class TestArchiveExtraction exten
         assertTrue("Package should be marked as installed", pack.isInstalled());
         assertTrue("Package should be marked as empty", pack.isEmpty());
         assertNull("Package should not have a snapshot", pack.getSnapshot());
+        assertNotNull("Package should have a definition", pack.getDefinition());
+        assertNotNull("Package should have a definition creation date", pack.getDefinition().getCreated());
+        assertNotNull("Package should have properties", pack.getPackage().getProperties());
+        assertNotNull("Package should have a properties creation date", pack.getPackage().getCreated());
 
         try {
             pack.install(getDefaultOptions());



Mime
View raw message