From 248eceac4a6404ecdb9e0eea5d8d6a55248752a0 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Fri, 11 Sep 2015 18:21:05 +0300 Subject: [PATCH] Fix doctor command output In case gradle is not setup correctly or some of the required Android Tools are missing, `tns doctor` command show the warnings, but at the end a "No issues detected" message is shown. Make sure to prevent such message when there are issues by modifying validateInfo's return type to boolean and use it in doctor service. --- lib/android-tools-info.ts | 13 ++++++++++--- lib/declarations.ts | 4 ++-- lib/services/doctor-service.ts | 7 +++++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/android-tools-info.ts b/lib/android-tools-info.ts index 773a207307..a22d7ff4a9 100644 --- a/lib/android-tools-info.ts +++ b/lib/android-tools-info.ts @@ -39,8 +39,9 @@ export class AndroidToolsInfo implements IAndroidToolsInfo { }).future()(); } - public validateInfo(options?: {showWarningsAsErrors: boolean, validateTargetSdk: boolean}): IFuture { - return (() => { + public validateInfo(options?: {showWarningsAsErrors: boolean, validateTargetSdk: boolean}): IFuture { + return (() : boolean => { + let detectedErrors = false; this.showWarningsAsErrors = options && options.showWarningsAsErrors; let toolsInfoData = this.getToolsInfo().wait(); if(!toolsInfoData.androidHomeEnvVar || !this.$fs.exists(toolsInfoData.androidHomeEnvVar).wait()) { @@ -51,6 +52,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo { if(!toolsInfoData.compileSdkVersion) { this.printMessage(`Cannot find a compatible Android SDK for compilation. To be able to build for Android, install Android SDK ${AndroidToolsInfo.MIN_REQUIRED_COMPILE_TARGET} or later.`, "Run `$ android` to manage your Android SDK versions."); + detectedErrors = true; } if(!toolsInfoData.buildToolsVersion) { @@ -65,11 +67,13 @@ export class AndroidToolsInfo implements IAndroidToolsInfo { this.printMessage("You need to have the Android SDK Build-tools installed on your system. " + message, 'Run "android" from your command-line to install required Android Build Tools.'); + detectedErrors = true; } if(!toolsInfoData.supportRepositoryVersion) { this.printMessage(`You need to have the latest Android Support Repository installed on your system.`, 'Run `$ android` to manage the Android Support Repository.'); + detectedErrors = true; } if(options && options.validateTargetSdk) { @@ -81,12 +85,15 @@ export class AndroidToolsInfo implements IAndroidToolsInfo { if(targetSdk && (targetSdk < minSupportedVersion)) { this.printMessage(`The selected Android target SDK ${newTarget} is not supported. You must target ${minSupportedVersion} or later.`); + detectedErrors = true; } else if(!targetSdk || targetSdk > this.getMaxSupportedVersion()) { this.$logger.warn(`Support for the selected Android target SDK ${newTarget} is not verified. Your Android app might not work as expected.`); } } } - }).future()(); + + return detectedErrors; + }).future()(); } /** diff --git a/lib/declarations.ts b/lib/declarations.ts index 26febe1e6d..529e96c6c7 100644 --- a/lib/declarations.ts +++ b/lib/declarations.ts @@ -105,9 +105,9 @@ interface IAndroidToolsInfo { /** * Validates the information about required Android tools and SDK versions. * @param {any} options Defines if the warning messages should treated as error and if the targetSdk value should be validated as well. - * @return {void} + * @return {boolean} True if there are detected issues, false otherwise. */ - validateInfo(options?: {showWarningsAsErrors: boolean, validateTargetSdk: boolean}): IFuture; + validateInfo(options?: {showWarningsAsErrors: boolean, validateTargetSdk: boolean}): IFuture; } /** diff --git a/lib/services/doctor-service.ts b/lib/services/doctor-service.ts index dd12b92ca2..1f8aae0c70 100644 --- a/lib/services/doctor-service.ts +++ b/lib/services/doctor-service.ts @@ -69,12 +69,14 @@ class DoctorService implements IDoctorService { this.$logger.warn("WARNING: Gradle is not installed or is not configured properly."); this.$logger.out("You will not be able to build your projects for Android or run them in the emulator or on a connected device." + EOL + "To be able to build for Android and run apps in the emulator or on a connected device, verify that you have installed Gradle."); + result = true; } if(sysInfo.gradleVer && helpers.versionCompare(sysInfo.gradleVer, DoctorService.MIN_SUPPORTED_GRADLE_VERSION) === -1) { this.$logger.warn(`WARNING: Gradle version is lower than ${DoctorService.MIN_SUPPORTED_GRADLE_VERSION}.`); this.$logger.out("You will not be able to build your projects for Android or run them in the emulator or on a connected device." + EOL + `To be able to build for Android and run apps in the emulator or on a connected device, verify thqt you have at least ${DoctorService.MIN_SUPPORTED_GRADLE_VERSION} version installed.`); + result = true; } if(!sysInfo.javacVersion) { @@ -82,10 +84,11 @@ class DoctorService implements IDoctorService { this.$logger.out("You will not be able to build your projects for Android." + EOL + "To be able to build for Android, verify that you have installed The Java Development Kit (JDK) and configured it according to system requirements as" + EOL + " described in https://github.com/NativeScript/nativescript-cli#system-requirements."); + result = true; } - this.$androidToolsInfo.validateInfo().wait(); - return result; + let androidToolsIssues = this.$androidToolsInfo.validateInfo().wait(); + return result || androidToolsIssues; } private printPackageManagerTip() {