You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2013/01/29 00:03:49 UTC

git commit: CB-2219: moved "check requirements" type stuff into indiv platform handlers. removes dependency on android stuff on-install.

Updated Branches:
  refs/heads/master e8bd7a370 -> 235a8d27e


CB-2219: moved "check requirements" type stuff into indiv platform handlers. removes dependency on android stuff on-install.


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

Branch: refs/heads/master
Commit: 235a8d27e812ca723bd606a258072da01de94360
Parents: e8bd7a3
Author: Fil Maj <ma...@gmail.com>
Authored: Mon Jan 28 14:48:53 2013 -0800
Committer: Fil Maj <ma...@gmail.com>
Committed: Mon Jan 28 14:48:53 2013 -0800

----------------------------------------------------------------------
 .gitignore                        |    2 +-
 bin/cordova                       |   18 ------
 bootstrap.js                      |   33 ++++-------
 src/metadata/android_parser.js    |   21 +++++++
 src/metadata/blackberry_parser.js |    5 ++
 src/metadata/ios_parser.js        |   35 +++++++++---
 src/platform.js                   |   95 +++++++++++++++++---------------
 7 files changed, 116 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/235a8d27/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index f80e23b..a690a1c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,4 @@ npm-debug.log
 temp
 .DS_Store
 spec/fixtures/projects/native
-lib
+lib/**

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/235a8d27/bin/cordova
----------------------------------------------------------------------
diff --git a/bin/cordova b/bin/cordova
index 97d2358..4d29175 100755
--- a/bin/cordova
+++ b/bin/cordova
@@ -1,21 +1,3 @@
-#    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.
-
 #!/usr/bin/env node
 var tokens = process.argv.slice(2, process.argv.length),
     cordova= require('../cordova');

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/235a8d27/bootstrap.js
----------------------------------------------------------------------
diff --git a/bootstrap.js b/bootstrap.js
index 74f913e..6e18e85 100644
--- a/bootstrap.js
+++ b/bootstrap.js
@@ -25,25 +25,18 @@ var util      = require('./src/util'),
     shell     = require('shelljs'),
     platforms = require('./platforms');
 
-var cmd = 'android update project -p ' + path.join(__dirname, 'lib', 'cordova-android', 'framework') + ' -t android-17';
-shell.exec(cmd, {async:true}, function(code, output) {
-    if (code > 0) {
-        process.exit(1);
-    } else {
-        // Create native projects using bin/create
-        var tempDir = path.join(__dirname, 'spec', 'fixtures', 'projects', 'native');
-        shell.rm('-rf', tempDir);
-        shell.mkdir('-p', tempDir);
+// Create native projects using bin/create
+var tempDir = path.join(__dirname, 'spec', 'fixtures', 'projects', 'native');
+shell.rm('-rf', tempDir);
+shell.mkdir('-p', tempDir);
 
-        platforms.forEach(function(platform) {
-            var fix_path = path.join(tempDir, platform + '_fixture');
-            var create = path.join(util.libDirectory, 'cordova-' + platform, 'bin', 'create'); 
-            console.log('Creating cordova-' + platform + ' project using live project lib for tests...');
-            var cmd = create + ' "' + fix_path + '" org.apache.cordova.cordovaExample cordovaExample';
-            if (platform == 'blackberry') cmd = create + ' "' + fix_path + '" cordovaExample';
-            var create_result = shell.exec(cmd, {silent:true});
-            if (create_result.code > 0) throw ('Could not create a native ' + platform + ' project test fixture: ' + create_result.output);
-            console.log('.. complete.');
-        });
-    }
+platforms.forEach(function(platform) {
+    var fix_path = path.join(tempDir, platform + '_fixture');
+    var create = path.join(util.libDirectory, 'cordova-' + platform, 'bin', 'create'); 
+    console.log('Creating cordova-' + platform + ' project using live project lib for tests...');
+    var cmd = create + ' "' + fix_path + '" org.apache.cordova.cordovaExample cordovaExample';
+    if (platform == 'blackberry') cmd = create + ' "' + fix_path + '" cordovaExample';
+    var create_result = shell.exec(cmd, {silent:true});
+    if (create_result.code > 0) throw ('Could not create a native ' + platform + ' project test fixture: ' + create_result.output);
+    console.log('.. complete.');
 });

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/235a8d27/src/metadata/android_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/android_parser.js b/src/metadata/android_parser.js
index 35a80bf..4d24952 100644
--- a/src/metadata/android_parser.js
+++ b/src/metadata/android_parser.js
@@ -39,6 +39,27 @@ module.exports = function android_parser(project) {
     this.android_config = path.join(this.path, 'res', 'xml', 'config.xml');
 };
 
+module.exports.check_requirements = function(callback) {
+    shell.exec('android list target', {silent:true, async:true}, function(code, output) {
+        if (code != 0) {
+            callback('The command `android` failed. Make sure you have the latest Android SDK installed, and the `android` command (inside the tools/ folder) added to your path.');
+        } else {
+            if (output.indexOf('android-17') == -1) {
+                callback('Please install Android target 17 (the Android 4.2 SDK). Make sure you have the latest Android tools installed as well. Run `android` from your command-line to install/update any missing SDKs or tools.');
+            } else {
+                var cmd = 'android update project -p ' + path.join(__dirname, '..', '..', 'lib', 'cordova-android', 'framework') + ' -t android-17';
+                shell.exec(cmd, {silent:true, async:true}, function(code, output) {
+                    if (code != 0) {
+                        callback('Error updating the Cordova library to work with your Android environment. Command run: "' + cmd + '", output: ' + output);
+                    } else {
+                        callback(false);
+                    }
+                });
+            }
+        }
+    });
+};
+
 module.exports.prototype = {
     update_from_config:function(config) {
         if (config instanceof config_parser) {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/235a8d27/src/metadata/blackberry_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/blackberry_parser.js b/src/metadata/blackberry_parser.js
index 965e36c..f70702e 100644
--- a/src/metadata/blackberry_parser.js
+++ b/src/metadata/blackberry_parser.js
@@ -34,6 +34,11 @@ module.exports = function blackberry_parser(project) {
     this.xml = new config_parser(this.config_path);
 };
 
+module.exports.check_requirements = function(callback) {
+    // TODO: below, we ask for users to fill out SDK paths, etc. into config.json. Android requires the sdk path be on the PATH. Which to choose? 
+    callback(false);
+};
+
 module.exports.prototype = {
     update_from_config:function(config) {
         if (config instanceof config_parser) {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/235a8d27/src/metadata/ios_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/ios_parser.js b/src/metadata/ios_parser.js
index d342e37..77eff90 100644
--- a/src/metadata/ios_parser.js
+++ b/src/metadata/ios_parser.js
@@ -1,4 +1,3 @@
-
 /**
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file
@@ -17,15 +16,18 @@
     specific language governing permissions and limitations
     under the License.
 */
-var fs   = require('fs'),
-    path = require('path'),
-    xcode = require('xcode'),
-    util = require('../util'),
-    shell = require('shelljs'),
-    plist = require('plist'),
-    et = require('elementtree'),
+var fs            = require('fs'),
+    path          = require('path'),
+    xcode         = require('xcode'),
+    util          = require('../util'),
+    shell         = require('shelljs'),
+    plist         = require('plist'),
+    semver        = require('semver'),
+    et            = require('elementtree'),
     config_parser = require('../config_parser');
 
+var MIN_XCODE_VERSION = '4.5.x';
+
 var default_prefs = {
     "KeyboardDisplayRequiresUserAction":"true",
     "SuppressesIncrementalRendering":"false",
@@ -49,12 +51,27 @@ module.exports = function ios_parser(project) {
         this.originalName = this.xcodeproj.substring(this.xcodeproj.lastIndexOf('/'), this.xcodeproj.indexOf('.xcodeproj'));
         this.cordovaproj = path.join(project, this.originalName);
     } catch(e) {
-        throw 'The provided path is not a Cordova iOS project.';
+        throw new Error('The provided path is not a Cordova iOS project.');
     }
     this.path = project;
     this.pbxproj = path.join(this.xcodeproj, 'project.pbxproj');
     this.config = new config_parser(path.join(this.cordovaproj, 'config.xml'));
 };
+
+module.exports.check_requirements = function(callback) {
+    // Check xcode + version.
+    shell.exec('xcodebuild -version', {silent:true, async:true}, function(code, output) {
+        if (code != 0) {
+            callback('Xcode is not installed. Cannot add iOS platform.');
+        } else {
+            var xc_version = output.split('\n')[0].split(' ')[1];
+            if (semver.lt(xc_version, MIN_XCODE_VERSION)) {
+                callback('Xcode version installed is too old. Minimum: ' + MIN_XCODE_VERSION + ', yours: ' + xc_version);
+            } else callback(false);
+        }
+    });
+};
+
 module.exports.prototype = {
     update_from_config:function(config, callback) {
         if (config instanceof config_parser) {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/235a8d27/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index a64b117..9c4ef44 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -27,9 +27,14 @@ var config_parser     = require('./config_parser'),
     ios_parser        = require('./metadata/ios_parser'),
     hooker            = require('./hooker'),
     n                 = require('ncallbacks'),
-    semver            = require('semver'),
     shell             = require('shelljs');
 
+var check_requirements = {
+    "ios":ios_parser.check_requirements,
+    "android":android_parser.check_requirements,
+    "blackberry":blackberry_parser.check_requirements
+};
+
 module.exports = function platform(command, targets, callback) {
     var projectRoot = cordova_util.isCordova(process.cwd());
 
@@ -37,7 +42,8 @@ module.exports = function platform(command, targets, callback) {
         throw 'Current working directory is not a Cordova-based project.';
     }
 
-    var hooks = new hooker(projectRoot), end;
+    var hooks = new hooker(projectRoot),
+        end;
 
     if (arguments.length === 0) command = 'ls';
     if (targets) {
@@ -63,56 +69,55 @@ module.exports = function platform(command, targets, callback) {
                 hooks.fire('before_platform_add');
                 var output = path.join(projectRoot, 'platforms', target);
 
-                if (target == 'ios') {
-                    // Check xcode + version.
-                    var xcode = shell.exec('xcodebuild -version', {silent:true});
-                    if (xcode.code != 0) throw new Error('Xcode is not installed. Cannot add iOS platform.');
-                    var xc_version = xcode.output.split('\n')[0].split(' ')[1];
-                    var MIN_XCODE_VERSION = '4.5.x';
-                    if (semver.lt(xc_version, MIN_XCODE_VERSION)) throw new Error('Xcode version installed is too old. Minimum: ' + MIN_XCODE_VERSION + ', yours: ' + xc_version);
-                }
-                // Create a platform app using the ./bin/create scripts that exist in each repo.
-                // TODO: eventually refactor to allow multiple versions to be created.
                 // Check if output directory already exists.
                 if (fs.existsSync(output)) {
                     throw new Error('Platform "' + target + '" already exists' );
                 }
 
-                // Run platform's create script
-                var bin = path.join(cordova_util.libDirectory, 'cordova-' + target, 'bin', 'create');
-                var pkg = cfg.packageName().replace(/[^\w.]/g,'_');
-                var name = cfg.name().replace(/\W/g,'_');
-                // TODO: PLATFORM LIBRARY INCONSISTENCY: order/number of arguments to create
-                var command = util.format('"%s" "%s" "%s" "%s"', bin, output, (target=='blackberry'?name:pkg), name);
+                // Make sure we have minimum requirements to work with specified platform
+                check_requirements[target](function(err) {
+                    if (err) {
+                        throw new Error('Your system does not meet the requirements to create ' + target + ' projects: ' + err);
+                    } else {
+                        // Create a platform app using the ./bin/create scripts that exist in each repo.
+                        // TODO: eventually refactor to allow multiple versions to be created.
+                        // Run platform's create script
+                        var bin = path.join(cordova_util.libDirectory, 'cordova-' + target, 'bin', 'create');
+                        var pkg = cfg.packageName().replace(/[^\w.]/g,'_');
+                        var name = cfg.name().replace(/\W/g,'_');
+                        // TODO: PLATFORM LIBRARY INCONSISTENCY: order/number of arguments to create
+                        // TODO: keep tabs on CB-2300
+                        var command = util.format('"%s" "%s" "%s" "%s"', bin, output, (target=='blackberry'?name:pkg), name);
 
-                var create = shell.exec(command, {silent:true});
-                if (create.code > 0) {
-                    throw new Error('An error occured during creation of ' + target + ' sub-project. ' + create.output);
-                }
-
-                switch(target) {
-                    case 'android':
-                        var android = new android_parser(output);
-                        android.update_project(cfg);
-                        hooks.fire('after_platform_add');
-                        end();
-                        break;
-                    case 'ios':
-                        var ios = new ios_parser(output);
-                        ios.update_project(cfg, function() {
-                            hooks.fire('after_platform_add');
-                            end();
-                        });
-                        break;
-                    case 'blackberry':
-                        var bb = new blackberry_parser(output);
-                        bb.update_project(cfg, function() {
-                            hooks.fire('after_platform_add');
-                            end();
-                        });
-                        break;
-                }
+                        var create = shell.exec(command, {silent:true});
+                        if (create.code > 0) {
+                            throw new Error('An error occured during creation of ' + target + ' sub-project. ' + create.output);
+                        }
 
+                        switch(target) {
+                            case 'android':
+                                var android = new android_parser(output);
+                                android.update_project(cfg);
+                                hooks.fire('after_platform_add');
+                                end();
+                                break;
+                            case 'ios':
+                                var ios = new ios_parser(output);
+                                ios.update_project(cfg, function() {
+                                    hooks.fire('after_platform_add');
+                                    end();
+                                });
+                                break;
+                            case 'blackberry':
+                                var bb = new blackberry_parser(output);
+                                bb.update_project(cfg, function() {
+                                    hooks.fire('after_platform_add');
+                                    end();
+                                });
+                                break;
+                        }
+                    }
+                });
             });
             break;
         case 'rm':