Only require java<version>_home env var if needed

We accidentally started enforcing the env vars are always there.
This reverts to only do this if they are requierd.
This commit is contained in:
Alpar Torok 2018-08-10 16:10:13 +03:00
parent f236bb3ff6
commit de2897a190
1 changed files with 9 additions and 3 deletions

View File

@ -116,8 +116,10 @@ class BuildPlugin implements Plugin<Project> {
final Map<Integer, String> javaVersions = [:]
for (int version = 7; version <= Integer.parseInt(minimumCompilerVersion.majorVersion); version++) {
if(System.getenv(getJavaHomeEnvVarName(version.toString())) != null) {
javaVersions.put(version, findJavaHome(version.toString()));
}
}
String javaVendor = System.getProperty('java.vendor')
String gradleJavaVersion = System.getProperty('java.version')
@ -247,8 +249,8 @@ class BuildPlugin implements Plugin<Project> {
}
private static String findJavaHome(String version) {
String versionedVarName = 'JAVA' + version + '_HOME'
String versionedJavaHome = System.getenv(versionedVarName)
String versionedVarName = getJavaHomeEnvVarName(version)
String versionedJavaHome = System.getenv(versionedVarName);
if (versionedJavaHome == null) {
throw new GradleException(
"$versionedVarName must be set to build Elasticsearch. " +
@ -259,6 +261,10 @@ class BuildPlugin implements Plugin<Project> {
return versionedJavaHome
}
private static String getJavaHomeEnvVarName(String version) {
return 'JAVA' + version + '_HOME'
}
/** Add a check before gradle execution phase which ensures java home for the given java version is set. */
static void requireJavaHome(Task task, int version) {
Project rootProject = task.project.rootProject // use root project for global accounting