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"]
errorOutput = stream
}
def matcher = stream.toString() =~ /^(?:java|openjdk) version "([^"]+)"/
if (matcher) {
def version = JavaVersion.toVersion(matcher.group(1))
cache.put(path, version)
return version
} else {
throw new GradleScriptException("Cannot determine java version: ${stream.toString}")
def output = stream.toString()
for (def line : output.split('\n')) {
line = line.trim()
def matcher = line =~ /^(?:java|openjdk) version "([^"]+)"/
if (matcher) {
def version = JavaVersion.toVersion(matcher.group(1))
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)
}
}