jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1814557 - in /jackrabbit/commons/filevault/trunk/vault-core/src: main/java/org/apache/jackrabbit/vault/fs/api/ main/java/org/apache/jackrabbit/vault/fs/config/ main/java/org/apache/jackrabbit/vault/fs/io/ test/java/org/apache/jackrabbit/va...
Date Wed, 08 Nov 2017 06:45:59 GMT
Author: tripod
Date: Wed Nov  8 06:45:59 2017
New Revision: 1814557

URL: http://svn.apache.org/viewvc?rev=1814557&view=rev
Log:
JCRVLT-220 Include package type when assembling a package

Modified:
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/PathFilterSet.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/package-info.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/AbstractExporter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestManifestCreationExport.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageTypes.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/fs/filter/workspacefilters/complex-expected.xml

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/PathFilterSet.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/PathFilterSet.java?rev=1814557&r1=1814556&r2=1814557&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/PathFilterSet.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/PathFilterSet.java
Wed Nov  8 06:45:59 2017
@@ -19,6 +19,9 @@ package org.apache.jackrabbit.vault.fs.a
 
 import java.util.List;
 
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
 /**
  * The path filter set holds a set of path filters each attributes as include
  * or exclude filter. The evaluation of the set allows included paths and
@@ -50,6 +53,11 @@ public class PathFilterSet extends Filte
     private boolean onlyRelativePatterns;
 
     /**
+     * specifies the filter type.
+     */
+    private String type;
+
+    /**
      * Default constructor. initializes the root path to "/"
      */
     public PathFilterSet() {
@@ -142,4 +150,24 @@ public class PathFilterSet extends Filte
         seal();
         return onlyRelativePatterns;
     }
+
+    /**
+     * Returns the filter type or {@code null}
+     * @return the filter type.
+     */
+    @Nullable
+    public String getType() {
+        return type;
+    }
+
+    /**
+     * Sets the filter type
+     * @param type the type
+     * @return this.
+     */
+    @Nonnull
+    public PathFilterSet setType(@Nullable String type) {
+        this.type = type;
+        return this;
+    }
 }
\ No newline at end of file

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/package-info.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/package-info.java?rev=1814557&r1=1814556&r2=1814557&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/package-info.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/package-info.java
Wed Nov  8 06:45:59 2017
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-@Version("2.5.1")
+@Version("2.6.0")
 package org.apache.jackrabbit.vault.fs.api;
 
 import org.osgi.annotation.versioning.Version;
\ No newline at end of file

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java?rev=1814557&r1=1814556&r2=1814557&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
Wed Nov  8 06:45:59 2017
@@ -350,6 +350,12 @@ public class DefaultWorkspaceFilter impl
             nodeFilters.setImportMode(importMode);
             propFilters.setImportMode(importMode);
         }
+        String type = elem.getAttribute("type");
+        if (type != null && type.length() > 0) {
+            nodeFilters.setType(type);
+            propFilters.setType(type);
+        }
+
         // check for filters
         NodeList n1 = elem.getChildNodes();
         for (int i=0; i<n1.getLength(); i++) {
@@ -425,6 +431,9 @@ public class DefaultWorkspaceFilter impl
                 if (set.getImportMode() != ImportMode.REPLACE) {
                     attrs.addAttribute(null, null, "mode", "CDATA", set.getImportMode().name().toLowerCase());
                 }
+                if (set.getType() != null) {
+                    attrs.addAttribute(null, null, "type", "CDATA", set.getType());
+                }
                 ser.startElement(null, null, "filter", attrs);
                 for (PathFilterSet.Entry<PathFilter> entry: set.getEntries()) {
                     // only handle path filters

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/AbstractExporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/AbstractExporter.java?rev=1814557&r1=1814556&r2=1814557&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/AbstractExporter.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/AbstractExporter.java
Wed Nov  8 06:45:59 2017
@@ -49,6 +49,7 @@ import org.apache.jackrabbit.vault.fs.sp
 import org.apache.jackrabbit.vault.fs.spi.ProgressTracker;
 import org.apache.jackrabbit.vault.fs.spi.ServiceProviderFactory;
 import org.apache.jackrabbit.vault.packaging.PackageId;
+import org.apache.jackrabbit.vault.packaging.PackageType;
 import org.apache.jackrabbit.vault.util.Constants;
 import org.apache.jackrabbit.vault.util.Text;
 import org.slf4j.Logger;
@@ -58,6 +59,7 @@ import static org.apache.jackrabbit.vaul
 import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_DESCRIPTION;
 import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_GROUP;
 import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_NAME;
+import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_PACKAGE_TYPE;
 import static org.apache.jackrabbit.vault.packaging.PackageProperties.NAME_VERSION;
 
 /**
@@ -91,6 +93,10 @@ public abstract class AbstractExporter {
      */
     private static final String MF_PACKAGE_DESC = "Content-Package-Description";
 
+    /**
+     * name of the manifest property for the package type
+     */
+    private static final String MF_PACKAGE_TYPE = "Content-Package-Type";
 
     private ProgressTracker tracker;
 
@@ -208,6 +214,11 @@ public abstract class AbstractExporter {
                 filter = filter.translate(new SimplePathMapping(mountPath, rootPath));
             }
 
+            // check for package type
+            if (!properties.containsKey(NAME_PACKAGE_TYPE)) {
+                properties.setProperty(NAME_PACKAGE_TYPE, detectPackageType(filter).name().toLowerCase());
+            }
+
             // write Manifest
             Manifest mf = new Manifest();
             mf.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
@@ -227,6 +238,7 @@ public abstract class AbstractExporter {
             addManifestAttribute(mf, MF_PACKAGE_DESC, properties.getProperty(NAME_DESCRIPTION));
             addManifestAttribute(mf, MF_PACKAGE_ROOTS, Text.implode(filterRoots, ","));
             addManifestAttribute(mf, MF_PACKAGE_DEPENDENCIES, properties.getProperty(NAME_DEPENDENCIES));
+            addManifestAttribute(mf, MF_PACKAGE_TYPE, properties.getProperty(NAME_PACKAGE_TYPE));
             ByteArrayOutputStream tmpOut = new ByteArrayOutputStream();
             mf.write(tmpOut);
             writeFile(new ByteArrayInputStream(tmpOut.toByteArray()), JarFile.MANIFEST_NAME);
@@ -352,7 +364,7 @@ public abstract class AbstractExporter {
      * @param key attribute name
      * @param value attribute value
      */
-    private void addManifestAttribute(Manifest manifest, String key, String value) {
+    private static void addManifestAttribute(Manifest manifest, String key, String value)
{
         if (value != null && value.length() > 0) {
             Attributes.Name name = new Attributes.Name(key);
             manifest.getMainAttributes().put(name, value);
@@ -360,6 +372,33 @@ public abstract class AbstractExporter {
     }
 
     /**
+     * Detects the package type based on the workspace filter.
+     * @param filter the workspace filter
+     * @return the package type
+     */
+    private static PackageType detectPackageType(WorkspaceFilter filter)  {
+        boolean hasApps = false;
+        boolean hasOther = false;
+        for (PathFilterSet p: filter.getFilterSets()) {
+            if ("cleanup".equals(p.getType())) {
+                continue;
+            }
+            String root = p.getRoot();
+            if ("/apps".equals(root) || root.startsWith("/apps/") || "/libs".equals(root)
|| root.startsWith("/libs/")) {
+                hasApps = true;
+            } else {
+                hasOther = true;
+            }
+        }
+        if (hasApps && !hasOther) {
+            return PackageType.APPLICATION;
+        } else if (hasOther && !hasApps) {
+            return PackageType.CONTENT;
+        }
+        return PackageType.MIXED;
+    }
+
+    /**
      * Opens the exporter and initializes the undelying structures.
      * @throws IOException if an I/O error occurs
      * @throws RepositoryException if a repository error occurs

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestManifestCreationExport.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestManifestCreationExport.java?rev=1814557&r1=1814556&r2=1814557&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestManifestCreationExport.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestManifestCreationExport.java
Wed Nov  8 06:45:59 2017
@@ -69,6 +69,7 @@ public class TestManifestCreationExport
                 "Content-Package-Description:This is a test package.\n" +
                 "Content-Package-Id:jackrabbit/test:test-package\n" +
                 "Content-Package-Roots:/tmp/foo/bar,/tmp/foo/zoo\n" +
+                "Content-Package-Type:content\n" +
                 "Manifest-Version:1.0";
         verifyManifest(tmpFile, Collections.<String>emptySet(), expected);
         tmpFile.delete();

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageTypes.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageTypes.java?rev=1814557&r1=1814556&r2=1814557&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageTypes.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/integration/TestPackageTypes.java
Wed Nov  8 06:45:59 2017
@@ -17,12 +17,22 @@
 
 package org.apache.jackrabbit.vault.packaging.integration;
 
+import java.io.File;
 import java.io.IOException;
+import java.util.Properties;
 
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
+import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
+import org.apache.jackrabbit.vault.fs.config.DefaultMetaInf;
+import org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter;
+import org.apache.jackrabbit.vault.packaging.ExportOptions;
 import org.apache.jackrabbit.vault.packaging.PackageException;
 import org.apache.jackrabbit.vault.packaging.PackageExistsException;
 import org.apache.jackrabbit.vault.packaging.PackageId;
 import org.apache.jackrabbit.vault.packaging.PackageType;
+import org.apache.jackrabbit.vault.packaging.VaultPackage;
 import org.apache.jackrabbit.vault.packaging.registry.PackageRegistry;
 import org.apache.jackrabbit.vault.packaging.registry.RegisteredPackage;
 import org.apache.jackrabbit.vault.packaging.registry.impl.JcrPackageRegistry;
@@ -56,6 +66,28 @@ public class TestPackageTypes extends In
         assertEquals("Package type", expected, result);
     }
 
+    private void verifyPackageTypeViaPackageCreation(WorkspaceFilter filter, PackageType
expected)
+            throws IOException, RepositoryException {
+
+        File tmpFile = File.createTempFile("vaulttest", "zip");
+
+        ExportOptions options = new ExportOptions();
+        DefaultMetaInf meta = new DefaultMetaInf();
+        meta.setFilter(filter);
+
+        Properties props = new Properties();
+        props.setProperty(VaultPackage.NAME_GROUP, "jackrabbit/test");
+        props.setProperty(VaultPackage.NAME_NAME, "package-types-export-package");
+        meta.setProperties(props);
+
+        options.setMetaInf(meta);
+        try (VaultPackage pkg = packMgr.assemble(admin, options, tmpFile)) {
+            PackageType result = pkg.getProperties().getPackageType();
+            assertEquals("Package type", expected, result);
+        }
+    }
+
+
     /**
      * checks if 'application' package type is correct read from package using the registry.
      */
@@ -96,4 +128,36 @@ public class TestPackageTypes extends In
         verifyViaRegistry("notype");
     }
 
+    /**
+     * checks if assembling an "application" package adds the correct package type to the
properties.
+     */
+    @Test
+    public void test_export_application() throws IOException, RepositoryException {
+        DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
+        filter.add(new PathFilterSet("/libs/foo"));
+        filter.add(new PathFilterSet("/apps/foo"));
+        verifyPackageTypeViaPackageCreation(filter, PackageType.APPLICATION);
+    }
+
+    /**
+     * checks if assembling a "content" package adds the correct package type to the properties.
+     */
+    @Test
+    public void test_export_content() throws IOException, RepositoryException {
+        DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
+        filter.add(new PathFilterSet("/content/foo"));
+        filter.add(new PathFilterSet("/cont/foo"));
+        verifyPackageTypeViaPackageCreation(filter, PackageType.CONTENT);
+    }
+
+    /**
+     * checks if assembling a "mixed" package adds the correct package type to the properties.
+     */
+    @Test
+    public void test_export_mixed() throws IOException, RepositoryException {
+        DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
+        filter.add(new PathFilterSet("/content/foo"));
+        filter.add(new PathFilterSet("/libs/foo"));
+        verifyPackageTypeViaPackageCreation(filter, PackageType.MIXED);
+    }
 }
\ No newline at end of file

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/fs/filter/workspacefilters/complex-expected.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/fs/filter/workspacefilters/complex-expected.xml?rev=1814557&r1=1814556&r2=1814557&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/fs/filter/workspacefilters/complex-expected.xml
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/fs/filter/workspacefilters/complex-expected.xml
Wed Nov  8 06:45:59 2017
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <workspaceFilter version="1.0">
-    <filter root="/bar" mode="merge"/>
+    <filter root="/bar" mode="merge" type="cleanup"/>
     <filter root="/tmp">
         <include pattern="/a/b.*"/>
         <include pattern="/a/c.*"/>



Mime
View raw message