Skip to content

Commit

Permalink
Be more intelligent about locating java for @QuarkusIntegrationTest
Browse files Browse the repository at this point in the history
Fixes: quarkusio#20049
(cherry picked from commit 338f2ae)
  • Loading branch information
geoand authored and gsmet committed Dec 1, 2021
1 parent 4fd2b35 commit 75d8eac
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 @@ -18,6 +19,9 @@

public class DefaultJarLauncher implements JarArtifactLauncher {

private static final String JAVA_HOME_SYS = "java.home";
private static final String JAVA_HOME_ENV = "JAVA_HOME";

private int httpPort;
private int httpsPort;
private long waitTimeSeconds;
Expand Down Expand Up @@ -45,7 +49,7 @@ public void start() 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 @@ -86,6 +90,26 @@ public void start() 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 75d8eac

Please sign in to comment.