From 00fbdfa3971d483ead5b08695b141abef747e1e0 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Thu, 10 Oct 2024 08:39:52 +0200 Subject: [PATCH] Allow to parameterize output file Use Path instead of File as plugin parameter type Update plugins to most recent versions Minor tweaks to site --- aem-classification-maven-plugin/pom.xml | 29 ++--------- .../DownloadContentClassificationMojo.java | 42 +++++++++------ .../site/markdown/{index.md => index.md.vm} | 11 ++-- pom.xml | 51 +++++++++---------- 4 files changed, 63 insertions(+), 70 deletions(-) rename aem-classification-maven-plugin/src/site/markdown/{index.md => index.md.vm} (74%) diff --git a/aem-classification-maven-plugin/pom.xml b/aem-classification-maven-plugin/pom.xml index 5779786..024b2b7 100644 --- a/aem-classification-maven-plugin/pom.xml +++ b/aem-classification-maven-plugin/pom.xml @@ -1,6 +1,7 @@ 4.0.0 aem-classification-maven-plugin + 1.1.0-SNAPSHOT AEM Classification Maven Plugin Maven plugin to generate classification maps from existing AEM instances (https://docs.adobe.com/content/help/en/experience-manager-65/deploying/upgrading/sustainable-upgrades.html). maven-plugin @@ -25,6 +26,7 @@ 11 + 3.9.8 @@ -38,31 +40,6 @@ gh-pages - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.apache.maven.plugins - maven-plugin-plugin - [3.6.0,) - - descriptor - - - - - - - - - - @@ -83,7 +60,7 @@ - maven-plugin-plugin + maven-plugin-report-plugin maven-project-info-reports-plugin diff --git a/aem-classification-maven-plugin/src/main/java/biz/netcentric/filevault/validator/aem/classification/mojo/DownloadContentClassificationMojo.java b/aem-classification-maven-plugin/src/main/java/biz/netcentric/filevault/validator/aem/classification/mojo/DownloadContentClassificationMojo.java index bbd747d..13775ad 100644 --- a/aem-classification-maven-plugin/src/main/java/biz/netcentric/filevault/validator/aem/classification/mojo/DownloadContentClassificationMojo.java +++ b/aem-classification-maven-plugin/src/main/java/biz/netcentric/filevault/validator/aem/classification/mojo/DownloadContentClassificationMojo.java @@ -13,8 +13,6 @@ * #L% */ -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -52,13 +50,12 @@ import biz.netcentric.filevault.validator.aem.classification.map.MutableContentClassificationMapImpl; /** - * Downloads the classification data from a remote JCR repository (only works with AEM 6.4 or newer), + * Downloads the classification data from a remote JCR (only works with AEM 6.4 or newer) via HTTP endpoints, * serializes it into a map file and optionally wraps that within a JAR file. *

- * That JAR file still needs to be manually uploaded to a Maven repository to leverage this classification map from the plugin. + * That JAR file still needs to be manually uploaded to a Maven repository to leverage this classification map from the aem-classification-validator. *

- * Uses the JCR search to find the current classification and also deprecation infos from properties "cq:deprecated" and "cq:deprecatedReason" - * The search index needs to be setup for that though (property index limited to properties jcr:primaryType and jcr:mixinTypes for node types granite:FinalArea, granite:PublicArea, granite:InternalArea, granite:AbstractArea and another property index for properties cq:deprecated for any node type) + * Uses the JCR search to find the current classification and also deprecation infos from properties {@code cq:deprecated} and {@code cq:deprecatedReason}. */ @Mojo(requiresProject=false, name = "download-content-classification") public class DownloadContentClassificationMojo extends AbstractMojo { @@ -86,7 +83,11 @@ public class DownloadContentClassificationMojo extends AbstractMojo { * needs to be set to the filepath the map should have within the JAR. */ @Parameter(property="relativeFileNameInJar", required = false) - File relativeFileNameInJar; + Path relativeFileNameInJar; + + /** The path of the classification map file (and potentially wrapper jar) without extension. If not set it is written to the default temporary directory of the file system with a random file name. */ + @Parameter(property="outputFile", required = false) + Path outputFile; @Override public void execute() throws MojoExecutionException, MojoFailureException { @@ -113,15 +114,20 @@ public void execute() throws MojoExecutionException, MojoFailureException { retrieveDeprecatedResourceTypes(httpClient, map); // 3. persist the map - Path outputFile = Files.createTempFile("contentclassification", ".map"); - try (OutputStream fileOutputStream = Files.newOutputStream(outputFile)) { + final Path classificationMapFile; + if (outputFile == null) { + classificationMapFile = Files.createTempFile("contentclassification", ".map"); + } else { + classificationMapFile = outputFile.resolveSibling(outputFile.getFileName() + ".map"); + } + try (OutputStream fileOutputStream = Files.newOutputStream(classificationMapFile)) { map.write(fileOutputStream); } - log.info("Written classification map to " + outputFile + " containing " + map.size() + " entries."); + log.info("Written classification map to " + classificationMapFile + " containing " + map.size() + " entries."); // 4. optionally wrap in a JAR if (relativeFileNameInJar != null) { - File jarFile = createJarWrapper(outputFile, relativeFileNameInJar.toPath()); + Path jarFile = createJarWrapper(classificationMapFile, relativeFileNameInJar); log.info("Written wrapper jar to " + jarFile); } } catch (InterruptedException e) { @@ -232,11 +238,17 @@ private InputStream downloadFromAem(HttpClient httpClient, String path) throws I return response.body(); } - File createJarWrapper(Path sourceFile, Path relativeFileNameInJar) throws IOException { + Path createJarWrapper(Path sourceFile, Path relativeFileNameInJar) throws IOException { Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); - File outputFile = File.createTempFile("contentclassification", ".jar"); - try (JarOutputStream target = new JarOutputStream(new FileOutputStream(outputFile), manifest)) { + final Path jarFile; + if (outputFile == null) { + jarFile = Files.createTempFile("contentclassification", ".jar"); + } else { + jarFile = outputFile.resolveSibling(outputFile.getFileName() + ".jar"); + } + + try (JarOutputStream target = new JarOutputStream(Files.newOutputStream(jarFile), manifest)) { JarEntry entry = new JarEntry(getPathWithUnixSeparators(relativeFileNameInJar)); entry.setTime(Files.getLastModifiedTime(sourceFile).toMillis()); target.putNextEntry(entry); @@ -245,7 +257,7 @@ File createJarWrapper(Path sourceFile, Path relativeFileNameInJar) throws IOExce } target.closeEntry(); } - return outputFile; + return jarFile; } static String getPathWithUnixSeparators(Path path) { diff --git a/aem-classification-maven-plugin/src/site/markdown/index.md b/aem-classification-maven-plugin/src/site/markdown/index.md.vm similarity index 74% rename from aem-classification-maven-plugin/src/site/markdown/index.md rename to aem-classification-maven-plugin/src/site/markdown/index.md.vm index a78f8b6..43e6ad7 100644 --- a/aem-classification-maven-plugin/src/site/markdown/index.md +++ b/aem-classification-maven-plugin/src/site/markdown/index.md.vm @@ -10,8 +10,13 @@ Prepare AEM Server ---------- The AEM instance needs to have several [query indices][3] in place for this plugin to work: -1. property index limited to properties jcr:primaryType and jcr:mixinTypes for node types granite:FinalArea, granite:PublicArea, granite:InternalArea and granite:AbstractArea -1. property index for properties cq:deprecated for any node type) +1. property index limited to properties `jcr:primaryType` and `jcr:mixinTypes`for node types + - `granite:FinalArea`, + - `granite:PublicArea`, + - `granite:InternalArea` and + - `granite:AbstractArea` + and +1. property index for properties `cq:deprecated` and `cq:deprecatedReason` for any node type There is a package containing the relevant indices called [aem-classification-search-index-package][4]. @@ -21,7 +26,7 @@ Usage The only goal can be used without a Maven project like this ``` -mvn biz.netcentric.filevault.validator:aem-classification-maven-plugin:1.0.0-SNAPSHOT:download-content-classification +mvn biz.netcentric.filevault.validator:aem-classification-maven-plugin:${project.version}:download-content-classification ``` [1]: https://docs.adobe.com/content/help/en/experience-manager-65/deploying/upgrading/sustainable-upgrades.html#content-classifications diff --git a/pom.xml b/pom.xml index 073015e..2b0a380 100644 --- a/pom.xml +++ b/pom.xml @@ -80,94 +80,93 @@ maven-surefire-plugin - 3.0.0-M7 + 3.5.1 maven-failsafe-plugin - 3.0.0-M7 + 3.5.1 maven-compiler-plugin - 3.10.1 + 3.13.0 maven-install-plugin - 3.0.1 + 3.1.3 maven-deploy-plugin - 3.0.0 + 3.1.3 maven-resources-plugin - 3.3.0 + 3.3.1 maven-clean-plugin - 3.2.0 + 3.4.0 maven-jar-plugin - 3.2.2 + 3.4.2 maven-javadoc-plugin - 3.4.0 + 3.10.1 maven-source-plugin - 3.2.1 + 3.3.1 maven-release-plugin - 3.0.0-M6 + 3.1.1 maven-plugin-plugin - 3.6.4 + 3.15.0 + + + maven-plugin-report-plugin + 3.15.0 maven-project-info-reports-plugin - 3.4.0 + 3.6.2 maven-dependency-plugin - 3.3.0 + 3.8.0 maven-site-plugin - 3.12.0 + 3.12.1 maven-scm-publish-plugin - 3.1.0 + 3.3.0 maven-enforcer-plugin - 3.1.0 - - - org.codehaus.mojo - animal-sniffer-maven-plugin - 1.21 + 3.5.0 org.apache.maven.plugins maven-gpg-plugin - 3.0.1 + 3.2.7 org.sonatype.plugins nexus-staging-maven-plugin - 1.6.8 + 1.7.0 org.apache.jackrabbit filevault-package-maven-plugin - 1.3.0 + 1.4.0 com.day.jcr.vault @@ -182,7 +181,7 @@ org.codehaus.mojo flatten-maven-plugin - 1.2.7 + 1.6.0 ossrh