From 338f2ae9f3674f9640626b576f62d590325299b3 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Fri, 10 Sep 2021 09:22:46 +0300 Subject: [PATCH] Be more intelligent about locating java for @QuarkusIntegrationTest Fixes: #20049 --- .../test/common/DefaultJarLauncher.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/test-framework/common/src/main/java/io/quarkus/test/common/DefaultJarLauncher.java b/test-framework/common/src/main/java/io/quarkus/test/common/DefaultJarLauncher.java index 92074dcc385be..10958e167ad83 100644 --- a/test-framework/common/src/main/java/io/quarkus/test/common/DefaultJarLauncher.java +++ b/test-framework/common/src/main/java/io/quarkus/test/common/DefaultJarLauncher.java @@ -5,6 +5,7 @@ import static io.quarkus.test.common.LauncherUtil.waitForCapturedListeningData; import static io.quarkus.test.common.LauncherUtil.waitForStartedFunction; +import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; @@ -19,7 +20,10 @@ public class DefaultJarLauncher implements JarArtifactLauncher { + private static final String JAVA_HOME_SYS = "java.home"; + private static final String JAVA_HOME_ENV = "JAVA_HOME"; private static final String VERTX_HTTP_RECORDER = "io.quarkus.vertx.http.runtime.VertxHttpRecorder"; + static boolean HTTP_PRESENT; static { @@ -92,7 +96,7 @@ public void start(String[] programArgs, boolean handleIo) throws IOException { System.setProperty("test.url", TestHTTPResourceManager.getUri()); List args = new ArrayList<>(); - args.add("java"); + args.add(determineJavaPath()); if (!argLine.isEmpty()) { args.addAll(argLine); } @@ -129,6 +133,26 @@ public void start(String[] programArgs, boolean handleIo) throws IOException { } + private String determineJavaPath() { + // try system property first - it will be the JAVA_HOME used by the current JVM + String home = System.getProperty(JAVA_HOME_SYS); + if (home == null) { + // No luck, somewhat a odd JVM not enforcing this property + // try with the JAVA_HOME environment variable + home = System.getenv(JAVA_HOME_ENV); + } + if (home != null) { + File javaHome = new File(home); + File file = new File(javaHome, "bin/java"); + if (file.exists()) { + return file.getAbsolutePath(); + } + } + + // just assume 'java' is on the system path + return "java"; + } + @Override public boolean listensOnSsl() { return isSsl;