Unverified Commit 311193d3 authored by Reid Baker's avatar Reid Baker Committed by GitHub

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.
parent 23289958
...@@ -148,8 +148,8 @@ class Java { ...@@ -148,8 +148,8 @@ class Java {
// Should look something like 'openjdk 19.0.2 2023-01-17'. // Should look something like 'openjdk 19.0.2 2023-01-17'.
final String longVersionText = versionLines.length >= 2 ? versionLines[1] : versionLines[0]; 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'. // The contents that matter come in the format '11.0.18', '1.8.0_202 or 21'.
final RegExp jdkVersionRegex = RegExp(r'\d+\.\d+(\.\d+(?:_\d+)?)?'); final RegExp jdkVersionRegex = RegExp(r'(?<version>\d+(\.\d+(\.\d+(?:_\d+)?)?)?)');
final Iterable<RegExpMatch> matches = final Iterable<RegExpMatch> matches =
jdkVersionRegex.allMatches(rawVersionOutput); jdkVersionRegex.allMatches(rawVersionOutput);
if (matches.isEmpty) { if (matches.isEmpty) {
...@@ -167,7 +167,7 @@ class Java { ...@@ -167,7 +167,7 @@ class Java {
_logger.printWarning(_formatJavaVersionWarning(rawVersionOutput)); _logger.printWarning(_formatJavaVersionWarning(rawVersionOutput));
return null; return null;
} }
final String? version = matches.first.group(0); final String? version = matches.first.namedGroup('version');
if (version == null || version.split('_').isEmpty) { if (version == null || version.split('_').isEmpty) {
_logger.printWarning(_formatJavaVersionWarning(rawVersionOutput)); _logger.printWarning(_formatJavaVersionWarning(rawVersionOutput));
return null; return null;
......
...@@ -296,6 +296,15 @@ Java HotSpot(TM) 64-Bit Server VM (build 21+35-LTS-2513, mixed mode, sharing) ...@@ -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 21 2023-09-19 LTS
Java(TM) SE Runtime Environment (build 21+35-LTS-2513) 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) 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; final Version? version = java.version;
expect(version, equals(Version(21, 0, 0))); 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