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/02/05 02:08:53 UTC

git commit: 2.4.3. Fixes with plugins. Tests are faster. woot.

Updated Branches:
  refs/heads/master 34ee767a5 -> 1b91256b2


2.4.3. Fixes with plugins. Tests are faster. woot.


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

Branch: refs/heads/master
Commit: 1b91256b2bd24d43d86fb21206b25ce45aa842c2
Parents: 34ee767
Author: Fil Maj <ma...@gmail.com>
Authored: Mon Feb 4 17:12:40 2013 -0800
Committer: Fil Maj <ma...@gmail.com>
Committed: Mon Feb 4 17:12:40 2013 -0800

----------------------------------------------------------------------
 bootstrap.js                          |    8 +-
 package.json                          |    6 +-
 spec/fixtures/plugins/test/plugin.xml |    4 -
 spec/plugin.spec.js                   |  239 +++-------------------------
 src/metadata/ios_parser.js            |    4 +-
 src/platform.js                       |    3 +
 src/plugin.js                         |   21 ++--
 7 files changed, 51 insertions(+), 234 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/1b91256b/bootstrap.js
----------------------------------------------------------------------
diff --git a/bootstrap.js b/bootstrap.js
index 4df2089..14b6973 100644
--- a/bootstrap.js
+++ b/bootstrap.js
@@ -48,6 +48,8 @@ var cordovaDir = path.join(projectFixtures, 'cordova');
 shell.rm('-rf', cordovaDir);
 create(cordovaDir);
 var platformsDir = path.join(cordovaDir, 'platforms');
+// kill the stupid spec shit!
+shell.rm('-rf', path.join(cordovaDir, 'www', 'spec'));
 
 platforms.forEach(function(platform) {
     min_reqs[platform](function(err) {
@@ -67,8 +69,12 @@ platforms.forEach(function(platform) {
                     console.error('ERROR! Could not create a native ' + platform + ' project test fixture. See below for error output.');
                     console.error(output);
                 } else {
-                    // copy over to full cordova project test fixture
                     var platformDir = path.join(platformsDir, platform);
+                    // remove extra spec bullshit as it intereferes with jasmine-node
+                    var dub = path.join(fix_path, 'www');
+                    if (platform == 'android') dub = path.join(fix_path, 'assets', 'www');
+                    shell.rm('-rf', path.join(dub, 'spec'));
+                    // copy over to full cordova project test fixture
                     shell.mkdir('-p', platformDir);
                     shell.cp('-rf', path.join(fix_path, '*'), platformDir); 
                     // set permissions on executables

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/1b91256b/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 6baaf1d..6c52ced 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "cordova",
-  "version": "2.4.2",
+  "version": "2.4.3",
   "preferGlobal": "true",
   "description": "Cordova command line interface tool",
   "main": "cordova",
@@ -23,8 +23,8 @@
   "dependencies": {
     "colors":">=0.6.0",
     "elementtree":"0.1.3",
-    "plugman":"git://github.com/filmaj/plugman.git#0.5.5",
-    "plist":"git://github.com/filmaj/node-plist.git",
+    "plugman":"git+https://github.com/imhotep/plugman.git#0.5.7",
+    "plist":"git+https://github.com/filmaj/node-plist.git",
     "xcode":"0.5.1",
     "express":"3.0",
     "shelljs":"0.1.2",

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/1b91256b/spec/fixtures/plugins/test/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/fixtures/plugins/test/plugin.xml b/spec/fixtures/plugins/test/plugin.xml
index 9ab851c..774eda1 100644
--- a/spec/fixtures/plugins/test/plugin.xml
+++ b/spec/fixtures/plugins/test/plugin.xml
@@ -7,12 +7,8 @@
     <name>Test Plugin</name>
 
     <asset src="www/test.js" target="test.js" />
-    <platform name="android">
-    </platform>
     <platform name="ios">
         <plugins-plist key="TestPlugin" string="Test" />
     </platform>
-    <platform name="blackberry">
-    </platform>
 </plugin>
 

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/1b91256b/spec/plugin.spec.js
----------------------------------------------------------------------
diff --git a/spec/plugin.spec.js b/spec/plugin.spec.js
index 43fbecb..787747f 100644
--- a/spec/plugin.spec.js
+++ b/spec/plugin.spec.js
@@ -24,11 +24,12 @@ var cordova = require('../cordova'),
     tempDir = path.join(__dirname, '..', 'temp'),
     fixturesDir = path.join(__dirname, 'fixtures'),
     testPlugin = path.join(fixturesDir, 'plugins', 'test'),
+    cordova_project = path.join(fixturesDir, 'projects', 'cordova'),
     androidPlugin = path.join(fixturesDir, 'plugins', 'android');
 
 var cwd = process.cwd();
 
-xdescribe('plugin command', function() {
+describe('plugin command', function() {
     beforeEach(function() {
         // Make a temp directory
         shell.rm('-rf', tempDir);
@@ -92,232 +93,44 @@ xdescribe('plugin command', function() {
                 }).toThrow('You need at least one platform added to your app. Use `cordova platform add <platform>`.');
             });
             it('should throw if plugin does not support any app platforms', function() {
-                var cb = jasmine.createSpy();
-                runs(function() {
-                    cordova.platform('add', 'ios', cb);
-                });
-                waitsFor(function() { return cb.wasCalled; }, 'ios platform add');
-                runs(function() {
-                    expect(function() {
-                        cordova.plugin('add', androidPlugin);
-                    }).toThrow('Plugin "android" does not support any of your application\'s platforms. Plugin platforms: android; your application\'s platforms: ios');
+                process.chdir(cordova_project);
+                shell.mv('-f', path.join(cordova_project, 'platforms', 'android'), tempDir);
+                shell.mv('-f', path.join(cordova_project, 'platforms', 'blackberry'), tempDir);
+                this.after(function() {
+                    process.chdir(cwd);
+                    shell.mv('-f', path.join(tempDir, 'android'), path.join(cordova_project, 'platforms'));
+                    shell.mv('-f', path.join(tempDir, 'blackberry'), path.join(cordova_project, 'platforms'));
                 });
+                expect(function() {
+                    cordova.plugin('add', androidPlugin);
+                }).toThrow('Plugin "android" does not support any of your application\'s platforms. Plugin platforms: android; your application\'s platforms: ios');
             });
             it('should throw if plugin is already added to project', function() {
+                process.chdir(cordova_project);
                 var cb = jasmine.createSpy();
-                var pluginCb = jasmine.createSpy();
-                runs(function() {
-                    cordova.platform('add', 'ios', cb);
+                this.after(function() {
+                    process.chdir(cordova_project);
+                    cordova.plugin('rm', "test");
+                    process.chdir(cwd);
                 });
-                waitsFor(function() { return cb.wasCalled; }, 'ios platform add');
                 runs(function() {
-                    cordova.plugin('add', testPlugin, pluginCb);
+                    cordova.plugin('add', testPlugin, cb);
                 });
-                waitsFor(function() { return pluginCb.wasCalled; }, 'test plugin add');
-                runs(function() {
+                waitsFor(function() { return cb.wasCalled; }, 'frst add plugin');
+                runs(function(){
                     expect(function() {
-                        cordova.plugin('add', testPlugin, pluginCb);
+                        cordova.plugin('add', testPlugin);
                     }).toThrow('Plugin "test" already added to project.');
                 });
             });
             it('should throw if plugin does not have a plugin.xml', function() {
-                var cb = jasmine.createSpy();
-                runs(function() {
-                    cordova.platform('add', 'ios', cb);
-                });
-                waitsFor(function() { return cb.wasCalled; }, 'ios platform add');
-                runs(function() {
-                    expect(function() {
-                        cordova.plugin('add', fixturesDir);
-                    }).toThrow('Plugin "fixtures" does not have a plugin.xml in the root. Plugin must support the Cordova Plugin Specification: https://github.com/alunny/cordova-plugin-spec');
-                });
-            });
-        });
-        describe('success', function() {
-            it('should add plugin www assets to project www folder', function() {
-                var cb = jasmine.createSpy();
-                var pluginCb = jasmine.createSpy();
-                runs(function() {
-                    cordova.platform('add', 'ios', cb);
-                });
-                waitsFor(function() { return cb.wasCalled; }, 'ios platform add');
-                runs(function() {
-                    cordova.plugin('add', testPlugin, pluginCb);
-                });
-                waitsFor(function() { return pluginCb.wasCalled; }, 'test plugin add');
-                runs(function() {
-                    expect(fs.existsSync(path.join(tempDir, 'www', 'test.js'))).toBe(true);
-                });
-            });
-            it('should add the full plugin to the plugins directory', function() {
-                var cb = jasmine.createSpy();
-                var pluginCb = jasmine.createSpy();
-                runs(function() {
-                    cordova.platform('add', 'ios', cb);
-                });
-                waitsFor(function() { return cb.wasCalled; }, 'ios platform add');
-                runs(function() {
-                    cordova.plugin('add', testPlugin, pluginCb);
-                });
-                waitsFor(function() { return pluginCb.wasCalled; }, 'test plugin add');
-                runs(function() {
-                    expect(fs.existsSync(path.join(tempDir, 'plugins', 'test'))).toBe(true);
-                });
-            });
-            it('should be able to handle adding multiple plugins', function() {
-                cordova.platform('add', 'android');
-                var cb = jasmine.createSpy();
-                runs(function() {
-                    cordova.plugin('add', [testPlugin, androidPlugin], cb);
+                process.chdir(cordova_project);
+                this.after(function() {
+                    process.chdir(cwd);
                 });
-                waitsFor(function() { return cb.wasCalled; }, 'test+android plugin add');
-                runs(function() {
-                    expect(fs.existsSync(path.join(tempDir, 'plugins', 'test'))).toBe(true);
-                    expect(fs.existsSync(path.join(tempDir, 'plugins', 'android'))).toBe(true);
-                });
-            });
-        });
-    });
-
-    describe('`rm`',function() {
-        beforeEach(function() {
-            cordova.create(tempDir);
-            process.chdir(tempDir);
-        });
-
-        afterEach(function() {
-            process.chdir(cwd);
-        });
-        describe('failure', function() {
-            it('should throw if your app has no platforms added', function() {
                 expect(function() {
-                    cordova.plugin(_invocation, testPlugin);
-                }).toThrow('You need at least one platform added to your app. Use `cordova platform add <platform>`.');
-            });
-            it('should throw if plugin is not added to project', function() {
-                var cb = jasmine.createSpy();
-                runs(function() {
-                    cordova.platform('add', 'ios', cb);
-                });
-                waitsFor(function() { return cb.wasCalled; }, 'ios platform add');
-                runs(function() {
-                    expect(function() {
-                        cordova.plugin(_invocation, 'test', function() {});
-                    }).toThrow('Plugin "test" not added to project.');
-                });
-            });
-        });
-        describe('success', function() {
-            it('should remove plugin www assets from project www folder', function() {
-                var cb = jasmine.createSpy();
-                var pluginCb = jasmine.createSpy();
-                var removeCb = jasmine.createSpy();
-                runs(function() {
-                    cordova.platform('add', 'ios', cb);
-                });
-                waitsFor(function() { return cb.wasCalled; }, 'ios platform add');
-                runs(function() {
-                    cordova.plugin('add', testPlugin, pluginCb);
-                });
-                waitsFor(function() { return pluginCb.wasCalled; }, 'test plugin add');
-                runs(function() {
-                    cordova.plugin(_invocation, 'test', removeCb);
-                });
-                waitsFor(function() { return removeCb.wasCalled; }, 'test plugin remove');
-                runs(function() {
-                    expect(fs.existsSync(path.join(tempDir, 'www', 'test.js'))).toBe(false);
-                });
-            });
-            it('should remove the full plugin from the plugins directory', function() {
-                var cb = jasmine.createSpy();
-                var pluginCb = jasmine.createSpy();
-                var removeCb = jasmine.createSpy();
-                runs(function() {
-                    cordova.platform('add', 'ios', cb);
-                });
-                waitsFor(function() { return cb.wasCalled; }, 'ios platform add');
-                runs(function() {
-                    cordova.plugin('add', testPlugin, pluginCb);
-                });
-                waitsFor(function() { return pluginCb.wasCalled; }, 'test plugin add');
-                runs(function() {
-                    cordova.plugin(_invocation, 'test', removeCb);
-                });
-                waitsFor(function() { return removeCb.wasCalled; }, 'test plugin remove');
-                runs(function() {
-                    expect(fs.existsSync(path.join(tempDir, 'plugins', 'test'))).toBe(false);
-                });
-            });
-            it('should be able to handle removing multiple plugins', function() {
-                cordova.platform('add', 'android');
-                var cb = jasmine.createSpy();
-                var cbtwo = jasmine.createSpy();
-                runs(function() {
-                    cordova.plugin('add', [testPlugin, androidPlugin], cb);
-                });
-                waitsFor(function() { return cb.wasCalled; }, 'test+android plugin add');
-                runs(function() {
-                    cordova.plugin(_invocation, [testPlugin, androidPlugin], cbtwo);
-                });
-                waitsFor(function() { return cbtwo.wasCalled; }, 'test+android plugin rm');
-                runs(function() {
-                    expect(fs.existsSync(path.join(tempDir, 'plugins', 'test'))).toBe(false);
-                    expect(fs.existsSync(path.join(tempDir, 'plugins', 'android'))).toBe(false);
-                });
-            });
-        });
-    });
-
-    describe('hooks', function() {
-        var s;
-        beforeEach(function() {
-            cordova.create(tempDir);
-            process.chdir(tempDir);
-            s = spyOn(hooker.prototype, 'fire').andReturn(true);
-        });
-        afterEach(function() {
-            process.chdir(cwd);
-            shell.rm('-rf', tempDir);
-        });
-
-        describe('list (ls) hooks', function() {
-            it('should fire before hooks through the hooker module', function() {
-                cordova.plugin();
-                expect(s).toHaveBeenCalledWith('before_plugin_ls');
-            });
-            it('should fire after hooks through the hooker module', function() {
-                cordova.plugin();
-                expect(s).toHaveBeenCalledWith('after_plugin_ls');
-            });
-        });
-        describe('remove (rm) hooks', function() {
-            beforeEach(function() {
-                cordova.platform('add', 'android');
-                spyOn(shell, 'exec').andReturn({code:0}); // fake call to pluginstall
-                cordova.plugin('add', androidPlugin);
-                s.reset();
-            });
-            it('should fire before hooks through the hooker module', function() {
-                cordova.plugin('rm', 'android');
-                expect(s).toHaveBeenCalledWith('before_plugin_rm');
-            });
-            it('should fire after hooks through the hooker module', function() {
-                cordova.plugin('rm', 'android');
-                expect(s).toHaveBeenCalledWith('after_plugin_rm');
-            });
-        });
-        describe('add hooks', function() {
-            beforeEach(function() {
-                cordova.platform('add', 'android');
-                spyOn(shell, 'exec').andReturn({code:0}); // fake call to pluginstall
-            });
-            it('should fire before hooks through the hooker module', function() {
-                cordova.plugin('add', androidPlugin);
-                expect(s).toHaveBeenCalledWith('before_plugin_add');
-            });
-            it('should fire after hooks through the hooker module', function() {
-                cordova.plugin('add', androidPlugin);
-                expect(s).toHaveBeenCalledWith('after_plugin_add');
+                    cordova.plugin('add', fixturesDir);
+                }).toThrow('Plugin "fixtures" does not have a plugin.xml in the root. Plugin must support the Cordova Plugin Specification: https://github.com/alunny/cordova-plugin-spec');
             });
         });
     });

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/1b91256b/src/metadata/ios_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/ios_parser.js b/src/metadata/ios_parser.js
index cdc6802..41da1b4 100644
--- a/src/metadata/ios_parser.js
+++ b/src/metadata/ios_parser.js
@@ -75,7 +75,7 @@ module.exports.check_requirements = function(callback) {
 module.exports.prototype = {
     update_from_config:function(config, callback) {
         if (config instanceof config_parser) {
-        } else throw 'update_from_config requires a config_parser object';
+        } else throw new Error('update_from_config requires a config_parser object');
         var name = config.name();
         var pkg = config.packageName();
 
@@ -123,7 +123,7 @@ module.exports.prototype = {
         var proj = new xcode.project(this.pbxproj);
         var parser = this;
         proj.parse(function(err,hash) {
-            if (err) throw 'An error occured during parsing of project.pbxproj. Start weeping.';
+            if (err) throw new Error('An error occured during parsing of project.pbxproj. Start weeping.');
             else {
                 proj.updateProductName(name);
                 fs.writeFileSync(parser.pbxproj, proj.writeSync(), 'utf-8');

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/1b91256b/src/platform.js
----------------------------------------------------------------------
diff --git a/src/platform.js b/src/platform.js
index 834c514..caab916 100644
--- a/src/platform.js
+++ b/src/platform.js
@@ -23,6 +23,9 @@ var config_parser     = require('./config_parser'),
     path              = require('path'),
     hooker            = require('./hooker'),
     n                 = require('ncallbacks'),
+    android_parser    = require('./metadata/android_parser'),
+    ios_parser        = require('./metadata/ios_parser'),
+    blackberry_parser = require('./metadata/blackberry_parser'),
     shell             = require('shelljs');
 
 module.exports = function platform(command, targets, callback) {

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/1b91256b/src/plugin.js
----------------------------------------------------------------------
diff --git a/src/plugin.js b/src/plugin.js
index ad553cf..3421b7b 100644
--- a/src/plugin.js
+++ b/src/plugin.js
@@ -1,4 +1,3 @@
-
 /**
     Licensed to the Apache Software Foundation (ASF) under one
     or more contributor license agreements.  See the NOTICE file
@@ -33,7 +32,7 @@ module.exports = function plugin(command, targets, callback) {
     var projectRoot = cordova_util.isCordova(process.cwd());
 
     if (!projectRoot) {
-        throw 'Current working directory is not a Cordova-based project.';
+        throw new Error('Current working directory is not a Cordova-based project.');
     }
     if (arguments.length === 0) command = 'ls';
 
@@ -71,7 +70,7 @@ module.exports = function plugin(command, targets, callback) {
             break;
         case 'add':
             if (platforms.length === 0) {
-                throw 'You need at least one platform added to your app. Use `cordova platform add <platform>`.';
+                throw new Error('You need at least one platform added to your app. Use `cordova platform add <platform>`.');
             }
             targets.forEach(function(target, index) {
                 var pluginContents = ls(target);
@@ -80,12 +79,12 @@ module.exports = function plugin(command, targets, callback) {
                 // TODO edge case: if a new platform is added, then you want
                 // to re-add the plugin to the new platform.
                 if (plugins.indexOf(targetName) > -1) {
-                    throw 'Plugin "' + targetName + '" already added to project.';
+                    throw new Error('Plugin "' + targetName + '" already added to project.');
                 }
                 // Check if the plugin has a plugin.xml in the root of the
                 // specified dir.
                 if (pluginContents.indexOf('plugin.xml') == -1) {
-                    throw 'Plugin "' + targetName + '" does not have a plugin.xml in the root. Plugin must support the Cordova Plugin Specification: https://github.com/alunny/cordova-plugin-spec';
+                    throw new Error('Plugin "' + targetName + '" does not have a plugin.xml in the root. Plugin must support the Cordova Plugin Specification: https://github.com/alunny/cordova-plugin-spec');
                 }
 
                 // Check if there is at least one match between plugin
@@ -96,7 +95,7 @@ module.exports = function plugin(command, targets, callback) {
                     else return true;
                 });
                 if (intersection.length === 0) {
-                    throw 'Plugin "' + targetName + '" does not support any of your application\'s platforms. Plugin platforms: ' + pluginXml.platforms.join(', ') + '; your application\'s platforms: ' + platforms.join(', ');
+                    throw new Error('Plugin "' + targetName + '" does not support any of your application\'s platforms. Plugin platforms: ' + pluginXml.platforms.join(', ') + '; your application\'s platforms: ' + platforms.join(', '));
                 }
 
                 hooks.fire('before_plugin_add');
@@ -110,7 +109,7 @@ module.exports = function plugin(command, targets, callback) {
                 intersection.forEach(function(platform) {
                     var cmd = util.format('%s --platform %s --project "%s" --plugin "%s"', cli, platform, path.join(projectRoot, 'platforms', platform), target);
                     var plugin_cli = shell.exec(cmd, {silent:true});
-                    if (plugin_cli.code > 0) throw 'An error occured during plugin installation for ' + platform + '. ' + plugin_cli.output;
+                    if (plugin_cli.code > 0) throw new Error('An error occured during plugin installation for ' + platform + '. ' + plugin_cli.output);
                 });
                 
                 // Add the plugin web assets to the www folder as well
@@ -140,7 +139,7 @@ module.exports = function plugin(command, targets, callback) {
         case 'rm':
         case 'remove':
             if (platforms.length === 0) {
-                throw 'You need at least one platform added to your app. Use `cordova platform add <platform>`.';
+                throw new Error('You need at least one platform added to your app. Use `cordova platform add <platform>`.');
             }
             targets.forEach(function(target, index) {
                 var targetName = names[index];
@@ -163,9 +162,9 @@ module.exports = function plugin(command, targets, callback) {
                     // Iterate over all matchin app-plugin platforms in the project and uninstall the
                     // plugin.
                     intersection.forEach(function(platform) {
-                        var cmd = util.format('%s --remove --platform %s --project "%s" --plugin "%s"', cli, platform, path.join(projectRoot, 'platforms', platform), targetPath);
+                        var cmd = util.format('%s --platform %s --project "%s" --plugin "%s" --remove', cli, platform, path.join(projectRoot, 'platforms', platform), targetPath);
                         var plugin_cli = shell.exec(cmd, {silent:true});
-                        if (plugin_cli.code > 0) throw 'An error occured during plugin uninstallation for ' + platform + '. ' + plugin_cli.output;
+                        if (plugin_cli.code > 0) throw new Error('An error occured during plugin uninstallation for ' + platform + '. ' + plugin_cli.output);
                     });
                     
                     // Remove the plugin web assets to the www folder as well
@@ -192,6 +191,6 @@ module.exports = function plugin(command, targets, callback) {
             if (callback) callback();
             break;
         default:
-            throw 'Unrecognized command "' + command + '". Use either `add`, `remove`, or `list`.';
+            throw new Error('Unrecognized command "' + command + '". Use either `add`, `remove`, or `list`.');
     }
 };