Skip to content

Commit

Permalink
Merge pull request #20050 from geoand/#20049
Browse files Browse the repository at this point in the history
Be more intelligent about locating java for @QuarkusIntegrationTest
  • Loading branch information
geoand committed Sep 10, 2021
2 parents 994e164 + 338f2ae commit b95587b
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -92,7 +96,7 @@ public void start(String[] programArgs, boolean handleIo) throws IOException {
System.setProperty("test.url", TestHTTPResourceManager.getUri());

List<String> args = new ArrayList<>();
args.add("java");
args.add(determineJavaPath());
if (!argLine.isEmpty()) {
args.addAll(argLine);
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b95587b

Please sign in to comment.