Skip to content

Remove compiler java version flag #57237

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

Merged
merged 2 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
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 @@ -53,16 +53,12 @@
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;
Expand Down Expand Up @@ -231,24 +227,10 @@ public static void configureCompile(Project project) {
throw new GradleException("Failed to get canonical path for " + file, e);
}
};
// common options to both java and groovy
Consumer<CompileOptions> 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.
Expand Down Expand Up @@ -279,7 +261,6 @@ public static void configureCompile(Project project) {
});
// 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)
Expand Down Expand Up @@ -416,7 +397,6 @@ public void execute(Task t) {
// 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
Expand Down Expand Up @@ -493,7 +473,7 @@ static void configureJars(Project project) {
"Build-Date",
BuildParams.getBuildDate(),
"Build-Java-Version",
BuildParams.getCompilerJavaVersion()
BuildParams.getGradleJavaVersion()
)
);
}
Expand Down Expand Up @@ -544,18 +524,6 @@ private static void configureJarManifest(Project project) {

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);
}

/*
* Generate docs using html5 to suppress a warning from `javadoc`
* that the default will change to html5 in the future.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public void apply(Project project) {
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);
Expand All @@ -81,11 +80,9 @@ public void apply(Project project) {
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);
Expand Down Expand Up @@ -132,12 +129,8 @@ private void logGlobalBuildInfo() {
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 + ")");
Expand Down Expand Up @@ -233,26 +226,14 @@ private static void throwInvalidJavaHomeException(String description, File javaH
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
import static java.util.Objects.requireNonNull;

public class BuildParams {
private static File compilerJavaHome;
private static File runtimeJavaHome;
private static Boolean isRuntimeJavaHomeSet;
private static List<JavaHome> 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;
Expand All @@ -45,10 +43,6 @@ public static void init(Consumer<MutableBuildParams> initializer) {
initializer.accept(MutableBuildParams.INSTANCE);
}

public static File getCompilerJavaHome() {
return value(compilerJavaHome);
}

public static File getRuntimeJavaHome() {
return value(runtimeJavaHome);
}
Expand All @@ -73,10 +67,6 @@ public static JavaVersion getGradleJavaVersion() {
return value(gradleJavaVersion);
}

public static JavaVersion getCompilerJavaVersion() {
return value(compilerJavaVersion);
}

public static JavaVersion getRuntimeJavaVersion() {
return value(runtimeJavaVersion);
}
Expand Down Expand Up @@ -162,10 +152,6 @@ public void reset() {
});
}

public void setCompilerJavaHome(File compilerJavaHome) {
BuildParams.compilerJavaHome = requireNonNull(compilerJavaHome);
}

public void setRuntimeJavaHome(File runtimeJavaHome) {
BuildParams.runtimeJavaHome = requireNonNull(runtimeJavaHome);
}
Expand All @@ -190,10 +176,6 @@ public void setGradleJavaVersion(JavaVersion gradleJavaVersion) {
BuildParams.gradleJavaVersion = requireNonNull(gradleJavaVersion);
}

public void setCompilerJavaVersion(JavaVersion compilerJavaVersion) {
BuildParams.compilerJavaVersion = requireNonNull(compilerJavaVersion);
}

public void setRuntimeJavaVersion(JavaVersion runtimeJavaVersion) {
BuildParams.runtimeJavaVersion = requireNonNull(runtimeJavaVersion);
}
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugin/sql/qa/jdbc/security/with-ssl/build.gradle
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugin/sql/qa/server/security/with-ssl/build.gradle
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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',
Expand Down