Unverified Commit 050ee9d1 authored by jcollins-g's avatar jcollins-g Committed by GitHub

Improve robustness of --version parsing for sdkmanager (#15029)

parent 701eff4a
......@@ -347,7 +347,8 @@ class AndroidSdk {
throwToolExit('Android sdkmanager not found. Update to the latest Android SDK to resolve this.');
final ProcessResult result = processManager.runSync(<String>[sdkManagerPath, '--version'], environment: sdkManagerEnv);
if (result.exitCode != 0) {
throwToolExit('sdkmanager --version failed: ${result.exitCode}', exitCode: result.exitCode);
printTrace('sdkmanager --version failed: exitCode: ${result.exitCode} stdout: ${result.stdout} stderr: ${result.stderr}');
return null;
}
return result.stdout.trim();
}
......
......@@ -213,7 +213,7 @@ class AndroidWorkflow extends DoctorValidator implements Workflow {
);
final Version sdkManagerVersion = new Version.parse(androidSdk.sdkManagerVersion);
if (sdkManagerVersion.major < 26)
if (sdkManagerVersion == null || sdkManagerVersion.major < 26)
// SDK manager is found, but needs to be updated.
throwToolExit(
'A newer version of the Android SDK is required. To update, run:\n'
......
......@@ -81,7 +81,7 @@ void main() {
ProcessManager: () => processManager,
});
testUsingContext('throws on sdkmanager version check failure', () {
testUsingContext('does not throw on sdkmanager version check failure', () {
sdkDir = MockAndroidSdk.createSdkDirectory();
Config.instance.setValue('android-sdk', sdkDir.path);
......@@ -89,7 +89,7 @@ void main() {
when(processManager.canRun(sdk.sdkManagerPath)).thenReturn(true);
when(processManager.runSync(<String>[sdk.sdkManagerPath, '--version'], environment: argThat(isNotNull)))
.thenReturn(new ProcessResult(1, 1, '26.1.1\n', 'Mystery error'));
expect(() => sdk.sdkManagerVersion, throwsToolExit(exitCode: 1));
expect(sdk.sdkManagerVersion, isNull);
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => processManager,
......
......@@ -132,7 +132,21 @@ void main() {
when(sdk.sdkManagerPath).thenReturn('/foo/bar/sdkmanager');
when(sdk.sdkManagerVersion).thenReturn('25.0.0');
expect(AndroidWorkflow.runLicenseManager(), throwsToolExit());
expect(AndroidWorkflow.runLicenseManager(), throwsToolExit(message: 'To update, run'));
}, overrides: <Type, Generator>{
AndroidSdk: () => sdk,
FileSystem: () => fs,
Platform: () => new FakePlatform()..environment = <String, String>{'HOME': '/home/me'},
ProcessManager: () => processManager,
Stdio: () => stdio,
});
testUsingContext('runLicenseManager errors correctly for null version', () async {
MockAndroidSdk.createSdkDirectory();
when(sdk.sdkManagerPath).thenReturn('/foo/bar/sdkmanager');
when(sdk.sdkManagerVersion).thenReturn(null);
expect(AndroidWorkflow.runLicenseManager(), throwsToolExit(message: 'To update, run'));
}, overrides: <Type, Generator>{
AndroidSdk: () => sdk,
FileSystem: () => fs,
......
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