Skip to content

Commit

Permalink
Allow to parameterize output file
Browse files Browse the repository at this point in the history
Use Path instead of File as plugin parameter type
Update plugins to most recent versions
Minor tweaks to site
  • Loading branch information
kwin committed Oct 10, 2024
1 parent 8d1aeef commit 00fbdfa
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 70 deletions.
29 changes: 3 additions & 26 deletions aem-classification-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>aem-classification-maven-plugin</artifactId>
<version>1.1.0-SNAPSHOT</version>
<name>AEM Classification Maven Plugin</name>
<description>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).</description>
<packaging>maven-plugin</packaging>
Expand All @@ -25,6 +26,7 @@

<properties>
<maven.compiler.release>11</maven.compiler.release> <!-- used for compiler and javadoc plugin -->
<maven.version>3.9.8</maven.version><!-- due to https://issues.apache.org/jira/browse/MNG-8136 and https://github.com/eclipse-sisu/sisu.plexus/issues/21-->
</properties>

<build>
Expand All @@ -38,31 +40,6 @@
<scmBranch>gh-pages</scmBranch>
</configuration>
</plugin>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<versionRange>[3.6.0,)</versionRange>
<goals>
<goal>descriptor</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
Expand All @@ -83,7 +60,7 @@
<reporting>
<plugins>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<artifactId>maven-plugin-report-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
* <p>
* 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.
* <p>
* 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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -245,7 +257,7 @@ File createJarWrapper(Path sourceFile, Path relativeFileNameInJar) throws IOExce
}
target.closeEntry();
}
return outputFile;
return jarFile;
}

static String getPathWithUnixSeparators(Path path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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].

Expand All @@ -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
Expand Down
51 changes: 25 additions & 26 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,94 +80,93 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<version>3.5.1</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M7</version>
<version>3.5.1</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.13.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.1</version>
<version>3.1.3</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0</version>
<version>3.1.3</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.2.0</version>
<version>3.4.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<version>3.4.2</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.0</version>
<version>3.10.1</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M6</version>
<version>3.1.1</version>
</plugin>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.4</version>
<version>3.15.0</version>
</plugin>
<plugin>
<artifactId>maven-plugin-report-plugin</artifactId>
<version>3.15.0</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.4.0</version>
<version>3.6.2</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.3.0</version>
<version>3.8.0</version>
</plugin>
<!-- ====================================================================== -->
<!-- S I T E P L U G I N -->
<!-- ====================================================================== -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.0</version>
<version>3.12.1</version>
</plugin>
<plugin>
<artifactId>maven-scm-publish-plugin</artifactId>
<version>3.1.0</version>
<version>3.3.0</version>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.21</version>
<version>3.5.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.0.1</version>
<version>3.2.7</version>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<version>1.7.0</version>
</plugin>
<plugin>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>filevault-package-maven-plugin</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
</plugin>
<plugin>
<groupId>com.day.jcr.vault</groupId>
Expand All @@ -182,7 +181,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.2.7</version>
<version>1.6.0</version>
<configuration>
<flattenMode>ossrh</flattenMode>
</configuration>
Expand Down

0 comments on commit 00fbdfa

Please sign in to comment.