Improved Java version parsing (#138155)

Fixes #135402
Add fallback logic for a different format of java version output and handle no patch versions. 
Add tests for new logic output to prevent regressions.
This commit is contained in:
Reid Baker
2023-11-09 13:38:18 -05:00
committed by GitHub
parent 750e232be1
commit 94079b9c61
2 changed files with 31 additions and 0 deletions

View File

@@ -153,6 +153,17 @@ class Java {
final Iterable<RegExpMatch> matches =
jdkVersionRegex.allMatches(rawVersionOutput);
if (matches.isEmpty) {
// Fallback to second string format like "java 21.0.1 2023-09-19 LTS"
final RegExp secondJdkVersionRegex =
RegExp(r'java\s+(?<version>\d+(\.\d+)?(\.\d+)?)\s+\d\d\d\d-\d\d-\d\d');
final RegExpMatch? match = secondJdkVersionRegex.firstMatch(versionLines[0]);
if (match != null) {
final Version? parsedVersion = Version.parse(match.namedGroup('version'));
if (parsedVersion == null) {
return null;
}
return parsedVersion;
}
_logger.printWarning(_formatJavaVersionWarning(rawVersionOutput));
return null;
}