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 2022/06/17 15:14:54 UTC
[jackrabbit-filevault] branch master updated: JCRVLT-637: fix support for non-docview files with additional properties (#228)
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git
The following commit(s) were added to refs/heads/master by this push:
new 45711185 JCRVLT-637: fix support for non-docview files with additional properties (#228)
45711185 is described below
commit 45711185f567dc63e61619a7f551f172fff8d6dc
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Fri Jun 17 17:14:50 2022 +0200
JCRVLT-637: fix support for non-docview files with additional properties (#228)
Co-authored-by: Dirk Rudolph <dr...@adobe.com>
---
.../vault/validation/ValidationExecutor.java | 12 +++++++++--
.../validation/spi/GenericJcrDataValidator.java | 3 ++-
.../spi/impl/DocumentViewParserValidator.java | 1 -
.../DocumentViewParserValidatorTest.java | 8 +++----
.../jcr_root/apps/genericfile.xml.dir/.content.xml | 25 ++++++++++++++++++++++
5 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/ValidationExecutor.java b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/ValidationExecutor.java
index ee96d470..b866f356 100644
--- a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/ValidationExecutor.java
+++ b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/ValidationExecutor.java
@@ -309,7 +309,7 @@ public final class ValidationExecutor {
enrichedMessages.addAll(ValidationViolation.wrapMessages(entry.getKey(), messages, filePath, basePath, null, 0, 0));
}
}
- // only do it if we haven't collected node paths from a previous run
+ // if we haven't collected node paths from a previous run the input is no docview xml
if (nodePathsAndLineNumbers.isEmpty()) {
// convert file name to node path
String nodePath = filePathToNodePath(filePath);
@@ -372,7 +372,15 @@ public final class ValidationExecutor {
static <T> Map<String, T> filterValidatorsByClass(Map<String, Validator> allValidators, Class<T> type) {
return allValidators.entrySet().stream()
.filter(x -> type.isInstance(x.getValue()))
- .collect(Collectors.toMap(Map.Entry::getKey, x -> type.cast(x.getValue())));
+ // keep map order
+ .collect(Collectors.toMap(
+ Map.Entry::getKey,
+ x -> type.cast(x.getValue()),
+ (u, v) -> {
+ throw new IllegalStateException(String.format("Duplicate key %s", u));
+ },
+ LinkedHashMap::new
+ ));
}
}
diff --git a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/GenericJcrDataValidator.java b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/GenericJcrDataValidator.java
index 30e86f04..5d0100ad 100644
--- a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/GenericJcrDataValidator.java
+++ b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/GenericJcrDataValidator.java
@@ -22,6 +22,7 @@ import java.nio.file.Path;
import java.util.Collection;
import java.util.Map;
+import org.apache.jackrabbit.vault.validation.spi.impl.DocumentViewParserValidator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.osgi.annotation.versioning.ProviderType;
@@ -57,7 +58,7 @@ public interface GenericJcrDataValidator extends Validator {
* @param input the input stream of the file which ends up below jcr_root in the package located at filePath
* @param filePath file path relative to the jcr_root directory (i.e. does not start with {@code jcr_root})
* @param basePath the absolute file path of jcr_root (base for {@code filePath)})
- * @param nodePathsAndLineNumbers a map which should be filled with all node path and their according line numbers if nodes are detected in the given input
+ * @param nodePathsAndLineNumbers a map with all found node paths and their according line numbers (for the current input stream). Must only be modified in case the given file is a docview xml and the implementation is {@link DocumentViewParserValidator})
* @return a collection of validation messages or {@code null}
* @throws IOException in case the input stream could not be accessed
*/
diff --git a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/impl/DocumentViewParserValidator.java b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/impl/DocumentViewParserValidator.java
index b788bb52..f20b7e42 100644
--- a/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/impl/DocumentViewParserValidator.java
+++ b/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/impl/DocumentViewParserValidator.java
@@ -102,7 +102,6 @@ public class DocumentViewParserValidator implements GenericJcrDataValidator {
} else {
messages.add(new ValidationMessage(ValidationMessageSeverity.INFO, "This file is not detected as docview xml file and therefore treated as binary"));
- nodePathsAndLineNumbers.put(ValidationExecutor.filePathToNodePath(filePath), 0);
}
return messages;
diff --git a/vault-validation/src/test/java/org/apache/jackrabbit/vault/validation/DocumentViewParserValidatorTest.java b/vault-validation/src/test/java/org/apache/jackrabbit/vault/validation/DocumentViewParserValidatorTest.java
index c2f8604f..1e4a00c4 100644
--- a/vault-validation/src/test/java/org/apache/jackrabbit/vault/validation/DocumentViewParserValidatorTest.java
+++ b/vault-validation/src/test/java/org/apache/jackrabbit/vault/validation/DocumentViewParserValidatorTest.java
@@ -268,17 +268,15 @@ public class DocumentViewParserValidatorTest {
@Test
public void testDocViewWithRegularFileNameWithRootElementDifferentThanJcrRoot() throws IOException {
- // https://issues.apache.org/jira/browse/JCRVLT-358"
+ // https://issues.apache.org/jira/browse/JCRVLT-358 and https://issues.apache.org/jira/browse/JCRVLT-637
try (InputStream input = this.getClass().getResourceAsStream("/simple-package/jcr_root/apps/child2/child1.xml")) {
Collection<ValidationMessage> messages = validator.validateJcrData(input, Paths.get("apps", "child2", "child1.xml"), Paths.get(""), nodePathsAndLineNumbers);
MatcherAssert.assertThat(messages, AnyValidationViolationMessageMatcher.noValidationViolationMessageInCollection());
Mockito.verifyNoMoreInteractions(docViewXmlValidator);
- // verify node names
- Map<String, Integer> expectedNodePathsAndLineNumber = new HashMap<>();
- expectedNodePathsAndLineNumber.put("/apps/child2/child1.xml", 0);
- Assert.assertEquals(expectedNodePathsAndLineNumber, nodePathsAndLineNumbers);
+ // verify node names in case this is no docview xml
+ Assert.assertEquals(new HashMap<>(), nodePathsAndLineNumbers);
}
}
diff --git a/vault-validation/src/test/resources/valid-packages/application-package/jcr_root/apps/genericfile.xml.dir/.content.xml b/vault-validation/src/test/resources/valid-packages/application-package/jcr_root/apps/genericfile.xml.dir/.content.xml
new file mode 100644
index 00000000..20dfd9a0
--- /dev/null
+++ b/vault-validation/src/test/resources/valid-packages/application-package/jcr_root/apps/genericfile.xml.dir/.content.xml
@@ -0,0 +1,25 @@
+<?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:jcr="http://www.jcp.org/jcr/1.0"
+ jcr:primaryType="nt:file">
+ <jcr:content
+ jcr:primaryType="nt:resource"
+ jcr:mixinTypes="[mix:language]"
+ jcr:language="en">
+ </jcr:content>
+</jcr:root>