From ddb55e436363c796b8ccb19fb69ac2556f1fedb9 Mon Sep 17 00:00:00 2001 From: Jonas Rutishauser Date: Fri, 25 Oct 2024 09:41:25 +0200 Subject: [PATCH] Support maven version 4.0.0-beta-5 for integration tests --- .../io/takari/maven/testing/executor/Embedded3xLauncher.java | 5 ++++- .../io/takari/maven/testing/executor/ForkedLauncher.java | 3 +++ .../maven/testing/executor/MavenInstallationUtils.java | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/takari-plugin-testing/src/main/java/io/takari/maven/testing/executor/Embedded3xLauncher.java b/takari-plugin-testing/src/main/java/io/takari/maven/testing/executor/Embedded3xLauncher.java index 2adab65..3536eda 100644 --- a/takari-plugin-testing/src/main/java/io/takari/maven/testing/executor/Embedded3xLauncher.java +++ b/takari-plugin-testing/src/main/java/io/takari/maven/testing/executor/Embedded3xLauncher.java @@ -23,6 +23,7 @@ */ import static io.takari.maven.testing.executor.MavenInstallationUtils.SYSPROP_MAVEN_HOME; +import static io.takari.maven.testing.executor.MavenInstallationUtils.SYSPROP_MAVEN_MAIN_CLASS; import java.io.BufferedInputStream; import java.io.BufferedWriter; @@ -273,7 +274,9 @@ private static Embedded3xLauncher createFromMavenHome0( Thread.currentThread().setContextClassLoader(bootLoader); try { ClassworldsConfiguration config = new ClassworldsConfiguration(); - ConfigurationParser configParser = new ConfigurationParser(config, System.getProperties()); + Properties properties = new Properties(System.getProperties()); + properties.put(SYSPROP_MAVEN_MAIN_CLASS, "org.apache.maven.cli.MavenCli"); + ConfigurationParser configParser = new ConfigurationParser(config, properties); try (InputStream is = new BufferedInputStream(new FileInputStream(configFile))) { configParser.parse(is); } diff --git a/takari-plugin-testing/src/main/java/io/takari/maven/testing/executor/ForkedLauncher.java b/takari-plugin-testing/src/main/java/io/takari/maven/testing/executor/ForkedLauncher.java index 715acea..28cd8f8 100644 --- a/takari-plugin-testing/src/main/java/io/takari/maven/testing/executor/ForkedLauncher.java +++ b/takari-plugin-testing/src/main/java/io/takari/maven/testing/executor/ForkedLauncher.java @@ -22,6 +22,8 @@ * the License. */ +import static io.takari.maven.testing.executor.MavenInstallationUtils.SYSPROP_MAVEN_MAIN_CLASS; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -118,6 +120,7 @@ public int run( cli.addArgument("-Dclassworlds.conf=" + new File(mavenHome, "bin/m2.conf").getAbsolutePath()); cli.addArgument("-Dmaven.home=" + mavenHome.getAbsolutePath()); cli.addArgument("-Dmaven.multiModuleProjectDirectory=" + multiModuleProjectDirectory.getAbsolutePath()); + cli.addArgument("-D" + SYSPROP_MAVEN_MAIN_CLASS + "=org.apache.maven.cling.MavenCling"); cli.addArguments(jvmArgs.toArray(new String[jvmArgs.size()])); diff --git a/takari-plugin-testing/src/main/java/io/takari/maven/testing/executor/MavenInstallationUtils.java b/takari-plugin-testing/src/main/java/io/takari/maven/testing/executor/MavenInstallationUtils.java index 16d2846..7af391f 100644 --- a/takari-plugin-testing/src/main/java/io/takari/maven/testing/executor/MavenInstallationUtils.java +++ b/takari-plugin-testing/src/main/java/io/takari/maven/testing/executor/MavenInstallationUtils.java @@ -29,6 +29,8 @@ public class MavenInstallationUtils { public static final String SYSPROP_MAVEN_HOME = "maven.home"; + public static final String SYSPROP_MAVEN_MAIN_CLASS = "maven.mainClass"; + public static final String SYSPROP_CLASSWORLDSCONF = "classworlds.conf"; public static String getMavenVersion(Class clazz) throws IOException { @@ -104,6 +106,7 @@ public void addLoadURL(URL url) {} VersionConfigHandler configHandler = new VersionConfigHandler(); Properties properties = new Properties(System.getProperties()); properties.setProperty(SYSPROP_MAVEN_HOME, mavenHome.getCanonicalPath()); + properties.setProperty(SYSPROP_MAVEN_MAIN_CLASS, SYSPROP_MAVEN_MAIN_CLASS); ConfigurationParser configParser = new ConfigurationParser(configHandler, properties); try (InputStream is = new BufferedInputStream(new FileInputStream(classworldsConf))) { configParser.parse(is);