cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [01/12] android commit: CB-12546: more robust sdk location detection. ANDROID_HOME now can be set from location of either of `adb`, `android` or `avdmanager` commands. slightly rework logic of infering ANDROID_HOME + setting up PATH to hopefully separate
Date Mon, 20 Mar 2017 17:51:19 GMT
Repository: cordova-android
Updated Branches:
  refs/heads/master e2af492a6 -> 2f2e8a560


CB-12546: more robust sdk location detection. ANDROID_HOME now can be set from location of
either of `adb`, `android` or `avdmanager` commands. slightly rework logic of infering ANDROID_HOME
+ setting up PATH to hopefully separate the logic into clearer sections. check_reqs.check_android
now validates SDK Tools 25.3.1 binaries/structure. added specs for check_reqs.check_android.
move android sdk version script. expose some helper functions as module methods to help with
mocking.


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/eb6ada80
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/eb6ada80
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/eb6ada80

Branch: refs/heads/master
Commit: eb6ada80917e01e86d247409bfe8fbe5a60b4de8
Parents: a7ef686
Author: filmaj <maj.fil@gmail.com>
Authored: Mon Mar 13 23:44:52 2017 -0700
Committer: filmaj <maj.fil@gmail.com>
Committed: Mon Mar 20 10:08:35 2017 -0700

----------------------------------------------------------------------
 bin/android_sdk_version                  |   2 +-
 bin/lib/android_sdk.js                   |  78 ----------
 bin/lib/check_reqs.js                    |  86 ++++++++---
 bin/templates/cordova/lib/android_sdk.js |  78 ++++++++++
 bin/templates/cordova/lib/emulator.js    |  12 +-
 spec/unit/check_reqs.spec.js             | 214 ++++++++++++++++++++++++++
 6 files changed, 360 insertions(+), 110 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/eb6ada80/bin/android_sdk_version
----------------------------------------------------------------------
diff --git a/bin/android_sdk_version b/bin/android_sdk_version
index 6140e11..4d120c6 100755
--- a/bin/android_sdk_version
+++ b/bin/android_sdk_version
@@ -19,7 +19,7 @@
        under the License.
 */
 
-var android_sdk_version = require('./lib/android_sdk');
+var android_sdk_version = require('./templates/cordova/lib/android_sdk');
 
 android_sdk_version.run().done(null, function(err) {
     console.log(err);

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/eb6ada80/bin/lib/android_sdk.js
----------------------------------------------------------------------
diff --git a/bin/lib/android_sdk.js b/bin/lib/android_sdk.js
deleted file mode 100755
index dbec25e..0000000
--- a/bin/lib/android_sdk.js
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/usr/bin/env node
-
-/*
-       Licensed to the Apache Software Foundation (ASF) under one
-       or more contributor license agreements.  See the NOTICE file
-       distributed with this work for additional information
-       regarding copyright ownership.  The ASF licenses this file
-       to you under the Apache License, Version 2.0 (the
-       "License"); you may not use this file except in compliance
-       with the License.  You may obtain a copy of the License at
-
-         http://www.apache.org/licenses/LICENSE-2.0
-
-       Unless required by applicable law or agreed to in writing,
-       software distributed under the License is distributed on an
-       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-       KIND, either express or implied.  See the License for the
-       specific language governing permissions and limitations
-       under the License.
-*/
-
-var child_process = require('child_process'),
-    Q     = require('q');
-
-var get_highest_sdk = function(results){
-    var reg = /\d+/;
-    var apiLevels = [];
-    for(var i=0;i<results.length;i++){
-        apiLevels[i] = parseInt(results[i].match(reg)[0]);
-    }
-    apiLevels.sort(function(a,b){return b-a;});
-    console.log(apiLevels[0]);
-};
-
-var get_sdks = function() {
-    var d = Q.defer();
-    child_process.exec('android list targets', function(err, stdout, stderr) {
-        if (err) d.reject(stderr);
-        else d.resolve(stdout);
-    });
-
-    return d.promise.then(function(output) {
-        var reg = /android-\d+/gi;
-        var results = output.match(reg);
-        if(results.length===0){
-            return Q.reject(new Error('No android sdks installed.'));
-        }else{
-            get_highest_sdk(results);
-        }
-
-        return Q();
-    }, function(stderr) {
-        if (stderr.match(/command\snot\sfound/) || stderr.match(/'android' is not recognized/))
{
-            return Q.reject(new Error('The command \"android\" failed. Make sure you have
the latest Android SDK installed, and the \"android\" command (inside the tools/ folder) is
added to your path.'));
-        } else {
-            return Q.reject(new Error('An error occurred while listing Android targets'));
-        }
-    });
-};
-
-module.exports.run = function() {
-    return Q.all([get_sdks()]);
-};
-
-module.exports.version_string_to_api_level = {
-    '4.0': 14,
-    '4.0.3': 15,
-    '4.1': 16,
-    '4.2': 17,
-    '4.3': 18,
-    '4.4': 19,
-    '4.4W': 20,
-    '5.0': 21,
-    '5.1': 22,
-    '6.0': 23,
-    '7.0': 24,
-    '7.1.1': 25
-};

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/eb6ada80/bin/lib/check_reqs.js
----------------------------------------------------------------------
diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js
index b368ecc..6c93c4d 100644
--- a/bin/lib/check_reqs.js
+++ b/bin/lib/check_reqs.js
@@ -30,7 +30,6 @@ var shelljs = require('shelljs'),
     ROOT  = path.join(__dirname, '..', '..');
 var CordovaError = require('cordova-common').CordovaError;
 
-var isWindows = process.platform == 'win32';
 
 function forgivingWhichSync(cmd) {
     try {
@@ -51,6 +50,14 @@ function tryCommand(cmd, errMsg, catchStderr) {
     return d.promise;
 }
 
+module.exports.isWindows = function() {
+    return (process.platform == 'win32');
+};
+
+module.exports.isDarwin = function() {
+    return (process.platform == 'darwin');
+};
+
 // Get valid target from framework/project.properties
 module.exports.get_target = function() {
     function extractFromFile(filePath) {
@@ -147,7 +154,7 @@ module.exports.check_java = function() {
                         throw new CordovaError(msg);
                     }
                 }
-            } else if (isWindows) {
+            } else if (module.exports.isWindows()) {
                 // Try to auto-detect java in the default install paths.
                 var oldSilent = shelljs.config.silent;
                 shelljs.config.silent = true;
@@ -188,7 +195,8 @@ module.exports.check_java = function() {
 module.exports.check_android = function() {
     return Q().then(function() {
         var androidCmdPath = forgivingWhichSync('android');
-        var adbInPath = !!forgivingWhichSync('adb');
+        var adbInPath = forgivingWhichSync('adb');
+        var avdmanagerInPath = forgivingWhichSync('avdmanager');
         var hasAndroidHome = !!process.env['ANDROID_HOME'] && fs.existsSync(process.env['ANDROID_HOME']);
         function maybeSetAndroidHome(value) {
             if (!hasAndroidHome && fs.existsSync(value)) {
@@ -196,8 +204,10 @@ module.exports.check_android = function() {
                 process.env['ANDROID_HOME'] = value;
             }
         }
-        if (!hasAndroidHome && !androidCmdPath) {
-            if (isWindows) {
+        // First ensure ANDROID_HOME is set
+        // If we have no hints (nothing in PATH), try a few default locations
+        if (!hasAndroidHome && !androidCmdPath && !adbInPath && !avdmanagerInPath)
{
+            if (module.exports.isWindows()) {
                 // Android Studio 1.0 installer
                 maybeSetAndroidHome(path.join(process.env['LOCALAPPDATA'], 'Android', 'sdk'));
                 maybeSetAndroidHome(path.join(process.env['ProgramFiles'], 'Android', 'sdk'));
@@ -207,7 +217,7 @@ module.exports.check_android = function() {
                 // Stand-alone installer
                 maybeSetAndroidHome(path.join(process.env['LOCALAPPDATA'], 'Android', 'android-sdk'));
                 maybeSetAndroidHome(path.join(process.env['ProgramFiles'], 'Android', 'android-sdk'));
-            } else if (process.platform == 'darwin') {
+            } else if (module.exports.isDarwin()) {
                 // Android Studio 1.0 installer
                 maybeSetAndroidHome(path.join(process.env['HOME'], 'Library', 'Android',
'sdk'));
                 // Android Studio pre-1.0 installer
@@ -222,26 +232,42 @@ module.exports.check_android = function() {
                 maybeSetAndroidHome(path.join(process.env['HOME'], 'android-sdk'));
             }
         }
-        if (hasAndroidHome && !androidCmdPath) {
-            process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'],
'tools');
-        }
-        if (androidCmdPath && !hasAndroidHome) {
-            var parentDir = path.dirname(androidCmdPath);
-            var grandParentDir = path.dirname(parentDir);
-            if (path.basename(parentDir) == 'tools') {
-                process.env['ANDROID_HOME'] = path.dirname(parentDir);
-                hasAndroidHome = true;
-            } else if (fs.existsSync(path.join(grandParentDir, 'tools', 'android'))) {
-                process.env['ANDROID_HOME'] = grandParentDir;
-                hasAndroidHome = true;
-            } else {
-                throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable.
Try setting setting it manually.\n' +
-                    'Detected \'android\' command at ' + parentDir + ' but no \'tools\' directory
found near.\n' +
-                    'Try reinstall Android SDK or update your PATH to include path to valid
SDK directory.');
+        if (!hasAndroidHome) {
+            // If we dont have ANDROID_HOME, but we do have some tools on the PATH, try to
infer from the tooling PATH.
+            var parentDir, grandParentDir;
+            if (androidCmdPath) {
+                parentDir = path.dirname(androidCmdPath);
+                grandParentDir = path.dirname(parentDir);
+                if (path.basename(parentDir) == 'tools' || fs.existsSync(path.join(grandParentDir,
'tools', 'android'))) {
+                    maybeSetAndroidHome(grandParentDir);
+                } else {
+                    throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable.
Try setting setting it manually.\n' +
+                        'Detected \'android\' command at ' + parentDir + ' but no \'tools\'
directory found near.\n' +
+                        'Try reinstall Android SDK or update your PATH to include valid path
to SDK' + path.sep + 'tools directory.');
+                }
+            }
+            if (adbInPath) {
+                parentDir = path.dirname(adbInPath);
+                grandParentDir = path.dirname(parentDir);
+                if (path.basename(parentDir) == 'platform-tools') {
+                    maybeSetAndroidHome(grandParentDir);
+                } else {
+                    throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable.
Try setting setting it manually.\n' +
+                        'Detected \'adb\' command at ' + parentDir + ' but no \'platform-tools\'
directory found near.\n' +
+                        'Try reinstall Android SDK or update your PATH to include valid path
to SDK' + path.sep + 'platform-tools directory.');
+                }
+            }
+            if (avdmanagerInPath) {
+                parentDir = path.dirname(avdmanagerInPath);
+                grandParentDir = path.dirname(parentDir);
+                if (path.basename(parentDir) == 'bin' && path.basename(grandParentDir)
== 'tools') {
+                    maybeSetAndroidHome(path.dirname(grandParentDir));
+                } else {
+                    throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable.
Try setting setting it manually.\n' +
+                        'Detected \'avdmanager\' command at ' + parentDir + ' but no \'tools'
+ path.sep + 'bin\' directory found near.\n' +
+                        'Try reinstall Android SDK or update your PATH to include valid path
to SDK' + path.sep + 'tools' + path.sep + 'bin directory.');
+                }
             }
-        }
-        if (hasAndroidHome && !adbInPath) {
-            process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'],
'platform-tools');
         }
         if (!process.env['ANDROID_HOME']) {
             throw new CordovaError('Failed to find \'ANDROID_HOME\' environment variable.
Try setting setting it manually.\n' +
@@ -251,6 +277,16 @@ module.exports.check_android = function() {
             throw new CordovaError('\'ANDROID_HOME\' environment variable is set to non-existent
path: ' + process.env['ANDROID_HOME'] +
                 '\nTry update it manually to point to valid SDK directory.');
         }
+        // Next let's make sure relevant parts of the SDK tooling is in our PATH
+        if (hasAndroidHome && !androidCmdPath) {
+            process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'],
'tools');
+        }
+        if (hasAndroidHome && !adbInPath) {
+            process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'],
'platform-tools');
+        }
+        if (hasAndroidHome && !avdmanagerInPath) {
+            process.env['PATH'] += path.delimiter + path.join(process.env['ANDROID_HOME'],
'tools', 'bin');
+        }
         return hasAndroidHome;
     });
 };

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/eb6ada80/bin/templates/cordova/lib/android_sdk.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/android_sdk.js b/bin/templates/cordova/lib/android_sdk.js
new file mode 100755
index 0000000..dbec25e
--- /dev/null
+++ b/bin/templates/cordova/lib/android_sdk.js
@@ -0,0 +1,78 @@
+#!/usr/bin/env node
+
+/*
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+*/
+
+var child_process = require('child_process'),
+    Q     = require('q');
+
+var get_highest_sdk = function(results){
+    var reg = /\d+/;
+    var apiLevels = [];
+    for(var i=0;i<results.length;i++){
+        apiLevels[i] = parseInt(results[i].match(reg)[0]);
+    }
+    apiLevels.sort(function(a,b){return b-a;});
+    console.log(apiLevels[0]);
+};
+
+var get_sdks = function() {
+    var d = Q.defer();
+    child_process.exec('android list targets', function(err, stdout, stderr) {
+        if (err) d.reject(stderr);
+        else d.resolve(stdout);
+    });
+
+    return d.promise.then(function(output) {
+        var reg = /android-\d+/gi;
+        var results = output.match(reg);
+        if(results.length===0){
+            return Q.reject(new Error('No android sdks installed.'));
+        }else{
+            get_highest_sdk(results);
+        }
+
+        return Q();
+    }, function(stderr) {
+        if (stderr.match(/command\snot\sfound/) || stderr.match(/'android' is not recognized/))
{
+            return Q.reject(new Error('The command \"android\" failed. Make sure you have
the latest Android SDK installed, and the \"android\" command (inside the tools/ folder) is
added to your path.'));
+        } else {
+            return Q.reject(new Error('An error occurred while listing Android targets'));
+        }
+    });
+};
+
+module.exports.run = function() {
+    return Q.all([get_sdks()]);
+};
+
+module.exports.version_string_to_api_level = {
+    '4.0': 14,
+    '4.0.3': 15,
+    '4.1': 16,
+    '4.2': 17,
+    '4.3': 18,
+    '4.4': 19,
+    '4.4W': 20,
+    '5.0': 21,
+    '5.1': 22,
+    '6.0': 23,
+    '7.0': 24,
+    '7.1.1': 25
+};

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/eb6ada80/bin/templates/cordova/lib/emulator.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/emulator.js b/bin/templates/cordova/lib/emulator.js
index 7a58479..8554fe9 100644
--- a/bin/templates/cordova/lib/emulator.js
+++ b/bin/templates/cordova/lib/emulator.js
@@ -30,6 +30,7 @@ var events = require('cordova-common').events;
 var spawn = require('cordova-common').superspawn.spawn;
 var CordovaError = require('cordova-common').CordovaError;
 var shelljs = require('shelljs');
+var android_sdk = require('./android_sdk');
 
 var Q             = require('q');
 var os            = require('os');
@@ -52,7 +53,7 @@ function forgivingWhichSync(cmd) {
     }
 }
 
-function list_images_using_avdmanager() {
+module.exports.list_images_using_avdmanager = function () {
     return spawn('avdmanager', ['list', 'avd'])
     .then(function(output) {
         var response = output.split('\n');
@@ -90,7 +91,6 @@ function list_images_using_avdmanager() {
                         }
                         var version_string = img_obj['target'].replace(/Android\s+/, '');
 
-                        var android_sdk = require('./android_sdk');
                         var api_level = android_sdk.version_string_to_api_level[version_string];
                         if (api_level) {
                             img_obj['target'] += ' (API level ' + api_level + ')';
@@ -112,7 +112,7 @@ function list_images_using_avdmanager() {
         }
         return emulator_list;
     });
-}
+};
 
 /**
  * Returns a Promise for a list of emulator images in the form of objects
@@ -166,14 +166,14 @@ module.exports.list_images = function() {
 
             }
             return emulator_list;
-        }).catch(function(stderr) {
+        }).catch(function(err) {
             // try to use `avdmanager` in case `android` has problems
             // this likely means the target machine is using a newer version of
             // the android sdk, and possibly `avdmanager` is available.
-            return list_images_using_avdmanager();
+            return module.exports.list_images_using_avdmanager();
         });
     } else if (forgivingWhichSync('avdmanager')) {
-        return list_images_using_avdmanager();
+        return module.exports.list_images_using_avdmanager();
     } else {
         return Q().then(function() {
             throw new CordovaError('Could not find either `android` or `avdmanager` on your
$PATH! Are you sure the Android SDK is installed and available?');

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/eb6ada80/spec/unit/check_reqs.spec.js
----------------------------------------------------------------------
diff --git a/spec/unit/check_reqs.spec.js b/spec/unit/check_reqs.spec.js
new file mode 100644
index 0000000..1ddc352
--- /dev/null
+++ b/spec/unit/check_reqs.spec.js
@@ -0,0 +1,214 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+/* jshint laxcomma:true */
+
+var check_reqs = require("../../bin/lib/check_reqs");
+var shelljs = require("shelljs");
+var fs = require("fs");
+var path = require("path");
+
+describe("check_reqs", function () {
+    var original_env;
+    beforeAll(function() {
+        original_env = Object.create(process.env);
+    });
+    afterEach(function() {
+        Object.keys(original_env).forEach(function(k) {
+            process.env[k] = original_env[k];
+        });
+    });
+    describe("check_android", function() {
+        describe("set ANDROID_HOME if not set", function() {
+            beforeEach(function() {
+                delete process.env.ANDROID_HOME;
+            });
+            describe("even if no Android binaries are on the PATH", function() {
+                beforeEach(function() {
+                    spyOn(shelljs, "which").and.returnValue(null);
+                    spyOn(fs, "existsSync").and.returnValue(true);
+                });
+                it("it should set ANDROID_HOME on Windows", function(done) {
+                    spyOn(check_reqs, "isWindows").and.returnValue(true);
+                    process.env.LOCALAPPDATA = "windows-local-app-data";
+                    process.env.ProgramFiles = "windows-program-files";
+                    return check_reqs.check_android()
+                    .then(function() {
+                        expect(process.env.ANDROID_HOME).toContain("windows-local-app-data");
+                    }).fail(function(err) {
+                        expect(err).toBeUndefined();
+                        console.log(err);
+                    }).fin(function() {
+                        delete process.env.LOCALAPPDATA;
+                        delete process.env.ProgramFiles;
+                        done();
+                    });
+                });
+                it("it should set ANDROID_HOME on Darwin", function(done) {
+                    spyOn(check_reqs, "isWindows").and.returnValue(false);
+                    spyOn(check_reqs, "isDarwin").and.returnValue(true);
+                    process.env.HOME = "home is where the heart is";
+                    return check_reqs.check_android()
+                    .then(function() {
+                        expect(process.env.ANDROID_HOME).toContain("home is where the heart
is");
+                    }).fail(function(err) {
+                        expect(err).toBeUndefined();
+                        console.log(err);
+                    }).fin(function() {
+                        delete process.env.HOME;
+                        done();
+                    });
+                });
+            });
+            describe("if some Android tooling exists on the PATH", function() {
+                beforeEach(function() {
+                    spyOn(fs, "realpathSync").and.callFake(function(path) {
+                        return path;
+                    });
+                });
+                it("should set ANDROID_HOME based on `android` command if command exists
in a SDK-like directory structure", function(done) {
+                    spyOn(fs, "existsSync").and.returnValue(true);
+                    spyOn(shelljs, "which").and.callFake(function(cmd) {
+                        if (cmd == "android") {
+                            return "/android/sdk/tools/android";
+                        } else {
+                            return null;
+                        }
+                    });
+                    return check_reqs.check_android()
+                    .then(function() {
+                        expect(process.env.ANDROID_HOME).toEqual("/android/sdk");
+                        done();
+                    }).fail(function(err) {
+                        expect(err).toBeUndefined();
+                        console.log(err);
+                    });
+                });
+                it("should error out if `android` command exists in a non-SDK-like directory
structure", function(done) {
+                    spyOn(shelljs, "which").and.callFake(function(cmd) {
+                        if (cmd == "android") {
+                            return "/just/some/random/path/android";
+                        } else {
+                            return null;
+                        }
+                    });
+                    return check_reqs.check_android()
+                    .then(function() {
+                        done.fail();
+                    }).fail(function(err) {
+                        expect(err).toBeDefined();
+                        expect(err.message).toContain("update your PATH to include valid
path");
+                        done();
+                    });
+                });
+                it("should set ANDROID_HOME based on `adb` command if command exists in a
SDK-like directory structure", function(done) {
+                    spyOn(fs, "existsSync").and.returnValue(true);
+                    spyOn(shelljs, "which").and.callFake(function(cmd) {
+                        if (cmd == "adb") {
+                            return "/android/sdk/platform-tools/adb";
+                        } else {
+                            return null;
+                        }
+                    });
+                    return check_reqs.check_android()
+                    .then(function() {
+                        expect(process.env.ANDROID_HOME).toEqual("/android/sdk");
+                        done();
+                    }).fail(function(err) {
+                        expect(err).toBeUndefined();
+                        console.log(err);
+                    });
+                });
+                it("should error out if `adb` command exists in a non-SDK-like directory
structure", function(done) {
+                    spyOn(shelljs, "which").and.callFake(function(cmd) {
+                        if (cmd == "adb") {
+                            return "/just/some/random/path/adb";
+                        } else {
+                            return null;
+                        }
+                    });
+                    return check_reqs.check_android()
+                    .then(function() {
+                        done.fail();
+                    }).fail(function(err) {
+                        expect(err).toBeDefined();
+                        expect(err.message).toContain("update your PATH to include valid
path");
+                        done();
+                    });
+                });
+                it("should set ANDROID_HOME based on `avdmanager` command if command exists
in a SDK-like directory structure", function(done) {
+                    spyOn(fs, "existsSync").and.returnValue(true);
+                    spyOn(shelljs, "which").and.callFake(function(cmd) {
+                        if (cmd == "avdmanager") {
+                            return "/android/sdk/tools/bin/avdmanager";
+                        } else {
+                            return null;
+                        }
+                    });
+                    return check_reqs.check_android()
+                    .then(function() {
+                        expect(process.env.ANDROID_HOME).toEqual("/android/sdk");
+                        done();
+                    }).fail(function(err) {
+                        expect(err).toBeUndefined();
+                        console.log(err);
+                    });
+                });
+                it("should error out if `avdmanager` command exists in a non-SDK-like directory
structure", function(done) {
+                    spyOn(shelljs, "which").and.callFake(function(cmd) {
+                        if (cmd == "avdmanager") {
+                            return "/just/some/random/path/avdmanager";
+                        } else {
+                            return null;
+                        }
+                    });
+                    return check_reqs.check_android()
+                    .then(function() {
+                        done.fail();
+                    }).fail(function(err) {
+                        expect(err).toBeDefined();
+                        expect(err.message).toContain("update your PATH to include valid
path");
+                        done();
+                    });
+                });
+            });
+        });
+        describe("set PATH for various Android binaries if not available", function() {
+            beforeEach(function() {
+                spyOn(shelljs, "which").and.returnValue(null);
+                process.env.ANDROID_HOME = "let the children play";
+                spyOn(fs, "existsSync").and.returnValue(true);
+            });
+            afterEach(function() {
+                delete process.env.ANDROID_HOME;
+            });
+            it("should add tools/bin,tools,platform-tools to PATH if `avdmanager`,`android`,`adb`
is not found", function(done) {
+                return check_reqs.check_android()
+                .then(function() {
+                    expect(process.env.PATH).toContain("let the children play" + path.sep
+ "tools");
+                    expect(process.env.PATH).toContain("let the children play" + path.sep
+ "platform-tools");
+                    expect(process.env.PATH).toContain("let the children play" + path.sep
+ "tools" + path.sep + "bin");
+                    done();
+                }).fail(function(err) {
+                    expect(err).toBeUndefined();
+                    console.log(err);
+                });
+            });
+        });
+    });
+});


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message