diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchJavaPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchJavaPlugin.java index 279596fe530..c8c2fa5d110 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchJavaPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/ElasticsearchJavaPlugin.java @@ -52,16 +52,12 @@ import org.gradle.api.tasks.compile.JavaCompile; import org.gradle.api.tasks.javadoc.Javadoc; import org.gradle.api.tasks.testing.Test; import org.gradle.external.javadoc.CoreJavadocOptions; -import org.gradle.internal.jvm.Jvm; import org.gradle.language.base.plugins.LifecycleBasePlugin; import java.io.File; import java.io.IOException; -import java.io.UncheckedIOException; import java.net.MalformedURLException; import java.net.URI; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.Arrays; import java.util.List; import java.util.Locale; @@ -230,24 +226,10 @@ public class ElasticsearchJavaPlugin implements Plugin { throw new GradleException("Failed to get canonical path for " + file, e); } }; - // common options to both java and groovy - Consumer configureFork = compileOptions -> { - // we only fork if the Gradle JDK is not the same as the compiler JDK - String compilerJavaHome = canonicalPath.apply(BuildParams.getCompilerJavaHome()); - String currentJavaHome = canonicalPath.apply(Jvm.current().getJavaHome()); - if (compilerJavaHome.equals(currentJavaHome)) { - compileOptions.setFork(false); - } else { - compileOptions.setFork(true); - compileOptions.getForkOptions().setJavaHome(BuildParams.getCompilerJavaHome()); - } - }; project.afterEvaluate(p -> { project.getTasks().withType(JavaCompile.class).configureEach(compileTask -> { CompileOptions compileOptions = compileTask.getOptions(); - - configureFork.accept(compileOptions); /* * -path because gradle will send in paths that don't always exist. * -missing because we have tons of missing @returns and @param. @@ -278,7 +260,6 @@ public class ElasticsearchJavaPlugin implements Plugin { }); // also apply release flag to groovy, which is used in build-tools project.getTasks().withType(GroovyCompile.class).configureEach(compileTask -> { - configureFork.accept(compileTask.getOptions()); // TODO: this probably shouldn't apply to groovy at all? // TODO: use native Gradle support for --release when available (cf. https://github.com/gradle/gradle/issues/2510) @@ -420,7 +401,6 @@ public class ElasticsearchJavaPlugin implements Plugin { // we use 'temp' relative to CWD since this is per JVM and tests are forbidden from writing to CWD nonInputProperties.systemProperty("java.io.tmpdir", test.getWorkingDir().toPath().resolve("temp")); - nonInputProperties.systemProperty("compiler.java", BuildParams.getCompilerJavaVersion().getMajorVersion()); nonInputProperties.systemProperty("runtime.java", BuildParams.getRuntimeJavaVersion().getMajorVersion()); // TODO: remove setting logging level via system property @@ -497,7 +477,7 @@ public class ElasticsearchJavaPlugin implements Plugin { "Build-Date", BuildParams.getBuildDate(), "Build-Java-Version", - BuildParams.getCompilerJavaVersion() + BuildParams.getGradleJavaVersion() ) ); } @@ -548,21 +528,11 @@ public class ElasticsearchJavaPlugin implements Plugin { private static void configureJavadoc(Project project) { project.getTasks().withType(Javadoc.class).configureEach(javadoc -> { - // only explicitly set javadoc executable if compiler JDK is different from Gradle - // this ensures better cacheability as setting ths input to an absolute path breaks portability - Path compilerJvm = BuildParams.getCompilerJavaHome().toPath(); - Path gradleJvm = Jvm.current().getJavaHome().toPath(); - try { - if (Files.isSameFile(compilerJvm, gradleJvm) == false) { - javadoc.setExecutable(compilerJvm.resolve("bin/javadoc").toString()); - } - } catch (IOException e) { - throw new UncheckedIOException(e); - } // remove compiled classes from the Javadoc classpath: // http://mail.openjdk.java.net/pipermail/javadoc-dev/2018-January/000400.html javadoc.setClasspath(Util.getJavaMainSourceSet(project).get().getCompileClasspath()); + /* * Generate docs using html5 to suppress a warning from `javadoc` * that the default will change to html5 in the future. diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java index 2387c9b72ba..f1e04da2d2f 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java @@ -70,8 +70,7 @@ public class GlobalBuildInfoPlugin implements Plugin { JavaVersion minimumCompilerVersion = JavaVersion.toVersion(Util.getResourceContents("/minimumCompilerVersion")); JavaVersion minimumRuntimeVersion = JavaVersion.toVersion(Util.getResourceContents("/minimumRuntimeVersion")); - File compilerJavaHome = findCompilerJavaHome(); - File runtimeJavaHome = findRuntimeJavaHome(compilerJavaHome); + File runtimeJavaHome = findRuntimeJavaHome(); File rootDir = project.getRootDir(); GitInfo gitInfo = gitInfo(rootDir); @@ -81,11 +80,9 @@ public class GlobalBuildInfoPlugin implements Plugin { boolean isInternal = GlobalBuildInfoPlugin.class.getResource("/buildSrc.marker") != null; params.reset(); - params.setCompilerJavaHome(compilerJavaHome); params.setRuntimeJavaHome(runtimeJavaHome); - params.setCompilerJavaVersion(determineJavaVersion("compiler java.home", compilerJavaHome, minimumCompilerVersion)); params.setRuntimeJavaVersion(determineJavaVersion("runtime java.home", runtimeJavaHome, minimumRuntimeVersion)); - params.setIsRutimeJavaHomeSet(compilerJavaHome.equals(runtimeJavaHome) == false); + params.setIsRutimeJavaHomeSet(Jvm.current().getJavaHome().equals(runtimeJavaHome) == false); params.setJavaVersions(getAvailableJavaVersions(minimumCompilerVersion)); params.setMinimumCompilerVersion(minimumCompilerVersion); params.setMinimumRuntimeVersion(minimumRuntimeVersion); @@ -132,12 +129,8 @@ public class GlobalBuildInfoPlugin implements Plugin { LOGGER.quiet("Elasticsearch Build Hamster says Hello!"); LOGGER.quiet(" Gradle Version : " + GradleVersion.current().getVersion()); LOGGER.quiet(" OS Info : " + osName + " " + osVersion + " (" + osArch + ")"); - if (Jvm.current().getJavaVersion().equals(BuildParams.getCompilerJavaVersion()) == false || BuildParams.getIsRuntimeJavaHomeSet()) { - String compilerJvmDetails = getJavaInstallation(BuildParams.getCompilerJavaHome()).getImplementationName(); + if (BuildParams.getIsRuntimeJavaHomeSet()) { String runtimeJvmDetails = getJavaInstallation(BuildParams.getRuntimeJavaHome()).getImplementationName(); - - LOGGER.quiet(" Compiler JDK Version : " + BuildParams.getCompilerJavaVersion() + " (" + compilerJvmDetails + ")"); - LOGGER.quiet(" Compiler java.home : " + BuildParams.getCompilerJavaHome()); LOGGER.quiet(" Runtime JDK Version : " + BuildParams.getRuntimeJavaVersion() + " (" + runtimeJvmDetails + ")"); LOGGER.quiet(" Runtime java.home : " + BuildParams.getRuntimeJavaHome()); LOGGER.quiet(" Gradle JDK Version : " + gradleJvm.getJavaVersion() + " (" + gradleJvmDetails + ")"); @@ -233,26 +226,14 @@ public class GlobalBuildInfoPlugin implements Plugin { throw new GradleException(message); } - private static File findCompilerJavaHome() { - String compilerJavaHome = System.getenv("JAVA_HOME"); - String compilerJavaProperty = System.getProperty("compiler.java"); - - if (compilerJavaProperty != null) { - compilerJavaHome = findJavaHome(compilerJavaProperty); - } - - // if JAVA_HOME is not set,so we use the JDK that Gradle was run with. - return compilerJavaHome == null ? Jvm.current().getJavaHome() : new File(compilerJavaHome); - } - - private static File findRuntimeJavaHome(final File compilerJavaHome) { + private static File findRuntimeJavaHome() { String runtimeJavaProperty = System.getProperty("runtime.java"); if (runtimeJavaProperty != null) { return new File(findJavaHome(runtimeJavaProperty)); } - return System.getenv("RUNTIME_JAVA_HOME") == null ? compilerJavaHome : new File(System.getenv("RUNTIME_JAVA_HOME")); + return System.getenv("RUNTIME_JAVA_HOME") == null ? Jvm.current().getJavaHome() : new File(System.getenv("RUNTIME_JAVA_HOME")); } private static String findJavaHome(String version) { diff --git a/buildSrc/src/minimumRuntime/java/org/elasticsearch/gradle/info/BuildParams.java b/buildSrc/src/minimumRuntime/java/org/elasticsearch/gradle/info/BuildParams.java index 58cb0591426..b26505f7537 100644 --- a/buildSrc/src/minimumRuntime/java/org/elasticsearch/gradle/info/BuildParams.java +++ b/buildSrc/src/minimumRuntime/java/org/elasticsearch/gradle/info/BuildParams.java @@ -13,14 +13,12 @@ import java.util.function.Consumer; import static java.util.Objects.requireNonNull; public class BuildParams { - private static File compilerJavaHome; private static File runtimeJavaHome; private static Boolean isRuntimeJavaHomeSet; private static List javaVersions; private static JavaVersion minimumCompilerVersion; private static JavaVersion minimumRuntimeVersion; private static JavaVersion gradleJavaVersion; - private static JavaVersion compilerJavaVersion; private static JavaVersion runtimeJavaVersion; private static Boolean inFipsJvm; private static String gitRevision; @@ -45,10 +43,6 @@ public class BuildParams { initializer.accept(MutableBuildParams.INSTANCE); } - public static File getCompilerJavaHome() { - return value(compilerJavaHome); - } - public static File getRuntimeJavaHome() { return value(runtimeJavaHome); } @@ -73,10 +67,6 @@ public class BuildParams { return value(gradleJavaVersion); } - public static JavaVersion getCompilerJavaVersion() { - return value(compilerJavaVersion); - } - public static JavaVersion getRuntimeJavaVersion() { return value(runtimeJavaVersion); } @@ -162,10 +152,6 @@ public class BuildParams { }); } - public void setCompilerJavaHome(File compilerJavaHome) { - BuildParams.compilerJavaHome = requireNonNull(compilerJavaHome); - } - public void setRuntimeJavaHome(File runtimeJavaHome) { BuildParams.runtimeJavaHome = requireNonNull(runtimeJavaHome); } @@ -190,10 +176,6 @@ public class BuildParams { BuildParams.gradleJavaVersion = requireNonNull(gradleJavaVersion); } - public void setCompilerJavaVersion(JavaVersion compilerJavaVersion) { - BuildParams.compilerJavaVersion = requireNonNull(compilerJavaVersion); - } - public void setRuntimeJavaVersion(JavaVersion runtimeJavaVersion) { BuildParams.runtimeJavaVersion = requireNonNull(runtimeJavaVersion); } diff --git a/x-pack/plugin/sql/qa/jdbc/security/with-ssl/build.gradle b/x-pack/plugin/sql/qa/jdbc/security/with-ssl/build.gradle index 7a4e25770aa..03e68e567f0 100644 --- a/x-pack/plugin/sql/qa/jdbc/security/with-ssl/build.gradle +++ b/x-pack/plugin/sql/qa/jdbc/security/with-ssl/build.gradle @@ -1,5 +1,6 @@ import org.elasticsearch.gradle.LoggedExec import org.elasticsearch.gradle.info.BuildParams +import org.gradle.internal.jvm.Jvm // Tell the tests we're running with ssl enabled integTest.runner { @@ -26,7 +27,7 @@ task createNodeKeyStore(type: LoggedExec) { delete nodeKeystore } } - executable = "${BuildParams.compilerJavaHome}/bin/keytool" + executable = "${Jvm.current().javaHome}/bin/keytool" standardInput = new ByteArrayInputStream('FirstName LastName\nUnit\nOrganization\nCity\nState\nNL\nyes\n\n'.getBytes('UTF-8')) args '-genkey', '-alias', 'test-node', diff --git a/x-pack/plugin/sql/qa/server/security/with-ssl/build.gradle b/x-pack/plugin/sql/qa/server/security/with-ssl/build.gradle index 91de5df698f..5477884773a 100644 --- a/x-pack/plugin/sql/qa/server/security/with-ssl/build.gradle +++ b/x-pack/plugin/sql/qa/server/security/with-ssl/build.gradle @@ -1,5 +1,6 @@ import org.elasticsearch.gradle.LoggedExec import org.elasticsearch.gradle.info.BuildParams +import org.gradle.internal.jvm.Jvm // Tell the tests we're running with ssl enabled integTest.runner { @@ -23,7 +24,7 @@ task createNodeKeyStore(type: LoggedExec) { delete nodeKeystore } } - executable = "${BuildParams.runtimeJavaHome}/bin/keytool" + executable = "${Jvm.current().javaHome}/bin/keytool" standardInput = new ByteArrayInputStream('FirstName LastName\nUnit\nOrganization\nCity\nState\nNL\nyes\n\n'.getBytes('UTF-8')) args '-genkey', '-alias', 'test-node',