mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
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:
parent
750e232be1
commit
94079b9c61
@ -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)));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user