From 59f01bbe2e27ec0551fb4de9fdcf34711efacd6c Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Mon, 9 Sep 2024 14:57:29 +0200 Subject: [PATCH] Fix integration tests running Maven on JDK 24 (cherry picked from commit 52d81763e1055c0ee3733ee71ab28e2e3867054a) --- .../support/tests/JavaVersionsTests.java | 16 ++++++----- .../tooling/support/tests/MavenEnvVars.java | 27 +++++++++++++++++++ .../support/tests/MultiReleaseJarTests.java | 12 ++++++--- 3 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MavenEnvVars.java diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/JavaVersionsTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/JavaVersionsTests.java index 633300801acd..032997c53b25 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/JavaVersionsTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/JavaVersionsTests.java @@ -18,6 +18,7 @@ import java.nio.file.Path; import java.util.List; +import java.util.Map; import de.sormuras.bartholdy.tool.Java; @@ -36,28 +37,31 @@ class JavaVersionsTests { void java_8() { var java8Home = Helper.getJavaHome("8"); assumeTrue(java8Home.isPresent(), "Java 8 installation directory not found!"); - var actualLines = execute("8", java8Home.get()); + var actualLines = execute("8", java8Home.get(), Map.of()); assertTrue(actualLines.contains("[WARNING] Tests run: 2, Failures: 0, Errors: 0, Skipped: 1")); } @Test void java_default() { - var actualLines = execute("default", new Java().getHome()); + var actualLines = execute("default", new Java().getHome(), MavenEnvVars.FOR_JDK24_AND_LATER); assertTrue(actualLines.contains("[WARNING] Tests run: 2, Failures: 0, Errors: 0, Skipped: 1")); } - List execute(String version, Path javaHome) { - var result = Request.builder() // + List execute(String version, Path javaHome, Map environmentVars) { + var builder = Request.builder() // .setTool(Request.maven()) // .setProject("java-versions") // .setWorkspace("java-versions-" + version) // .addArguments("-Dmaven.repo=" + MavenRepo.dir()) // .addArguments("--update-snapshots", "--batch-mode", "verify") // .setTimeout(TOOL_TIMEOUT) // - .setJavaHome(javaHome) // - .build().run(); + .setJavaHome(javaHome); + environmentVars.forEach(builder::putEnvironment); + + var result = builder.build().run(); + assertFalse(result.isTimedOut(), () -> "tool timed out: " + result); assertEquals(0, result.getExitCode()); assertEquals("", result.getOutput("err")); diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MavenEnvVars.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MavenEnvVars.java new file mode 100644 index 000000000000..bcec609010a0 --- /dev/null +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MavenEnvVars.java @@ -0,0 +1,27 @@ +/* + * Copyright 2015-2024 the original author or authors. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v2.0 which + * accompanies this distribution and is available at + * + * https://www.eclipse.org/legal/epl-v20.html + */ + +package platform.tooling.support.tests; + +import java.util.Map; + +import org.junit.jupiter.api.condition.JRE; + +final class MavenEnvVars { + + // https://issues.apache.org/jira/browse/MNG-8248 + static final Map FOR_JDK24_AND_LATER = JRE.currentVersion().compareTo(JRE.JAVA_24) >= 0 // + ? Map.of("MAVEN_OPTS", "--enable-native-access=ALL-UNNAMED") // + : Map.of(); + + private MavenEnvVars() { + } + +} diff --git a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MultiReleaseJarTests.java b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MultiReleaseJarTests.java index 945d866ca4e7..bd2f440f5e2b 100644 --- a/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MultiReleaseJarTests.java +++ b/platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/MultiReleaseJarTests.java @@ -19,6 +19,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; +import java.util.Map; import de.sormuras.bartholdy.Result; @@ -80,15 +81,18 @@ void checkDefault() throws Exception { } private Result mvn(String variant) { - var result = Request.builder() // + Map environmentVars = MavenEnvVars.FOR_JDK24_AND_LATER; + + var builder = Request.builder() // .setTool(Request.maven()) // .setProject("multi-release-jar") // .addArguments("-Dmaven.repo=" + MavenRepo.dir()) // .addArguments("--update-snapshots", "--show-version", "--errors", "--batch-mode", "--file", variant, "test") // - .setTimeout(TOOL_TIMEOUT) // - .build() // - .run(); + .setTimeout(TOOL_TIMEOUT); + environmentVars.forEach(builder::putEnvironment); + + var result = builder.build().run(); assertFalse(result.isTimedOut(), () -> "tool timed out: " + result);