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 2021/06/23 18:00:34 UTC
[jackrabbit-filevault-package-maven-plugin] branch master updated:
JCRVLT-537 improve subpackage detection (#56)
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-package-maven-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 0bf38c7 JCRVLT-537 improve subpackage detection (#56)
0bf38c7 is described below
commit 0bf38c7d8ddd6b3042ce1ae50878ec160262646a
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Wed Jun 23 20:00:28 2021 +0200
JCRVLT-537 improve subpackage detection (#56)
---
.../maven/packaging/ValidatePackageMojo.java | 32 ++++++++++-------
.../maven/packaging/it/ValidateFilesIT.java | 2 +-
.../maven/packaging/it/ValidatePackageIT.java | 16 ++++++---
.../main/content => }/META-INF/vault/filter.xml | 0
.../META-INF/vault/filter.xml | 5 +--
.../project-with-zip/jcr_root/apps/test/test.zip | Bin 0 -> 196 bytes
.../validator-projects/project-with-zip/pom.xml | 38 +++++++++++++++++++++
7 files changed, 70 insertions(+), 23 deletions(-)
diff --git a/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidatePackageMojo.java b/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidatePackageMojo.java
index ebe93ba..1fcd99a 100644
--- a/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidatePackageMojo.java
+++ b/src/main/java/org/apache/jackrabbit/filevault/maven/packaging/ValidatePackageMojo.java
@@ -163,20 +163,26 @@ public class ValidatePackageMojo extends AbstractValidateMojo {
// in case this is a subpackage
if (inputStream != null && entryPath.getFileName().toString().endsWith(VaultMojo.PACKAGE_EXT) && !skipSubPackageValidation) {
Path subPackagePath = context.getPackageRootPath().resolve(entryPath);
- getLog().info("Start validating sub package '" + subPackagePath + "'...");
- // can't use archive.getSubPackage because that holds the wrong metadata
- Archive subArchive = new ZipStreamArchive(inputStream);
- subArchive.open(true);
- SubPackageValidationContext subPackageValidationContext = new SubPackageValidationContext(context, subArchive, subPackagePath, resolver, getLog());
- ValidationExecutor subPackageValidationExecutor = validationExecutorFactory
- .createValidationExecutor(subPackageValidationContext, true, enforceRecursiveSubpackageValidation, getValidatorSettingsForPackage(subPackageValidationContext.getProperties().getId(), true));
- if (subPackageValidationExecutor != null) {
- validationHelper.printUsedValidators(getLog(), executor, subPackageValidationContext, false);
- validateArchive(validationHelper, subArchive, subPackagePath, subPackageValidationContext, subPackageValidationExecutor);
- } else {
- getLog().debug("Skip validating sub package as no validator is interested in it.");
+ // can't use archive.getSubArchive because that holds the wrong metadata
+ try (Archive subArchive = new ZipStreamArchive(inputStream)) {
+ subArchive.open(true);
+ // assure this is a real content package
+ if (subArchive.getJcrRoot() == null) {
+ getLog().debug("ZIP entry " + subPackagePath + " is no subpackage as it is lacking the mandatory jcr_root entry");
+ } else {
+ getLog().info("Start validating sub package '" + subPackagePath + "'...");
+ SubPackageValidationContext subPackageValidationContext = new SubPackageValidationContext(context, subArchive, subPackagePath, resolver, getLog());
+ ValidationExecutor subPackageValidationExecutor = validationExecutorFactory
+ .createValidationExecutor(subPackageValidationContext, true, enforceRecursiveSubpackageValidation, getValidatorSettingsForPackage(subPackageValidationContext.getProperties().getId(), true));
+ if (subPackageValidationExecutor != null) {
+ validationHelper.printUsedValidators(getLog(), executor, subPackageValidationContext, false);
+ validateArchive(validationHelper, subArchive, subPackagePath, subPackageValidationContext, subPackageValidationExecutor);
+ } else {
+ getLog().debug("Skip validating sub package as no validator is interested in it.");
+ }
+ getLog().info("End validating sub package.");
+ }
}
- getLog().info("End validating sub package.");
}
} else {
messages.add(new ValidationViolation(ValidationMessageSeverity.WARN, "Found unexpected file outside of " + Constants.ROOT_DIR + " and " + Constants.META_INF, entryPath, packagePath, null, 0,0, null));
diff --git a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ValidateFilesIT.java b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ValidateFilesIT.java
index c5d4c6c..61c1372 100644
--- a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ValidateFilesIT.java
+++ b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ValidateFilesIT.java
@@ -32,7 +32,7 @@ public class ValidateFilesIT {
.setTestGoals("clean", "process-classes") // make sure the validate-files mojo is not skipped
.setBuildExpectedToFail(true)
.build()
- .verifyExpectedLogLines(Paths.get("src","main","content", "META-INF","vault","filter.xml").toString());
+ .verifyExpectedLogLines(Paths.get("META-INF","vault","filter.xml").toString());
}
@Test
diff --git a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ValidatePackageIT.java b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ValidatePackageIT.java
index 9f27146..aead0f9 100644
--- a/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ValidatePackageIT.java
+++ b/src/test/java/org/apache/jackrabbit/filevault/maven/packaging/it/ValidatePackageIT.java
@@ -33,20 +33,26 @@ public class ValidatePackageIT {
private static final String TEST_PROJECT_NAME = "/validator-projects/";
- private ProjectBuilder verify(String projectName) throws VerificationException, IOException {
+ private ProjectBuilder verify(String projectName, boolean expectToFail) throws VerificationException, IOException {
return new ProjectBuilder()
.setTestProjectDir(TEST_PROJECT_NAME + projectName)
- .setBuildExpectedToFail(true)
- .build()
- .verifyExpectedLogLines(Paths.get("META-INF", "vault", "filter.xml").toString());
+ .setBuildExpectedToFail(expectToFail)
+ .build();
}
@Test
public void testInvalidProject() throws Exception {
- File csvReportFile = new File(verify("invalid-project").getTestProjectDir(), "report.csv");
+ ProjectBuilder projectBuilder = verify("invalid-project", true);
+ projectBuilder.verifyExpectedLogLines(Paths.get("META-INF", "vault", "filter.xml").toString());
+ File csvReportFile = new File(projectBuilder.getTestProjectDir(), "report.csv");
Assert.assertTrue(csvReportFile.exists());
CSVParser csvParser = CSVParser.parse(csvReportFile, StandardCharsets.UTF_8, CSVFormat.EXCEL);
List<CSVRecord> actualRecords = csvParser.getRecords();
Assert.assertEquals(4, actualRecords.size()); // 3 issues + header
}
+
+ @Test
+ public void testValidProjectWithZip() throws Exception {
+ verify("project-with-zip", false);
+ }
}
diff --git a/src/test/resources/test-projects/validator-projects/invalid-project/src/main/content/META-INF/vault/filter.xml b/src/test/resources/test-projects/validator-projects/invalid-project/META-INF/vault/filter.xml
similarity index 100%
copy from src/test/resources/test-projects/validator-projects/invalid-project/src/main/content/META-INF/vault/filter.xml
copy to src/test/resources/test-projects/validator-projects/invalid-project/META-INF/vault/filter.xml
diff --git a/src/test/resources/test-projects/validator-projects/invalid-project/src/main/content/META-INF/vault/filter.xml b/src/test/resources/test-projects/validator-projects/project-with-zip/META-INF/vault/filter.xml
similarity index 85%
rename from src/test/resources/test-projects/validator-projects/invalid-project/src/main/content/META-INF/vault/filter.xml
rename to src/test/resources/test-projects/validator-projects/project-with-zip/META-INF/vault/filter.xml
index c29c176..be47b49 100644
--- a/src/test/resources/test-projects/validator-projects/invalid-project/src/main/content/META-INF/vault/filter.xml
+++ b/src/test/resources/test-projects/validator-projects/project-with-zip/META-INF/vault/filter.xml
@@ -16,8 +16,5 @@
limitations under the License.
-->
<workspaceFilter version="1.0">
- <filter root="/apps/wcm/core/content">
- <include pattern="invalidpattern"/>
- </filter>
- <filter root="/rep:policy" mode="merge"/>
+ <filter root="/apps/test" />
</workspaceFilter>
diff --git a/src/test/resources/test-projects/validator-projects/project-with-zip/jcr_root/apps/test/test.zip b/src/test/resources/test-projects/validator-projects/project-with-zip/jcr_root/apps/test/test.zip
new file mode 100644
index 0000000..1714a34
Binary files /dev/null and b/src/test/resources/test-projects/validator-projects/project-with-zip/jcr_root/apps/test/test.zip differ
diff --git a/src/test/resources/test-projects/validator-projects/project-with-zip/pom.xml b/src/test/resources/test-projects/validator-projects/project-with-zip/pom.xml
new file mode 100755
index 0000000..436a1a1
--- /dev/null
+++ b/src/test/resources/test-projects/validator-projects/project-with-zip/pom.xml
@@ -0,0 +1,38 @@
+<!--
+ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.jackrabbit.filevault</groupId>
+ <artifactId>package-plugin-test-pkg</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>content-package</packaging>
+ <name>Packaging test</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>filevault-package-maven-plugin</artifactId>
+ <version>${plugin.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <csvReportFile>report.csv</csvReportFile>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>