Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be more intelligent about locating java for @QuarkusIntegrationTest #20050

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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