Skip to content

Commit

Permalink
Fix integration tests running Maven on JDK 24
Browse files Browse the repository at this point in the history
(cherry picked from commit 52d8176)
  • Loading branch information
marcphilipp committed Sep 23, 2024
1 parent e60653d commit 59f01bb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.nio.file.Path;
import java.util.List;
import java.util.Map;

import de.sormuras.bartholdy.tool.Java;

Expand All @@ -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<String> execute(String version, Path javaHome) {
var result = Request.builder() //
List<String> execute(String version, Path javaHome, Map<String, String> 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"));
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> FOR_JDK24_AND_LATER = JRE.currentVersion().compareTo(JRE.JAVA_24) >= 0 //
? Map.of("MAVEN_OPTS", "--enable-native-access=ALL-UNNAMED") //
: Map.of();

private MavenEnvVars() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -80,15 +81,18 @@ void checkDefault() throws Exception {
}

private Result mvn(String variant) {
var result = Request.builder() //
Map<String, String> 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);

Expand Down

0 comments on commit 59f01bb

Please sign in to comment.