From 525ce0e0ad585542d149700a442e767e3ed93c8b Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Fri, 12 Sep 2014 14:19:13 -0400 Subject: [PATCH] CB-7536 Tweak error messages for missing JDK / SDK / AVDs --- bin/lib/check_reqs.js | 22 +++++++++++++++------- bin/templates/cordova/lib/emulator.js | 20 ++++++++------------ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js index edfa2733..4fa8b1db 100644 --- a/bin/lib/check_reqs.js +++ b/bin/lib/check_reqs.js @@ -126,13 +126,15 @@ module.exports.check_java = function() { } }).then(function() { var msg = - 'Failed to run "java -version", make sure your java environment is set up\n' + - 'including JDK and JRE.\n' + - 'Your JAVA_HOME variable is: ' + process.env['JAVA_HOME']; + 'Failed to run "java -version", make sure that you have a JDK installed.\n' + + 'You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.\n'; + if (process.env['JAVA_HOME']) { + msg += 'Your JAVA_HOME is invalid: ' + process.env['JAVA_HOME'] + '\n'; + } return tryCommand('java -version', msg) - }).then(function() { - msg = 'Failed to run "javac -version", make sure you have a Java JDK (not just a JRE) installed.'; - return tryCommand('javac -version', msg) + .then(function() { + return tryCommand('javac -version', msg); + }); }); } @@ -192,6 +194,10 @@ module.exports.check_android = function() { }); }; +module.exports.getAbsoluteAndroidCmd = function() { + return forgivingWhichSync('android').replace(/([ \\])/g, '\\$1'); +}; + module.exports.check_android_target = function(valid_target) { // valid_target can look like: // android-19 @@ -202,8 +208,10 @@ module.exports.check_android_target = function(valid_target) { return tryCommand('android list targets --compact', msg) .then(function(output) { if (output.split('\n').indexOf(valid_target) == -1) { + var androidCmd = module.exports.getAbsoluteAndroidCmd(); throw new Error('Please install Android target: "' + valid_target + '".\n' + - 'Hint: Open the SDK manager by running: ' + forgivingWhichSync('android')); + 'Hint: Open the SDK manager by running: ' + androidCmd + '\n' + + 'Or install directly via: ' + androidCmd + ' update sdk --no-ui --all --filter "' + valid_target + '"'); } }); }; diff --git a/bin/templates/cordova/lib/emulator.js b/bin/templates/cordova/lib/emulator.js index 69f0e1b5..4c3d451e 100644 --- a/bin/templates/cordova/lib/emulator.js +++ b/bin/templates/cordova/lib/emulator.js @@ -28,6 +28,7 @@ var shell = require('shelljs'), ROOT = path.join(__dirname, '..', '..'), child_process = require('child_process'), new_emulator = 'cordova_emulator'; +var check_reqs = require('./check_reqs'); /** * Returns a Promise for a list of emulator images in the form of objects @@ -84,7 +85,7 @@ module.exports.list_images = function() { * Returns a promise. */ module.exports.best_image = function() { - var project_target = this.get_target().replace('android-', ''); + var project_target = check_reqs.get_target().replace('android-', ''); return this.list_images() .then(function(images) { var closest = 9999; @@ -120,11 +121,6 @@ module.exports.list_started = function() { }); } -module.exports.get_target = function() { - var target = shell.grep(/target=android-[\d+]/, path.join(ROOT, 'project.properties')); - return target.split('=')[1].replace('\n', '').replace('\r', '').replace(' ', ''); -} - // Returns a promise. module.exports.list_targets = function() { return exec('android list targets') @@ -156,7 +152,7 @@ module.exports.start = function(emulator_ID) { .then(function(list) { started_emulators = list; num_started = started_emulators.length; - if (typeof emulator_ID === 'undefined') { + if (!emulator_ID) { return self.list_images() .then(function(emulator_list) { if (emulator_list.length > 0) { @@ -167,11 +163,11 @@ module.exports.start = function(emulator_ID) { return emulator_ID; }); } else { - return Q.reject('ERROR : No emulator images (avds) found, if you would like to create an\n' + - ' avd follow the instructions provided here:\n' + - ' http://developer.android.com/tools/devices/index.html\n' + - ' Or run \'android create avd --name --target \'\n' + - ' in on the command line.'); + var androidCmd = check_reqs.getAbsoluteAndroidCmd(); + return Q.reject('ERROR : No emulator images (avds) found.\n' + + '1. Download desired System Image by running: ' + androidCmd + ' sdk\n' + + '2. Create an AVD by running: ' + androidCmd + ' avd\n' + 'HINT: For a faster emulator, use an Intel System Image and install the HAXM device driver\n'); } }); } else {