You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by kw...@apache.org on 2019/10/17 14:37:29 UTC
svn commit: r1868557 - in /jackrabbit/commons/filevault/trunk/vault-core/src:
main/java/org/apache/jackrabbit/vault/packaging/impl/
test/java/org/apache/jackrabbit/vault/packaging/impl/
test/resources/org/apache/jackrabbit/vault/packaging/impl/ test/re...
Author: kwin
Date: Thu Oct 17 14:37:29 2019
New Revision: 1868557
URL: http://svn.apache.org/viewvc?rev=1868557&view=rev
Log:
JCRVLT-386 allow to retrieve package properties from exploded package
folders
Added:
jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/
jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/
jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/
jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/
jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/definition/
jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/definition/.content.xml
jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/filter.xml
jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/nodetypes.cnd
jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/properties.xml
jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/marker
Modified:
jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/DefaultPackageInfo.java
jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/impl/DefaultPackageInfoTest.java
Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/DefaultPackageInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/DefaultPackageInfo.java?rev=1868557&r1=1868556&r2=1868557&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/DefaultPackageInfo.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/DefaultPackageInfo.java Thu Oct 17 14:37:29 2019
@@ -16,7 +16,10 @@
*/
package org.apache.jackrabbit.vault.packaging.impl;
+import java.io.BufferedInputStream;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
@@ -29,6 +32,9 @@ import java.util.zip.ZipFile;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.NameFileFilter;
+import org.apache.commons.io.filefilter.SuffixFileFilter;
import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
import org.apache.jackrabbit.vault.fs.config.ConfigurationException;
@@ -40,122 +46,148 @@ import org.apache.jackrabbit.vault.packa
import org.apache.jackrabbit.vault.packaging.PackageType;
import org.apache.jackrabbit.vault.util.Constants;
-/**
- * Very simple class that reads basic package info from a file.
+/** Very simple class that reads basic package info from a file.
*
- * TODO: take over some logic from {@link DefaultMetaInf#load}
- */
+ * TODO: take over some logic from {@link DefaultMetaInf#load} */
public class DefaultPackageInfo implements PackageInfo {
- private static final String PROPERTIES_FILE = Constants.META_DIR + "/" + Constants.PROPERTIES_XML;
- private static final String FILTER_FILE = Constants.META_DIR + "/" + Constants.FILTER_XML;
+ private static final File PROPERTIES_FILE = new File(Constants.META_DIR + "/" + Constants.PROPERTIES_XML);
+ private static final File FILTER_FILE = new File(Constants.META_DIR + "/" + Constants.FILTER_XML);
+ private static final File MANIFEST_FILE = new File(JarFile.MANIFEST_NAME);
private final PackageId id;
- private final DefaultWorkspaceFilter filter;
+ private final WorkspaceFilter filter;
private final PackageType packageType;
- public DefaultPackageInfo(PackageId id, DefaultWorkspaceFilter filter, PackageType packageType) {
+ public DefaultPackageInfo(PackageId id, WorkspaceFilter filter, PackageType packageType) {
this.id = id;
this.filter = filter;
this.packageType = packageType;
}
- /**
- * Reads the package file.
- * @param file the file.
+ /** Reads the package info from a given file
+ *
+ * @param file the package file as zip or an exploded directory containing metadata.
* @return the package info if the package is valid, otherwise {@code null}.
- * @throws IOException if an error occurs.
- */
+ * @throws IOException if an error occurs. */
public static @CheckForNull PackageInfo read(@Nonnull File file) throws IOException {
- PackageId id = null;
- DefaultWorkspaceFilter filter = null;
- PackageType packageType = PackageType.MIXED;
-
- try (ZipFile zip = new ZipFile(file)) {
- Enumeration<? extends ZipEntry> entries = zip.entries();
- while (entries.hasMoreElements() && (id == null || filter == null)) {
- ZipEntry e = entries.nextElement();
- if (JarFile.MANIFEST_NAME.equalsIgnoreCase(e.getName())) {
- Manifest mf = new Manifest(zip.getInputStream(e));
- String idStr = mf.getMainAttributes().getValue(PackageProperties.MF_KEY_PACKAGE_ID);
- if (idStr != null) {
- id = PackageId.fromString(idStr);
- }
- String roots = mf.getMainAttributes().getValue(PackageProperties.MF_KEY_PACKAGE_ROOTS);
- filter = new DefaultWorkspaceFilter();
- if (roots != null) {
- for (String root: roots.split(",")) {
- filter.add(new PathFilterSet(root));
- }
- }
- String type = mf.getMainAttributes().getValue(PackageProperties.MF_KEY_PACKAGE_TYPE);
- if (type != null) {
- packageType = PackageType.valueOf(type.toUpperCase());
+ DefaultPackageInfo info = new DefaultPackageInfo(null, null, PackageType.MIXED);
+ if (!file.exists()) {
+ throw new FileNotFoundException("Could not find file " + file);
+ }
+ if (file.isDirectory()) {
+ for (File directoryFile : FileUtils.listFiles(file, new NameFileFilter(new String[] { "MANIFEST.MF", Constants.PROPERTIES_XML, Constants.FILTER_XML}),
+ new SuffixFileFilter(new String[] { Constants.META_INF, Constants.VAULT_DIR }))) {
+ try (InputStream input = new BufferedInputStream(new FileInputStream(directoryFile))) {
+ info = readFromInputStream(new File(file.toURI().relativize(directoryFile.toURI()).getPath()), input, info);
+ // bail out as soon as all info was found
+ if (info.getId() != null && info.getFilter() != null) {
+ break;
}
- } else if (PROPERTIES_FILE.equalsIgnoreCase(e.getName())) {
-
- Properties props = new Properties();
+ }
+
+ }
+ if (info.getId() == null || info.getFilter() == null) {
+ return null;
+ } else {
+ return info;
+ }
+ } else if (file.getName().endsWith(".zip")) {
+ // try to derive from vault-work?
+ try (ZipFile zip = new ZipFile(file)) {
+ Enumeration<? extends ZipEntry> entries = zip.entries();
+ while (entries.hasMoreElements()) {
+ ZipEntry e = entries.nextElement();
try (InputStream input = zip.getInputStream(e)) {
- props.loadFromXML(input);
- }
- String version = props.getProperty("version");
- if (version == null) {
- version = "";
- }
- String group = props.getProperty("group");
- String name = props.getProperty("name");
- if (group != null && name != null) {
- id = new PackageId(group, name, version);
- } else {
- // check for legacy packages that only contains a 'path' property
- String path = props.getProperty("path");
- if (path == null || path.length() == 0) {
- path = "/etc/packages/unknown";
+ info = readFromInputStream(new File(e.getName()), input, info);
+ // bail out as soon as all info was found
+ if (info.getId() != null && info.getFilter() != null) {
+ break;
}
- id = new PackageId(path, version);
- }
- } else if (FILTER_FILE.equalsIgnoreCase(e.getName())) {
- filter = new DefaultWorkspaceFilter();
- try {
- filter.load(zip.getInputStream(e));
- } catch (ConfigurationException e1) {
- throw new IOException(e1);
}
}
- // bail out as soon as all info was found
- if (id != null && filter != null) {
- break;
- }
}
- }
- if (id == null || filter == null) {
- return null;
+ if (info.getId() == null || info.getFilter() == null) {
+ return null;
+ } else {
+ return info;
+ }
} else {
- return new DefaultPackageInfo(id, filter, packageType);
+ throw new IOException("Only metadata from zip files could be extracted but the given file is not a zip:" + file);
+ }
+ }
+
+ private static DefaultPackageInfo readFromInputStream(File file, InputStream input, PackageInfo alreadyFoundInfo) throws IOException {
+ PackageId id = alreadyFoundInfo.getId();
+ WorkspaceFilter filter = alreadyFoundInfo.getFilter();
+ DefaultWorkspaceFilter defaultFilter = new DefaultWorkspaceFilter();
+ PackageType packageType = alreadyFoundInfo.getPackageType();
+ if (MANIFEST_FILE.equals(file)) {
+ Manifest mf = new Manifest(input);
+ String idStr = mf.getMainAttributes().getValue(PackageProperties.MF_KEY_PACKAGE_ID);
+ if (idStr != null) {
+ id = PackageId.fromString(idStr);
+ }
+ String roots = mf.getMainAttributes().getValue(PackageProperties.MF_KEY_PACKAGE_ROOTS);
+ if (roots != null) {
+ for (String root : roots.split(",")) {
+ defaultFilter.add(new PathFilterSet(root));
+ }
+ filter = defaultFilter;
+ }
+ String type = mf.getMainAttributes().getValue(PackageProperties.MF_KEY_PACKAGE_TYPE);
+ if (type != null) {
+ packageType = PackageType.valueOf(type.toUpperCase());
+ }
+ } else if (PROPERTIES_FILE.equals(file)) {
+ Properties props = new Properties();
+ props.loadFromXML(input);
+
+ String version = props.getProperty(PackageProperties.NAME_VERSION);
+ if (version == null) {
+ version = "";
+ }
+ String group = props.getProperty(PackageProperties.NAME_GROUP);
+ String name = props.getProperty(PackageProperties.NAME_NAME);
+ if (group != null && name != null) {
+ id = new PackageId(group, name, version);
+ } else {
+ // check for legacy packages that only contains a 'path' property
+ String path = props.getProperty("path");
+ if (path == null || path.length() == 0) {
+ path = "/etc/packages/unknown";
+ }
+ id = new PackageId(path, version);
+ }
+ } else if (FILTER_FILE.equals(file)) {
+ try {
+ defaultFilter.load(input);
+ } catch (ConfigurationException e1) {
+ throw new IOException(e1);
+ }
+ filter = defaultFilter;
}
+ return new DefaultPackageInfo(id, filter, packageType);
}
- /**
- * Returns the package id.
- * @return the package id.
- */
+ /** Returns the package id.
+ *
+ * @return the package id. */
public PackageId getId() {
return id;
}
- /**
- * Returns the workspace filter
- * @return the filter
- */
+ /** Returns the workspace filter
+ *
+ * @return the filter */
public WorkspaceFilter getFilter() {
return filter;
}
- /**
- * Returns the package type.
- * @return the package type
- */
+ /** Returns the package type.
+ *
+ * @return the package type */
public PackageType getPackageType() {
return packageType;
}
Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/impl/DefaultPackageInfoTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/impl/DefaultPackageInfoTest.java?rev=1868557&r1=1868556&r2=1868557&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/impl/DefaultPackageInfoTest.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/packaging/impl/DefaultPackageInfoTest.java Thu Oct 17 14:37:29 2019
@@ -60,4 +60,15 @@ public class DefaultPackageInfoTest {
PackageInfo info = DefaultPackageInfo.read(load("non-valid-package.zip"));
assertNull("PackageInfo", info);
}
+
+ @Test
+ public void test_pkg_from_exploded_folder() throws Exception {
+ File directory = new File(getClass().getResource("exploded-package-folder1/marker").getFile()).getParentFile();
+ PackageInfo info = DefaultPackageInfo.read(directory);
+ assertNotNull("PackageInfo", info);
+ assertEquals("PackageId", "group1:name1:1.0.0-SNAPSHOT", info.getId().toString());
+ assertEquals("filter size", 2, info.getFilter().getFilterSets().size());
+ assertTrue("contains filter", info.getFilter().contains("/apps/wcm/core/content"));
+ assertEquals("package type", PackageType.MIXED, info.getPackageType());
+ }
}
Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/definition/.content.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/definition/.content.xml?rev=1868557&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/definition/.content.xml (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/definition/.content.xml Thu Oct 17 14:37:29 2019
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+<jcr:root xmlns:vlt="http://www.day.com/jcr/vault/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
+ jcr:primaryType="vlt:PackageDefinition"
+ providerName="Apache Software Foundation">
+</jcr:root>
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/filter.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/filter.xml?rev=1868557&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/filter.xml (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/filter.xml Thu Oct 17 14:37:29 2019
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+<workspaceFilter version="1.0">
+ <filter root="/apps/wcm/core/content"/>
+ <filter root="/rep:policy" mode="merge"/>
+</workspaceFilter>
Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/nodetypes.cnd
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/nodetypes.cnd?rev=1868557&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/nodetypes.cnd (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/nodetypes.cnd Thu Oct 17 14:37:29 2019
@@ -0,0 +1,18 @@
+/*
+ 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.
+*/
+
+/* this is a dummy file */
\ No newline at end of file
Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/properties.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/properties.xml?rev=1868557&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/properties.xml (added)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/META-INF/vault/properties.xml Thu Oct 17 14:37:29 2019
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<!--
+ ~ 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.
+ -->
+
+<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
+<properties>
+<comment>FileVault Package Properties</comment>
+<entry key="createdBy">admin</entry>
+<entry key="name">name1</entry>
+<entry key="lastModified">2011-11-15T09:43:22.972+01:00</entry>
+<entry key="lastModifiedBy">admin</entry>
+<entry key="created">2011-11-15T09:43:22.993+01:00</entry>
+<entry key="buildCount">1</entry>
+<entry key="version">1.0.0-SNAPSHOT</entry>
+<entry key="dependencies"/>
+<entry key="packageFormatVersion">2</entry>
+<entry key="description"/>
+<entry key="lastWrapped">2011-11-15T09:43:22.972+01:00</entry>
+<entry key="group">group1</entry>
+<entry key="lastWrappedBy">admin</entry>
+<entry key="acHandling">overwrite</entry>
+</properties>
Added: jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/marker
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/resources/org/apache/jackrabbit/vault/packaging/impl/exploded-package-folder1/marker?rev=1868557&view=auto
==============================================================================
(empty)