diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index 470c26e..d420926 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -9,11 +9,11 @@ jobs:
steps:
- name: Git Clone
uses: actions/checkout@v3
- - name: Set up JDK 1.8
- uses: actions/setup-java@v3
+ - name: Set up JDK 21
+ uses: actions/setup-java@v4
with:
distribution: 'temurin'
- java-version: 11
+ java-version: 21
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
server-username: MAVEN_USERNAME # env variable for username in deploy
server-password: MAVEN_PASSWORD # env variable for token in deploy
diff --git a/aem-classification-maven-plugin/pom.xml b/aem-classification-maven-plugin/pom.xml
index e8a846d..5779786 100644
--- a/aem-classification-maven-plugin/pom.xml
+++ b/aem-classification-maven-plugin/pom.xml
@@ -23,6 +23,10 @@
+
+ 11
+
+
@@ -121,16 +125,6 @@
aem-classification-validator
1.1.1
-
- commons-lang
- commons-lang
- 2.5
-
-
- commons-io
- commons-io
- 2.7
-
org.apache.felix
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 1ea955f..bbd747d 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
@@ -14,14 +14,18 @@
*/
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
+import java.io.OutputStream;
+import java.net.URI;
import java.net.URLEncoder;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Base64;
import java.util.Date;
import java.util.EnumSet;
@@ -31,10 +35,9 @@
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
-import org.apache.commons.io.FilenameUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.StringUtils;
import org.apache.felix.utils.json.JSONParser;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -64,7 +67,7 @@ public class DownloadContentClassificationMojo extends AbstractMojo {
* the base URL where AEM is deployed
*/
@Parameter(property="baseUrl", defaultValue="http://localhost:4502")
- URL baseUrl;
+ URI baseUrl;
/**
* the user name to access the {@link baseUrl}
@@ -84,12 +87,13 @@ public class DownloadContentClassificationMojo extends AbstractMojo {
*/
@Parameter(property="relativeFileNameInJar", required = false)
File relativeFileNameInJar;
-
+
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
Log log = getLog();
+ HttpClient httpClient = HttpClient.newHttpClient();
try {
- String aemVersion = getAemVersion();
+ String aemVersion = getAemVersion(httpClient);
log.warn("Make sure that the relevant search index definitions are deployed on AEM at " + baseUrl + ". Otherwise this goal will fail!");
log.info("Start retrieving the classification and deprecation data from " + baseUrl);
@@ -102,31 +106,34 @@ public void execute() throws MojoExecutionException, MojoFailureException {
if (classification.isLabelMixin() == false) {
continue;
}
- retrieveClassificationForMixin(classification, map);
+ retrieveClassificationForMixin(httpClient, classification, map);
}
// 2. update map with deprecation entries
- retrieveDeprecatedResourceTypes(map);
+ retrieveDeprecatedResourceTypes(httpClient, map);
// 3. persist the map
- File outputFile = File.createTempFile("contentclassification", ".map");
- try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile)) {
+ Path outputFile = Files.createTempFile("contentclassification", ".map");
+ try (OutputStream fileOutputStream = Files.newOutputStream(outputFile)) {
map.write(fileOutputStream);
}
log.info("Written classification map to " + outputFile + " containing " + map.size() + " entries.");
// 4. optionally wrap in a JAR
if (relativeFileNameInJar != null) {
- File jarFile = createJarWrapper(outputFile, relativeFileNameInJar);
+ File jarFile = createJarWrapper(outputFile, relativeFileNameInJar.toPath());
log.info("Written wrapper jar to " + jarFile);
}
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new MojoFailureException("Could not retrieve classification metadata: " + e.getMessage(), e);
} catch(IOException|IllegalStateException e) {
- throw new MojoFailureException("Could not generate classification JAR:" + e.getMessage(), e);
+ throw new MojoFailureException("Could not retrieve classification metadata: " + e.getMessage(), e);
}
}
- String getAemVersion() throws IOException {
- try (InputStream input = getHttpConnectionInputStream("/libs/granite/operations/content/systemoverview/export.json")) {
+ String getAemVersion(HttpClient httpClient) throws IOException, InterruptedException {
+ try (InputStream input = downloadFromAem(httpClient, "/libs/granite/operations/content/systemoverview/export.json")) {
JSONParser parser = new JSONParser(input);
Map response = parser.getParsed();
getLog().debug("Received JSON response " + response);
@@ -142,7 +149,7 @@ String getAemVersion() throws IOException {
}
@SuppressWarnings({ "unchecked", "rawtypes" })
- void retrieveClassificationForMixin(ContentClassification classification, MutableContentClassificationMap map) throws IOException {
+ void retrieveClassificationForMixin(HttpClient httpClient, ContentClassification classification, MutableContentClassificationMap map) throws IOException, InterruptedException {
// Uses the crxde search to find the current classification
// (http://localhost:8080/crx/de/query.jsp?_dc=1536334082630&_charset_=utf-8&type=JCR_SQL2&stmt=SELECT%20*%20FROM%20%5Bgranite%3AInternalArea%5D%0A&showResults=true)
// the index is crucial for that though (property index limited to properties jcr:primaryType and jcr:mixinTypes)
@@ -150,7 +157,7 @@ void retrieveClassificationForMixin(ContentClassification classification, Mutabl
String query = "SELECT * FROM [" + classification.getLabel() + "]";
StringBuilder urlParameters = new StringBuilder();
urlParameters.append("_dc=").append(new Date().getTime()).append("&_charset_=utf-8&type=JCR-SQL2&stmt=").append(URLEncoder.encode(query, "ASCII")).append("&showResults=true");
- try (InputStream input = getHttpConnectionInputStream( "/crx/de/query.jsp?" + urlParameters)) {
+ try (InputStream input = downloadFromAem(httpClient, "/crx/de/query.jsp?" + urlParameters)) {
JSONParser parser = new JSONParser(input);
Map response = parser.getParsed();
getLog().debug("Received JSON response " + response);
@@ -171,7 +178,7 @@ void retrieveClassificationForMixin(ContentClassification classification, Mutabl
}
for (Map result : (List