cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [10/12] android commit: CB-12546: use android_sdk list_targets instead of rewriting the same thing again.
Date Mon, 20 Mar 2017 17:51:28 GMT
CB-12546: use android_sdk list_targets instead of rewriting the same thing again.


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

Branch: refs/heads/master
Commit: f7687a2567c0d117b82f80dcfd3ddfdd7af31cd6
Parents: ebd4a02
Author: filmaj <maj.fil@gmail.com>
Authored: Tue Mar 14 16:18:37 2017 -0700
Committer: filmaj <maj.fil@gmail.com>
Committed: Mon Mar 20 10:09:45 2017 -0700

----------------------------------------------------------------------
 bin/android_sdk_version                  |  2 +-
 bin/templates/cordova/lib/android_sdk.js |  6 ++---
 bin/templates/cordova/lib/check_reqs.js  | 34 ++++++++-------------------
 3 files changed, 14 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/f7687a25/bin/android_sdk_version
----------------------------------------------------------------------
diff --git a/bin/android_sdk_version b/bin/android_sdk_version
index 9e75325..e0ce1ec 100755
--- a/bin/android_sdk_version
+++ b/bin/android_sdk_version
@@ -21,7 +21,7 @@
 
 var android_sdk = require('./templates/cordova/lib/android_sdk');
 
-android_sdk.print_newest_available_sdk_target.done(null, function(err) {
+android_sdk.print_newest_available_sdk_target().done(null, function(err) {
     console.error(err);
     process.exit(2);
 });

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/f7687a25/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
index 6bb0075..90fcfde 100755
--- a/bin/templates/cordova/lib/android_sdk.js
+++ b/bin/templates/cordova/lib/android_sdk.js
@@ -60,10 +60,10 @@ module.exports.list_targets = function() {
         // lets see if `sdkmanager` is available and we can figure it out
         var avail_regex = /android command is no longer available/;
         if (err.code && (err.stdout.match(avail_regex) || err.stderr.match(avail_regex)))
{
-            return superspawn.spawn('sdkmanager', ['--list'], {capture: ['stdout', 'stderr']})
-            .then(function(result) {
+            return superspawn.spawn('sdkmanager', ['--list'])
+            .then(function(stdout) {
                 var parsing_installed_packages = false;
-                var lines = result.stdout.split('\n');
+                var lines = stdout.split('\n');
                 var targets = [];
                 for (var i = 0, l = lines.length; i < l; i++) {
                     var line = lines[i];

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/f7687a25/bin/templates/cordova/lib/check_reqs.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/check_reqs.js b/bin/templates/cordova/lib/check_reqs.js
index 910c3a6..7d954b4 100644
--- a/bin/templates/cordova/lib/check_reqs.js
+++ b/bin/templates/cordova/lib/check_reqs.js
@@ -31,7 +31,7 @@ var shelljs = require('shelljs'),
     PROJECT_ROOT = path.join(__dirname, '..', '..');
 var CordovaError = require('cordova-common').CordovaError;
 var superspawn = require('cordova-common').superspawn;
-
+var android_sdk = require('./android_sdk');
 
 function forgivingWhichSync(cmd) {
     try {
@@ -89,7 +89,7 @@ module.exports.check_ant = function() {
         // Parse Ant version from command output
         return /version ((?:\d+\.)+(?:\d+))/i.exec(output)[1];
     }).catch(function(err) {
-        throw new CordovaError("Failed to run `ant -version`. Make sure you have `ant` on
your $PATH.");
+        throw new CordovaError('Failed to run `ant -version`. Make sure you have `ant` on
your $PATH.');
     });
 };
 
@@ -299,11 +299,11 @@ module.exports.check_android = function() {
     });
 };
 
+// TODO: is this actually needed?
 module.exports.getAbsoluteAndroidCmd = function () {
     var cmd = forgivingWhichSync('android');
-    // TODO: this probably needs to be `sdkmanager`, no?
     if (cmd.length === 0) {
-        cmd = forgivingWhichSync('avdmanager');
+        cmd = forgivingWhichSync('sdkmanager');
     }
     if (module.exports.isWindows()) {
         return '"' + cmd + '"';
@@ -317,37 +317,24 @@ module.exports.check_android_target = function(originalError) {
     //   android-L
     //   Google Inc.:Google APIs:20
     //   Google Inc.:Glass Development Kit Preview:20
-    var valid_target = module.exports.get_target();
-    var msg = 'Android SDK not found. Make sure that it is installed. If it is not at the
default location, set the ANDROID_HOME environment variable.';
+    var desired_api_level = parseInt(module.exports.get_target().replace(/android-/, ''));
     //   Changing "targets" to "target" is stupid and makes more code.  Thanks Google!
-    var cmd = 'android';
-    // TODO: the following conditional needs fixing, probably should leverage `sdkmanager`
-    // oh and tests
-    if (forgivingWhichSync('avdmanager').length > 0)
-        cmd = 'avdmanager';
-    return superspawn.spawn(cmd, ['list', 'targets', '--compact'])
-    .then(function(stdout) {
-        var targets = output.split('\n');
-        if (targets.indexOf(valid_target) >= 0) {
+    return android_sdk.list_targets()
+    .then(function(targets) {
+        if (targets.indexOf(desired_api_level) >= 0) {
             return targets;
         }
-
         var androidCmd = module.exports.getAbsoluteAndroidCmd();
-        var msg = 'Please install Android target: "' + valid_target + '".\n\n' +
+        var msg = 'Please install Android target / API level: "' + desired_api_level  + '".\n\n'
+
             'Hint: Open the SDK manager by running: ' + androidCmd + '\n' +
             'You will require:\n' +
-            '1. "SDK Platform" for ' + valid_target + '\n' +
+            '1. "SDK Platform" for API level ' + desired_api_level + '\n' +
             '2. "Android SDK Platform-tools (latest)\n' +
             '3. "Android SDK Build-tools" (latest)';
         if (originalError) {
             msg = originalError + '\n' + msg;
         }
         throw new CordovaError(msg);
-    }).catch(function(err) {
-        throw new CordovaError(msg);
-    });
-    return tryCommand(cmd, msg)
-    .then(function(output) {
     });
 };
 
@@ -362,7 +349,6 @@ module.exports.run = function() {
             throw new CordovaError('Requirements check failed for JDK 1.8 or greater');
          }
 
-
          if (!values[1]) {
             throw new CordovaError('Requirements check failed for Android SDK');
          }


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


Mime
View raw message