cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [1/2] android commit: Use add --compact flag in check_reqs when listing targets. No functional change.
Date Wed, 10 Sep 2014 16:44:22 GMT
Repository: cordova-android
Updated Branches:
  refs/heads/master 0e78dc35d -> bf13fd48c


Use add --compact flag in check_reqs when listing targets. No functional change.


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

Branch: refs/heads/master
Commit: bf13fd48ceb23a671a03ddfe4400003b70b72a9d
Parents: 3b99760
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Wed Sep 10 12:43:40 2014 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Wed Sep 10 12:44:17 2014 -0400

----------------------------------------------------------------------
 bin/lib/check_reqs.js | 39 ++++++++++++++++++++++-----------------
 1 file changed, 22 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/bf13fd48/bin/lib/check_reqs.js
----------------------------------------------------------------------
diff --git a/bin/lib/check_reqs.js b/bin/lib/check_reqs.js
index d2b3dcf..00137ff 100644
--- a/bin/lib/check_reqs.js
+++ b/bin/lib/check_reqs.js
@@ -48,20 +48,21 @@ function tryCommand(cmd, errMsg) {
 
 // Get valid target from framework/project.properties
 module.exports.get_target = function() {
-    if(fs.existsSync(path.join(ROOT, 'framework', 'project.properties'))) {
-        var target = shelljs.grep(/target=android-[\d+]/, path.join(ROOT, 'framework', 'project.properties'));
-        return target.split('=')[1].replace('\n', '').replace('\r', '').replace(' ', '');
-    } else if (fs.existsSync(path.join(ROOT, 'project.properties'))) {
-        // if no target found, we're probably in a project and project.properties is in ROOT.
-        // this is called on the project itself, and can support Google APIs AND Vanilla
Android
-        var target = shelljs.grep(/target=android-[\d+]/, path.join(ROOT, 'project.properties'))
||
-          shelljs.grep(/target=Google Inc.:Google APIs:[\d+]/, path.join(ROOT, 'project.properties'));
-        if(target == "" || !target) {
-          // Try Google Glass APIs
-          target = shelljs.grep(/target=Google Inc.:Glass Development Kit Preview:[\d+]/,
path.join(ROOT, 'project.properties'));
+    function extractFromFile(filePath) {
+        var target = shelljs.grep(/\btarget=/, filePath);
+        if (!target) {
+            throw new Error('Could not find android target within: ' + filePath);
         }
-        return target.split('=')[1].replace('\n', '').replace('\r', '');
+        return target.split('=')[1].trim();
+    }
+    if (fs.existsSync(path.join(ROOT, 'framework', 'project.properties'))) {
+        return extractFromFile(path.join(ROOT, 'framework', 'project.properties'));
+    }
+    if (fs.existsSync(path.join(ROOT, 'project.properties'))) {
+        // if no target found, we're probably in a project and project.properties is in ROOT.
+        return extractFromFile(path.join(ROOT, 'project.properties'));
     }
+    throw new Error('Could not find android target. File missing: ' + path.join(ROOT, 'project.properties'));
 }
 
 // Returns a promise. Called only by build and clean commands.
@@ -180,13 +181,17 @@ module.exports.check_android = function() {
 };
 
 module.exports.check_android_target = function(valid_target) {
+    // valid_target can look like:
+    //   android-19
+    //   android-L
+    //   Google Inc.:Google APIs:20
+    //   Google Inc.:Glass Development Kit Preview:20
     var msg = 'Failed to run "android". Make sure you have the latest Android SDK installed,
and that the "android" command (inside the tools/ folder) is added to your PATH.';
-    return tryCommand('android list targets', msg)
+    return tryCommand('android list targets --compact', msg)
     .then(function(output) {
-        if (!output.match(valid_target)) {
-            throw new Error('Please install Android target "' + valid_target + '".\n' +
-                output + '\n\n' +
-                'Hint: Install it using the SDK manager by running: ' + forgivingWhichSync('android'));
+        if (output.split('\n').indexOf(valid_target) == -1) {
+            throw new Error('Please install Android target: "' + valid_target + '".\n' +
+                'Hint: Open the SDK manager by running: ' + forgivingWhichSync('android'));
         }
     });
 };


Mime
View raw message