CB-7536 Tweak error messages for missing JDK / SDK / AVDs

This commit is contained in:
Andrew Grieve 2014-09-12 14:19:13 -04:00
parent 2f7ffa3636
commit 525ce0e0ad
2 changed files with 23 additions and 19 deletions

View File

@ -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 + '"');
}
});
};

View File

@ -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 <name> --target <targetID>\'\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 {