Fixed error handling when Java version can't be determined (#118)

* Fixed error handling when Java version can't be determined

* Made build getJavaExecutableVersion more resilient to output variations
This commit is contained in:
Pontus Rydin 2020-02-03 15:38:21 -05:00 committed by GitHub
parent 37b314fa0c
commit bec7775d56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 7 deletions

View File

@ -234,14 +234,19 @@ JavaVersion getJavaExecutableVersion(String path) {
commandLine = [path, "-version"] commandLine = [path, "-version"]
errorOutput = stream errorOutput = stream
} }
def matcher = stream.toString() =~ /^(?:java|openjdk) version "([^"]+)"/ def output = stream.toString()
if (matcher) { for (def line : output.split('\n')) {
def version = JavaVersion.toVersion(matcher.group(1)) line = line.trim()
cache.put(path, version) def matcher = line =~ /^(?:java|openjdk) version "([^"]+)"/
return version if (matcher) {
} else { def version = JavaVersion.toVersion(matcher.group(1))
throw new GradleScriptException("Cannot determine java version: ${stream.toString}") cache.put(path, version)
return version
}
} }
// Getting here means we didn't find a line matching the version pattern.
throw new GradleScriptException("Cannot determine java version. Executable: ${path}, output: ${output}", null)
} }
} }