Fixes issue #26: android 2.1.0 tab breaks create script. also refactored spec helper a bit so that we can turn off the android project create shortcut
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/commit/31e8cd37 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/31e8cd37 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/31e8cd37 Branch: refs/heads/cordova-client Commit: 31e8cd37409699a0c1208617e4bae3b363d6b3bc Parents: 1b309ae Author: Fil Maj <maj....@gmail.com> Authored: Tue Sep 25 16:57:31 2012 -0700 Committer: Fil Maj <maj....@gmail.com> Committed: Tue Sep 25 16:57:31 2012 -0700 ---------------------------------------------------------------------- spec/helper.js | 34 ++++++++++++++++++++++++---------- spec/platform.spec.js | 41 ++++++++++++++++++++++++++++++++++++++--- src/util.js | 5 ++++- 3 files changed, 66 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/31e8cd37/spec/helper.js ---------------------------------------------------------------------- diff --git a/spec/helper.js b/spec/helper.js index 79d7de8..3f7645d 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -7,15 +7,29 @@ var shell = require('shelljs'), var orig_exec = shell.exec; -shell.exec = function(cmd, opts) { - // Match various commands to exec - if (cmd.match(/android.bin.create/)) { - var r = new RegExp(/android.bin.create"\s"([\/\\\w-_\.]*)"/); - var dir = r.exec(cmd)[1]; - shell.cp('-r', android_project, path.join(dir, '..')); - fs.chmodSync(path.join(dir, 'cordova', 'debug'), '754'); - return {code:0}; +module.exports = { + enabled:false, + enable:function() { + module.exports.enabled = true; + require('shelljs').exec = function(cmd, opts) { + // Match various commands to exec + if (cmd.match(/android.bin.create/)) { + var r = new RegExp(/android.bin.create"\s"([\/\\\w-_\.]*)"/); + var dir = r.exec(cmd)[1]; + shell.cp('-r', android_project, path.join(dir, '..')); + fs.chmodSync(path.join(dir, 'cordova', 'debug'), '754'); + return {code:0}; + } + // Fire off to original exec + return orig_exec.apply(null, arguments); + } + }, + disable:function() { + module.exports.enabled = false; + require('shelljs').exec = orig_exec; } - // Fire off to original exec - return orig_exec.apply(null, arguments); +}; + +if (!module.exports.enabled) { + module.exports.enable(); } http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/31e8cd37/spec/platform.spec.js ---------------------------------------------------------------------- diff --git a/spec/platform.spec.js b/spec/platform.spec.js index 13c3f1b..57e27af 100644 --- a/spec/platform.spec.js +++ b/spec/platform.spec.js @@ -4,6 +4,7 @@ var cordova = require('../cordova'), fs = require('fs'), et = require('elementtree'), config_parser = require('../src/config_parser'), + helper = require('./helper'), tempDir = path.join(__dirname, '..', 'temp'); var cwd = process.cwd(); @@ -83,9 +84,43 @@ describe('platform command', function() { }); describe('without any libraries cloned', function() { - // TODO! - it('should clone down and checkout the correct android library'); - it('should clone down and checkout the correct ios library'); + var lib = path.join(__dirname, '..', 'lib'); + + beforeEach(function() { + ['ios','android'].forEach(function(p) { + var s = path.join(lib, p); + var d = path.join(lib, p + '-bkup'); + shell.mv(s, d); + }); + }); + afterEach(function() { + ['ios','android'].forEach(function(p) { + var s = path.join(lib, p + '-bkup'); + var d = path.join(lib, p); + shell.mv(s, d); + }); + }); + it('should clone down the android library and checkout appropriate tag', function() { + var s = spyOn(shell, 'exec').andReturn({code:0}); + try { + cordova.platform('add', 'android', function() {}); + } catch(e) {} + + expect(s).toHaveBeenCalled(); + expect(s.calls[0].args[0].match(/^git clone.*cordova-android/)).not.toBeNull(); + expect(s.calls[1].args[0].match(/git checkout 47daaaf/)).not.toBeNull(); + }); + it('should clone down the ios library and checkout appropriate tag', function() { + var s = spyOn(shell, 'exec').andReturn({code:0}); + + try { + cordova.platform('add', 'ios', function() {}); + } catch(e) {} + + expect(s).toHaveBeenCalled(); + expect(s.calls[0].args[0].match(/^git clone.*cordova-ios/)).not.toBeNull(); + expect(s.calls[1].args[0].match(/git checkout 2.1.0/)).not.toBeNull(); + }); it('should add a basic android project'); it('should add a basic ios project'); }); http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/31e8cd37/src/util.js ---------------------------------------------------------------------- diff --git a/src/util.js b/src/util.js index 8dd273e..e824527 100644 --- a/src/util.js +++ b/src/util.js @@ -34,7 +34,6 @@ module.exports = { /** * checkout a platform from the git repo * @param target string platform to get (enum of 'ios' or 'android' for now) - * @param flow I/O object to handle synchronous sys calls * @throws Javascript Error on failure */ getPlatformLib: function getPlatformLib(target) { @@ -47,6 +46,10 @@ module.exports = { } // specify which project tag to check out. minimum tag is 2.1.0 var cordova_lib_tag = '2.1.0'; + if (target == 'android') { + // FIXME: android hack. 2.1.0 tag messed up the create script + cordova_lib_tag = '47daaaf'; + } // Shell out to git. var outPath = path.join(__dirname, '..', 'lib', target);