Skip to content

Commit

Permalink
Fixed runtime Java version usage, it has to be respected when RUNTIME…
Browse files Browse the repository at this point in the history
…_JAVA_HOME == JAVA_HOME

Signed-off-by: Andriy Redko <[email protected]>
  • Loading branch information
reta committed Oct 14, 2021
1 parent f55b0ea commit fe6157f
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand All @@ -75,7 +76,6 @@ public class GlobalBuildInfoPlugin implements Plugin<Project> {
private static final String DEFAULT_LEGACY_VERSION_JAVA_FILE_PATH = "server/src/main/java/org/opensearch/LegacyESVersion.java";
private static final String DEFAULT_VERSION_JAVA_FILE_PATH = "server/src/main/java/org/opensearch/Version.java";
private static Integer _defaultParallel = null;
private static Boolean _isBundledJdkSupported = null;

private final JavaInstallationRegistry javaInstallationRegistry;
private final ObjectFactory objects;
Expand All @@ -101,7 +101,8 @@ public void apply(Project project) {
JavaVersion minimumCompilerVersion = JavaVersion.toVersion(Util.getResourceContents("/minimumCompilerVersion"));
JavaVersion minimumRuntimeVersion = JavaVersion.toVersion(Util.getResourceContents("/minimumRuntimeVersion"));

File runtimeJavaHome = findRuntimeJavaHome();
Optional<File> runtimeJavaHomeOpt = findRuntimeJavaHome();
File runtimeJavaHome = runtimeJavaHomeOpt.orElse(Jvm.current().getJavaHome());

File rootDir = project.getRootDir();
GitInfo gitInfo = gitInfo(rootDir);
Expand All @@ -113,7 +114,7 @@ public void apply(Project project) {
params.reset();
params.setRuntimeJavaHome(runtimeJavaHome);
params.setRuntimeJavaVersion(determineJavaVersion("runtime java.home", runtimeJavaHome, minimumRuntimeVersion));
params.setIsRutimeJavaHomeSet(Jvm.current().getJavaHome().equals(runtimeJavaHome) == false);
params.setIsRutimeJavaHomeSet(runtimeJavaHomeOpt.isPresent());
params.setRuntimeJavaDetails(getJavaInstallation(runtimeJavaHome).getImplementationName());
params.setJavaVersions(getAvailableJavaVersions(minimumCompilerVersion));
params.setMinimumCompilerVersion(minimumCompilerVersion);
Expand Down Expand Up @@ -262,14 +263,14 @@ private static void throwInvalidJavaHomeException(String description, File javaH
throw new GradleException(message);
}

private static File findRuntimeJavaHome() {
private static Optional<File> findRuntimeJavaHome() {
String runtimeJavaProperty = System.getProperty("runtime.java");

if (runtimeJavaProperty != null) {
return new File(findJavaHome(runtimeJavaProperty));
return Optional.of(new File(findJavaHome(runtimeJavaProperty)));
}

return System.getenv("RUNTIME_JAVA_HOME") == null ? Jvm.current().getJavaHome() : new File(System.getenv("RUNTIME_JAVA_HOME"));
return System.getenv("RUNTIME_JAVA_HOME") == null ? Optional.empty() : Optional.of(new File(System.getenv("RUNTIME_JAVA_HOME")));
}

private static String findJavaHome(String version) {
Expand Down

0 comments on commit fe6157f

Please sign in to comment.