mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[CP (beta)] have Java.version return null if java --version fails or cannot be run (#139838)
cherry-picks changes from https://github.com/flutter/flutter/pull/139614 onto the beta channel
This commit is contained in:
parent
593a031efb
commit
f5a2ca0b9d
@ -135,6 +135,10 @@ class Java {
|
||||
/// Returns the version of java in the format \d(.\d)+(.\d)+
|
||||
/// Returns null if version could not be determined.
|
||||
late final Version? version = (() {
|
||||
if (!canRun()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final RunResult result = _processUtils.runSync(
|
||||
<String>[binaryPath, '--version'],
|
||||
environment: environment,
|
||||
@ -142,6 +146,7 @@ class Java {
|
||||
if (result.exitCode != 0) {
|
||||
_logger.printTrace('java --version failed: exitCode: ${result.exitCode}'
|
||||
' stdout: ${result.stdout} stderr: ${result.stderr}');
|
||||
return null;
|
||||
}
|
||||
final String rawVersionOutput = result.stdout;
|
||||
final List<String> versionLines = rawVersionOutput.split('\n');
|
||||
|
||||
@ -183,7 +183,7 @@ OpenJDK 64-Bit Server VM Zulu19.32+15-CA (build 19.0.2+7, mixed mode, sharing)
|
||||
});
|
||||
});
|
||||
|
||||
group('getVersionString', () {
|
||||
group('version', () {
|
||||
late Java java;
|
||||
|
||||
setUp(() {
|
||||
@ -208,6 +208,23 @@ OpenJDK 64-Bit Server VM Zulu19.32+15-CA (build 19.0.2+7, mixed mode, sharing)
|
||||
);
|
||||
}
|
||||
|
||||
testWithoutContext('is null when java binary cannot be run', () async {
|
||||
addJavaVersionCommand('');
|
||||
processManager.excludedExecutables.add('java');
|
||||
|
||||
expect(java.version, null);
|
||||
});
|
||||
|
||||
testWithoutContext('is null when java --version returns a non-zero exit code', () async {
|
||||
processManager.addCommand(
|
||||
FakeCommand(
|
||||
command: <String>[java.binaryPath, '--version'],
|
||||
exitCode: 1,
|
||||
),
|
||||
);
|
||||
expect(java.version, null);
|
||||
});
|
||||
|
||||
testWithoutContext('parses jdk 8', () {
|
||||
addJavaVersionCommand('''
|
||||
java version "1.8.0_202"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user