Provision the correct JDK for test tasks (#48561)

This PR adds build configuration to use the `jdk-download` plugin with
unit tests when no runtime java is configured externally.

It's a first part in a longer chain of changes described in #40531.
This commit is contained in:
Alpar Torok 2019-11-18 10:27:28 +02:00
parent e84e21174b
commit 6e775cfc97
6 changed files with 38 additions and 3 deletions

View File

@ -41,6 +41,7 @@ plugins {
apply plugin: 'nebula.info-scm'
apply from: 'gradle/build-scan.gradle'
apply from: 'gradle/build-complete.gradle'
apply from: 'gradle/runtime-jdk-provision.gradle'
// common maven publishing configuration
allprojects {

View File

@ -661,7 +661,6 @@ class BuildPlugin implements Plugin<Project> {
test.jvmArgumentProviders.add(nonInputProperties)
test.extensions.add('nonInputProperties', nonInputProperties)
test.executable = "${BuildParams.runtimeJavaHome}/bin/java"
test.workingDir = project.file("${project.buildDir}/testrun/${test.name}")
test.maxParallelForks = System.getProperty('tests.jvms', BuildParams.defaultParallel.toString()) as Integer

View File

@ -111,6 +111,15 @@ public class Jdk implements Buildable, Iterable<File> {
return configuration.getBuildDependencies();
}
public Object getBinJavaPath() {
return new Object() {
@Override
public String toString() {
return getPath() + "/bin/java";
}
};
}
// internal, make this jdks configuration unmodifiable
void finalizeValues() {
if (version.isPresent() == false) {

View File

@ -173,7 +173,8 @@ public class JdkDownloadPlugin implements Plugin<Project> {
jdkConfig = configurations.create(remoteConfigName);
configurations.create(localConfigName);
}
String platformDep = platform.equals("darwin") ? (vendor.equals("adoptopenjdk") ? "mac" : "osx") : platform;
String platformDep = platform.equals("darwin") || platform.equals("osx") ?
(vendor.equals("adoptopenjdk") ? "mac" : "osx") : platform;
String extension = platform.equals("windows") ? "zip" : "tar.gz";
String jdkDep = vendor + ":" + platformDep + ":" + jdkVersion + "@" + extension;
rootProject.getDependencies().add(configName(vendor, version, platform), jdkDep);

View File

@ -25,7 +25,8 @@ public class VersionProperties {
public static String getBundledJdk(final String platform) {
switch (platform) {
case "darwin":
case "darwin": // fall trough
case "mac":
return bundledJdkDarwin;
case "linux":
return bundledJdkLinux;

View File

@ -0,0 +1,24 @@
import org.elasticsearch.gradle.OS
import org.elasticsearch.gradle.VersionProperties
import org.elasticsearch.gradle.info.BuildParams
apply plugin: 'elasticsearch.jdk-download'
jdks {
provisioned_runtime {
vendor = VersionProperties.bundledJdkVendor
version = VersionProperties.getBundledJdk(OS.current().name().toLowerCase())
platform = OS.current().name().toLowerCase()
}
}
allprojects {
project.tasks.withType(Test).configureEach { Test test ->
if (BuildParams.getIsRuntimeJavaHomeSet()) {
test.executable = "${BuildParams.runtimeJavaHome}/bin/java"
} else {
test.dependsOn(rootProject.jdks.provisioned_runtime)
test.executable = rootProject.jdks.provisioned_runtime.getBinJavaPath()
}
}
}