Lazy configure build tasks that require older JDKs (#29519)

Some build tasks require older JDKs. For example, the BWC build tasks
for older versions of Elasticsearch require older JDKs. It is onerous to
require these be configured when merely compiling Elasticsearch, the
requirement that they be strictly set to appropriate values should only
be enforced if these tasks are going to be executed. To address this, we
lazy configure these tasks.
This commit is contained in:
Jason Tedor 2018-04-14 15:44:43 -04:00 committed by GitHub
parent efa823bd79
commit b883e1217f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 28 deletions

View File

@ -221,6 +221,23 @@ class BuildPlugin implements Plugin<Project> {
return System.getenv('JAVA' + version + '_HOME') return System.getenv('JAVA' + version + '_HOME')
} }
/**
* Get Java home for the project for the specified version. If the specified version is not configured, an exception with the specified
* message is thrown.
*
* @param project the project
* @param version the version of Java home to obtain
* @param message the exception message if Java home for the specified version is not configured
* @return Java home for the specified version
* @throws GradleException if Java home for the specified version is not configured
*/
static String getJavaHome(final Project project, final int version, final String message) {
if (project.javaVersions.get(version) == null) {
throw new GradleException(message)
}
return project.javaVersions.get(version)
}
private static String findRuntimeJavaHome(final String compilerJavaHome) { private static String findRuntimeJavaHome(final String compilerJavaHome) {
assert compilerJavaHome != null assert compilerJavaHome != null
return System.getenv('RUNTIME_JAVA_HOME') ?: compilerJavaHome return System.getenv('RUNTIME_JAVA_HOME') ?: compilerJavaHome

View File

@ -16,21 +16,22 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.elasticsearch.gradle.test package org.elasticsearch.gradle.test
import com.sun.jna.Native import com.sun.jna.Native
import com.sun.jna.WString import com.sun.jna.WString
import org.apache.tools.ant.taskdefs.condition.Os import org.apache.tools.ant.taskdefs.condition.Os
import org.elasticsearch.gradle.Version import org.elasticsearch.gradle.Version
import org.gradle.api.GradleException
import org.gradle.api.InvalidUserDataException import org.gradle.api.InvalidUserDataException
import org.gradle.api.JavaVersion
import org.gradle.api.Project import org.gradle.api.Project
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Path import java.nio.file.Path
import java.nio.file.Paths import java.nio.file.Paths
import static org.elasticsearch.gradle.BuildPlugin.getJavaHome
/** /**
* A container for the files and configuration associated with a single node in a test cluster. * A container for the files and configuration associated with a single node in a test cluster.
*/ */
@ -165,24 +166,14 @@ class NodeInfo {
} }
final String javaHome final String javaHome
final Map<Integer, JavaVersion> javaVersions = project.javaVersions
if (nodeVersion.before("6.2.0")) { if (nodeVersion.before("6.2.0")) {
final String java8Home = javaVersions.get(8) env = ['JAVA_HOME':"${-> getJavaHome(project, 8, "JAVA8_HOME must be set to run BWC tests against [" + nodeVersion + "]")}"]
if (java8Home == null) {
throw new GradleException("JAVA8_HOME must be set to run BWC tests against [" + nodeVersion + "]")
}
javaHome = java8Home
} else if (nodeVersion.onOrAfter("6.2.0") && nodeVersion.before("6.3.0")) { } else if (nodeVersion.onOrAfter("6.2.0") && nodeVersion.before("6.3.0")) {
final String java9Home = javaVersions.get(9) env = ['JAVA_HOME':"${-> getJavaHome(project, 9, "JAVA9_HOME must be set to run BWC tests against [" + nodeVersion + "]")}"]
if (java9Home == null) {
throw new GradleException("JAVA9_HOME must be set to run BWC tests against [" + nodeVersion + "]")
}
javaHome = java9Home
} else { } else {
javaHome = project.compilerJavaHome env = ['JAVA_HOME':project.runtimeJavaHome]
} }
env = ['JAVA_HOME':javaHome]
args.addAll("-E", "node.portsfile=true") args.addAll("-E", "node.portsfile=true")
String collectedSystemProperties = config.systemProperties.collect { key, value -> "-D${key}=${value}" }.join(" ") String collectedSystemProperties = config.systemProperties.collect { key, value -> "-D${key}=${value}" }.join(" ")
String esJavaOpts = config.jvmArgs.isEmpty() ? collectedSystemProperties : collectedSystemProperties + " " + config.jvmArgs String esJavaOpts = config.jvmArgs.isEmpty() ? collectedSystemProperties : collectedSystemProperties + " " + config.jvmArgs

View File

@ -17,11 +17,12 @@
* under the License. * under the License.
*/ */
import org.apache.tools.ant.taskdefs.condition.Os import org.apache.tools.ant.taskdefs.condition.Os
import org.elasticsearch.gradle.LoggedExec import org.elasticsearch.gradle.LoggedExec
import org.elasticsearch.gradle.Version import org.elasticsearch.gradle.Version
import java.util.regex.Matcher import static org.elasticsearch.gradle.BuildPlugin.getJavaHome
/** /**
* This is a dummy project which does a local checkout of the previous * This is a dummy project which does a local checkout of the previous
@ -146,15 +147,9 @@ subprojects {
workingDir = checkoutDir workingDir = checkoutDir
if (["5.6", "6.0", "6.1"].contains(bwcBranch)) { if (["5.6", "6.0", "6.1"].contains(bwcBranch)) {
// we are building branches that are officially built with JDK 8, push JAVA8_HOME to JAVA_HOME for these builds // we are building branches that are officially built with JDK 8, push JAVA8_HOME to JAVA_HOME for these builds
if (project.javaVersions.get(8) == null) { environment('JAVA_HOME', "${-> getJavaHome(project, 8, "JAVA8_HOME is required to build BWC versions for BWC branch [" + bwcBranch + "]")}")
throw new GradleException("JAVA8_HOME is required to build BWC versions for BWC branch [" + bwcBranch + "]")
}
environment('JAVA_HOME', project.javaVersions.get(8))
} else if ("6.2".equals(bwcBranch)) { } else if ("6.2".equals(bwcBranch)) {
if (project.javaVersions.get(9) == null) { environment('JAVA_HOME', "${-> getJavaHome(project, 9, "JAVA9_HOME is required to build BWC versions for BWC branch [" + bwcBranch + "]")}")
throw new GradleException("JAVA9_HOME is required to build BWC versions for BWC branch [" + bwcBranch + "]")
}
environment('JAVA_HOME', project.javaVersions.get(9))
} else { } else {
environment('JAVA_HOME', project.compilerJavaHome) environment('JAVA_HOME', project.compilerJavaHome)
} }

View File

@ -24,8 +24,11 @@ should be able to use the standard launching mechanism which
is more flexible and reliable. is more flexible and reliable.
""" """
import org.apache.tools.ant.taskdefs.condition.Os import org.apache.tools.ant.taskdefs.condition.Os
import static org.elasticsearch.gradle.BuildPlugin.getJavaHome
apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.rest-test' apply plugin: 'elasticsearch.rest-test'
@ -55,9 +58,6 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
// we can't get the pid files in windows so we skip that // we can't get the pid files in windows so we skip that
integTest.enabled = false integTest.enabled = false
} else { } else {
if (project.javaVersions.get(7) == null) {
throw new GradleException("JAVA7_HOME must be set to run reindex-from-old")
}
/* Set up tasks to unzip and run the old versions of ES before running the /* Set up tasks to unzip and run the old versions of ES before running the
* integration tests. */ * integration tests. */
for (String version : ['2', '1', '090']) { for (String version : ['2', '1', '090']) {
@ -77,7 +77,7 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) {
dependsOn unzip dependsOn unzip
executable = new File(project.runtimeJavaHome, 'bin/java') executable = new File(project.runtimeJavaHome, 'bin/java')
env 'CLASSPATH', "${ -> project.configurations.oldesFixture.asPath }" env 'CLASSPATH', "${ -> project.configurations.oldesFixture.asPath }"
env 'JAVA_HOME', project.javaVersions.get(7) env 'JAVA_HOME', "${-> getJavaHome(project, 7, "JAVA7_HOME must be set to run reindex-from-old")}"
args 'oldes.OldElasticsearch', args 'oldes.OldElasticsearch',
baseDir, baseDir,
unzip.temporaryDir, unzip.temporaryDir,