Edge case on flutter/flutter/issues/135402 with test (#138814)
fixes flutter/flutter/issues/135402 Edge case that was reported by a user along with a test case specifically covering their output.
This commit is contained in:
@@ -148,8 +148,8 @@ class Java {
|
||||
// Should look something like 'openjdk 19.0.2 2023-01-17'.
|
||||
final String longVersionText = versionLines.length >= 2 ? versionLines[1] : versionLines[0];
|
||||
|
||||
// The contents that matter come in the format '11.0.18' or '1.8.0_202'.
|
||||
final RegExp jdkVersionRegex = RegExp(r'\d+\.\d+(\.\d+(?:_\d+)?)?');
|
||||
// The contents that matter come in the format '11.0.18', '1.8.0_202 or 21'.
|
||||
final RegExp jdkVersionRegex = RegExp(r'(?<version>\d+(\.\d+(\.\d+(?:_\d+)?)?)?)');
|
||||
final Iterable<RegExpMatch> matches =
|
||||
jdkVersionRegex.allMatches(rawVersionOutput);
|
||||
if (matches.isEmpty) {
|
||||
@@ -167,7 +167,7 @@ class Java {
|
||||
_logger.printWarning(_formatJavaVersionWarning(rawVersionOutput));
|
||||
return null;
|
||||
}
|
||||
final String? version = matches.first.group(0);
|
||||
final String? version = matches.first.namedGroup('version');
|
||||
if (version == null || version.split('_').isEmpty) {
|
||||
_logger.printWarning(_formatJavaVersionWarning(rawVersionOutput));
|
||||
return null;
|
||||
|
||||
@@ -296,6 +296,15 @@ Java HotSpot(TM) 64-Bit Server VM (build 21+35-LTS-2513, mixed mode, sharing)
|
||||
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)));
|
||||
});
|
||||
testWithoutContext('parses openjdk 21 with no patch numbers', () {
|
||||
addJavaVersionCommand('''
|
||||
openjdk version "21" 2023-09-19
|
||||
OpenJDK Runtime Environment (build 21+35)
|
||||
OpenJDK 64-Bit Server VM (build 21+35, mixed mode, sharing)
|
||||
''');
|
||||
final Version? version = java.version;
|
||||
expect(version, equals(Version(21, 0, 0)));
|
||||
|
||||
Reference in New Issue
Block a user