Unverified Commit 94079b9c authored by Reid Baker's avatar Reid Baker Committed by GitHub

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.
parent 750e232b
......@@ -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;
}
......
......@@ -280,6 +280,26 @@ OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
expect(version.toString(), 'openjdk 19.0 2023-01-17');
expect(version, equals(Version(19, 0, null)));
});
testWithoutContext('parses jdk 21 with patch numbers', () {
addJavaVersionCommand('''
java 21.0.1 2023-09-19 LTS
Java(TM) SE Runtime Environment (build 21+35-LTS-2513)
Java HotSpot(TM) 64-Bit Server VM (build 21+35-LTS-2513, mixed mode, sharing)
''');
final Version? version = java.version;
expect(version, equals(Version(21, 0, 1)));
});
testWithoutContext('parses jdk 21 with no patch numbers', () {
addJavaVersionCommand('''
java 21 2023-09-19 LTS
Java(TM) SE Runtime Environment (build 21+35-LTS-2513)
Java HotSpot(TM) 64-Bit Server VM (build 21+35-LTS-2513, mixed mode, sharing)
''');
final Version? version = java.version;
expect(version, equals(Version(21, 0, 0)));
});
});
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment