From 71b781d9193c64e34e9d986939af40745ea9740b Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Fri, 29 Jul 2022 09:20:02 -0400 Subject: [PATCH] NO-JIRA Improving dependency-scan for compatibility-tests --- .../artemis/maven/ArtemisAbstractPlugin.java | 2 +- .../maven/ArtemisDependencyScanPlugin.java | 32 ++++- tests/compatibility-tests/pom.xml | 132 +++--------------- .../compatibility/base/ClasspathBase.java | 26 ++-- 4 files changed, 56 insertions(+), 136 deletions(-) diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisAbstractPlugin.java b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisAbstractPlugin.java index 304df892a9..6668ff1a45 100644 --- a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisAbstractPlugin.java +++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisAbstractPlugin.java @@ -150,7 +150,7 @@ public abstract class ArtemisAbstractPlugin extends AbstractMojo { } }); } - getLog().info(writer.toString()); + getLog().debug(writer.toString()); return dependencies; } diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisDependencyScanPlugin.java b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisDependencyScanPlugin.java index 9091535ca7..00da6055f2 100644 --- a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisDependencyScanPlugin.java +++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisDependencyScanPlugin.java @@ -16,7 +16,10 @@ */ package org.apache.activemq.artemis.maven; +import java.io.BufferedOutputStream; import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintStream; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.util.ArrayList; @@ -56,6 +59,9 @@ public class ArtemisDependencyScanPlugin extends ArtemisAbstractPlugin { @Parameter private String variableName; + @Parameter + private String file; + @Parameter private String pathSeparator = File.pathSeparator; @@ -85,23 +91,23 @@ public class ArtemisDependencyScanPlugin extends ArtemisAbstractPlugin { remoteRepos.add(repo); } } - getLog().info("Local " + localRepository); + getLog().debug("Local " + localRepository); project = (MavenProject) getPluginContext().get("project"); Map properties = getPluginContext(); Set entries = properties.entrySet(); - getLog().info("Entries.size " + entries.size()); + getLog().debug("Entries.size " + entries.size()); for (Map.Entry entry : entries) { - getLog().info("... key=" + entry.getKey() + " = " + entry.getValue()); + getLog().debug("... key=" + entry.getKey() + " = " + entry.getValue()); } try { StringBuffer buffer = new StringBuffer(); Set filesSet = resolveDependencies(libListWithDeps, libList); - if (variableName != null) { + if (variableName != null || file != null) { String separatorUsed = ""; for (File f : filesSet) { buffer.append(separatorUsed); @@ -111,6 +117,22 @@ public class ArtemisDependencyScanPlugin extends ArtemisAbstractPlugin { String classPathGenerated = buffer.toString(); setVariable(classPathGenerated); + + if (file != null) { + File fileOutput = new File(file); + try { + if (getLog().isDebugEnabled()) { + getLog().debug("Generating file " + file + " with classpath output for " + variableName); + getLog().debug(classPathGenerated); + } + PrintStream printStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(fileOutput))); + printStream.print(classPathGenerated); + printStream.close(); + } catch (Exception e) { + getLog().error("could not generate file with classpath", e); + } + } + } if (targetFolder != null) { @@ -138,7 +160,7 @@ public class ArtemisDependencyScanPlugin extends ArtemisAbstractPlugin { private void setVariable(String classPathGenerated) { if (variableName != null) { project.getProperties().setProperty(variableName, classPathGenerated); - getLog().info("dependency-scan setting: -D" + variableName + "=\"" + classPathGenerated + "\""); + getLog().debug("dependency-scan setting: -D" + variableName + "=\"" + classPathGenerated + "\""); } } diff --git a/tests/compatibility-tests/pom.xml b/tests/compatibility-tests/pom.xml index f86066c81a..d608faee8b 100644 --- a/tests/compatibility-tests/pom.xml +++ b/tests/compatibility-tests/pom.xml @@ -286,6 +286,7 @@ org.apache.activemq artemis-maven-plugin + ${project.version} @@ -307,7 +308,7 @@ org.apache.activemq.tests:compatibility-tests:${project.version} - ARTEMIS-SNAPSHOT + ${basedir}/target/ARTEMIS-SNAPSHOT.cp @@ -335,7 +336,7 @@ org.apache.activemq:artemis-jakarta-service-extensions:${project.version} org.apache.activemq.tests:compatibility-tests:${project.version} - ARTEMIS-JAKARTAEE + ${basedir}/target/ARTEMIS-JAKARTAEE.cp @@ -359,7 +360,7 @@ - ARTEMIS-263 + ${basedir}/target/ARTEMIS-263.cp @@ -383,7 +384,7 @@ - ARTEMIS-270 + ${basedir}/target/ARTEMIS-270.cp @@ -409,7 +410,7 @@ - ARTEMIS-2_10_0 + ${basedir}/target/ARTEMIS-2_10_0.cp @@ -435,7 +436,7 @@ - ARTEMIS-2_17_0 + ${basedir}/target/ARTEMIS-2_17_0.cp compile @@ -460,7 +461,7 @@ - ARTEMIS-2_18_0 + ${basedir}/target/ARTEMIS-2_18_0.cp @@ -487,7 +488,7 @@ - ARTEMIS-2_22_0 + ${basedir}/target/ARTEMIS-2_22_0.cp @@ -512,7 +513,7 @@ - ARTEMIS-240 + ${basedir}/target/ARTEMIS-240.cp @@ -537,7 +538,7 @@ - ARTEMIS-210 + ${basedir}/target/ARTEMIS-210.cp @@ -562,7 +563,7 @@ - ARTEMIS-200 + ${basedir}/target/ARTEMIS-200.cp @@ -586,7 +587,7 @@ - ARTEMIS-140 + ${basedir}/target/ARTEMIS-140.cp @@ -611,7 +612,7 @@ - ARTEMIS-155 + ${basedir}/target/ARTEMIS-155.cp @@ -636,7 +637,7 @@ - HORNETQ-235 + ${basedir}/target/HORNETQ-235.cp @@ -661,7 +662,7 @@ - HORNETQ-247 + ${basedir}/target/HORNETQ-247.cp @@ -682,110 +683,11 @@ - AMQ_5_11 + ${basedir}/target/AMQ_5_11.cp - - - org.apache.maven.plugins - maven-surefire-plugin - - - - - ARTEMIS-SNAPSHOT - ${ARTEMIS-SNAPSHOT} - - - ARTEMIS-200 - ${ARTEMIS-200} - - - ARTEMIS-210 - ${ARTEMIS-210} - - - ARTEMIS-2_10_0 - ${ARTEMIS-2_10_0} - - - ARTEMIS-2_17_0 - ${ARTEMIS-2_17_0} - - - ARTEMIS-2_18_0 - ${ARTEMIS-2_18_0} - - - ARTEMIS-2_22_0 - ${ARTEMIS-2_22_0} - - - ARTEMIS-240 - ${ARTEMIS-240} - - - ARTEMIS-155 - ${ARTEMIS-155} - - - ARTEMIS-140 - ${ARTEMIS-140} - - - HORNETQ-235 - ${HORNETQ-235} - - - HORNETQ-247 - ${HORNETQ-247} - - - ARTEMIS-263 - ${ARTEMIS-263} - - - ARTEMIS-270 - ${ARTEMIS-270} - - - ARTEMIS-JAKARTAEE - ${ARTEMIS-JAKARTAEE} - - - AMQ_5_11 - ${AMQ_5_11} - - AMQ_5_11 - - ${skipCompatibilityTests} - ${modular.jdk.surefire.arg} -Djgroups.bind_addr=::1 ${activemq-surefire-argline} - - - - org.apache.servicemix.tooling depends-maven-plugin diff --git a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/base/ClasspathBase.java b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/base/ClasspathBase.java index 3fd4554e47..eb504b3a94 100644 --- a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/base/ClasspathBase.java +++ b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/base/ClasspathBase.java @@ -20,6 +20,7 @@ package org.apache.activemq.artemis.tests.compatibility.base; import java.io.File; import java.lang.reflect.Method; import java.net.URL; +import java.nio.file.Files; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -27,6 +28,7 @@ import java.util.Map; import org.apache.activemq.artemis.tests.compatibility.GroovyRun; import org.jboss.logging.Logger; import org.junit.AfterClass; +import org.junit.Assert; import org.junit.Assume; import org.junit.ClassRule; import org.junit.Rule; @@ -166,23 +168,17 @@ public class ClasspathBase { } } - String value = System.getProperty(name); - - if (!printed.contains(name)) { - boolean ok = value != null && !value.trim().isEmpty(); - if (!ok) { - System.out.println("Add \"-D" + name + "=\'CLASSPATH\'\" into your VM settings"); - System.out.println("You will see it in the output from mvn install at the compatibility-tests"); - System.out.println("... look for output from dependency-scan"); - - // our dependency scan used at the pom under compatibility-tests/pom.xml will generate these, example: - // [INFO] dependency-scan setting: -DARTEMIS-140="/Users/someuser/....." - // copy that into your IDE setting and you should be able to debug it - } - Assume.assumeTrue("Cannot run these tests, no classpath found", ok); + String classPathValue = null; + File file = new File("./target/" + name + ".cp"); + if (file.exists()) { + StringBuffer buffer = new StringBuffer(); + Files.lines(file.toPath()).forEach((str) -> buffer.append(str)); + classPathValue = buffer.toString(); } - ClassLoader loader = defineClassLoader(value); + Assert.assertTrue("Cannot run compatibility tests, no classpath found on ./target/" + name + ".cp", classPathValue != null && !classPathValue.trim().equals("")); + + ClassLoader loader = defineClassLoader(classPathValue); if (!forceNew) { // if we are forcing a new one, there's no point in caching it loaderMap.put(name, loader);