mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-31 17:32:51 +08:00
CB-12640: better handling of unrecognized commands on windows. removed error checking in emulator image listing when shelling out, as we already defensively dont shell out if the program is not on the PATH / not recognized. added additional test for windows unrecognized command errors for target listing. fixed up spying in a test.
This commit is contained in:
parent
bd94735ba2
commit
af31c83ec1
4
bin/templates/cordova/lib/android_sdk.js
vendored
4
bin/templates/cordova/lib/android_sdk.js
vendored
@ -1,5 +1,3 @@
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Licensed to the Apache Software Foundation (ASF) under one
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
or more contributor license agreements. See the NOTICE file
|
or more contributor license agreements. See the NOTICE file
|
||||||
@ -95,7 +93,7 @@ module.exports.list_targets = function() {
|
|||||||
// If there's an error, like avdmanager could not be found, we can try
|
// If there's an error, like avdmanager could not be found, we can try
|
||||||
// as a last resort, to run `android`, in case this is a super old
|
// as a last resort, to run `android`, in case this is a super old
|
||||||
// SDK installation.
|
// SDK installation.
|
||||||
if (err && err.code == 'ENOENT') {
|
if (err && (err.code == 'ENOENT' || (err.stderr && err.stderr.match(/not recognized/)))) {
|
||||||
return module.exports.list_targets_with_android();
|
return module.exports.list_targets_with_android();
|
||||||
} else throw err;
|
} else throw err;
|
||||||
})
|
})
|
||||||
|
12
bin/templates/cordova/lib/emulator.js
vendored
12
bin/templates/cordova/lib/emulator.js
vendored
@ -172,17 +172,7 @@ module.exports.list_images_using_android = function() {
|
|||||||
*/
|
*/
|
||||||
module.exports.list_images = function() {
|
module.exports.list_images = function() {
|
||||||
if (forgivingWhichSync('avdmanager')) {
|
if (forgivingWhichSync('avdmanager')) {
|
||||||
return module.exports.list_images_using_avdmanager()
|
return module.exports.list_images_using_avdmanager();
|
||||||
.catch(function(err) {
|
|
||||||
// try to use `avdmanager` in case `android` reports it is no longer available.
|
|
||||||
// this likely means the target machine is using a newer version of
|
|
||||||
// the android sdk, and possibly `avdmanager` is available.
|
|
||||||
if (err && err.code == 'ENOENT') {
|
|
||||||
return module.exports.list_images_using_android();
|
|
||||||
} else {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (forgivingWhichSync('android')) {
|
} else if (forgivingWhichSync('android')) {
|
||||||
return module.exports.list_images_using_android();
|
return module.exports.list_images_using_android();
|
||||||
} else {
|
} else {
|
||||||
|
@ -98,9 +98,26 @@ describe("android_sdk", function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it("should parse Android SDK installed target information with `android` command if list_targets_with_avdmanager fails with not-recognized error (Windows)", function(done) {
|
||||||
|
var deferred = Q.defer();
|
||||||
|
spyOn(android_sdk, "list_targets_with_avdmanager").and.returnValue(deferred.promise);
|
||||||
|
deferred.reject({
|
||||||
|
code: 1,
|
||||||
|
stderr: "'avdmanager' is not recognized as an internal or external commmand,\r\noperable program or batch file.\r\n"
|
||||||
|
});
|
||||||
|
var twoferred = Q.defer();
|
||||||
|
twoferred.resolve(["target1"]);
|
||||||
|
var avdmanager_spy = spyOn(android_sdk, "list_targets_with_android").and.returnValue(twoferred.promise);
|
||||||
|
return android_sdk.list_targets()
|
||||||
|
.then(function(targets) {
|
||||||
|
expect(avdmanager_spy).toHaveBeenCalled();
|
||||||
|
expect(targets[0]).toEqual("target1");
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
it("should throw an error if no Android targets were found.", function(done) {
|
it("should throw an error if no Android targets were found.", function(done) {
|
||||||
var deferred = Q.defer();
|
var deferred = Q.defer();
|
||||||
spyOn(android_sdk, "list_targets_with_android").and.returnValue(deferred.promise);
|
spyOn(android_sdk, "list_targets_with_avdmanager").and.returnValue(deferred.promise);
|
||||||
deferred.resolve([]);
|
deferred.resolve([]);
|
||||||
return android_sdk.list_targets()
|
return android_sdk.list_targets()
|
||||||
.then(function(targets) {
|
.then(function(targets) {
|
||||||
|
@ -88,23 +88,14 @@ describe("emulator", function () {
|
|||||||
emu.list_images();
|
emu.list_images();
|
||||||
expect(avdmanager_spy).toHaveBeenCalled();
|
expect(avdmanager_spy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
it("should catch if `avdmanager` exits with non-zero code, and delegate to `android` if it can find it", function() {
|
it("should delegate to `android` if `avdmanager` cant be found and `android` can", function() {
|
||||||
spyOn(shelljs, "which").and.callFake(function(cmd) {
|
spyOn(shelljs, "which").and.callFake(function(cmd) {
|
||||||
if (cmd == "avdmanager") {
|
if (cmd == "avdmanager") {
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
spyOn(emu, "list_images_using_avdmanager").and.returnValue({
|
|
||||||
catch:function(cb) {
|
|
||||||
cb({
|
|
||||||
code: "ENOENT"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Fake out the old promise to feign a failed `android` command
|
|
||||||
var android_spy = spyOn(emu, "list_images_using_android");
|
var android_spy = spyOn(emu, "list_images_using_android");
|
||||||
emu.list_images();
|
emu.list_images();
|
||||||
expect(android_spy).toHaveBeenCalled();
|
expect(android_spy).toHaveBeenCalled();
|
||||||
|
Loading…
Reference in New Issue
Block a user