Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 79AA41028B for ; Thu, 20 Jun 2013 18:35:28 +0000 (UTC) Received: (qmail 46901 invoked by uid 500); 20 Jun 2013 18:35:28 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 46883 invoked by uid 500); 20 Jun 2013 18:35:28 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 46876 invoked by uid 99); 20 Jun 2013 18:35:28 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Jun 2013 18:35:28 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 15A338A9922; Thu, 20 Jun 2013 18:35:28 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: filmaj@apache.org To: commits@cordova.apache.org Message-Id: <9c4b558fae194045b7bec595d5500a4f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: 2.8.25. Fixes [CB-3846]: make sure to lazy load libraries whenever prepare is called, as well as platform. Added a helper lazy_load.based_on_config method that looks into .cordova/config.json and lazy loads appropriate stock or custom librari Date: Thu, 20 Jun 2013 18:35:28 +0000 (UTC) Updated Branches: refs/heads/master2 09333582a -> 262a2f9c9 2.8.25. Fixes [CB-3846]: make sure to lazy load libraries whenever prepare is called, as well as platform. Added a helper lazy_load.based_on_config method that looks into .cordova/config.json and lazy loads appropriate stock or custom libraries. Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/262a2f9c Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/262a2f9c Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/262a2f9c Branch: refs/heads/master2 Commit: 262a2f9c91e2baf3cc59fb1d26ad235d3cf4fa8c Parents: 0933358 Author: Fil Maj Authored: Thu Jun 20 11:35:08 2013 -0700 Committer: Fil Maj Committed: Thu Jun 20 11:35:08 2013 -0700 ---------------------------------------------------------------------- package.json | 2 +- spec/lazy_load.spec.js | 141 ++++++++++++++++++++++++++++++++++++++++++++ spec/platform.spec.js | 9 +-- spec/prepare.spec.js | 10 +++- src/lazy_load.js | 15 ++++- src/platform.js | 27 +++------ src/prepare.js | 51 +++++++++------- 7 files changed, 207 insertions(+), 48 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/262a2f9c/package.json ---------------------------------------------------------------------- diff --git a/package.json b/package.json index 40c3a89..6dbea91 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova", - "version": "2.8.24", + "version": "2.8.25", "preferGlobal": "true", "description": "Cordova command line interface tool", "main": "cordova", http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/262a2f9c/spec/lazy_load.spec.js ---------------------------------------------------------------------- diff --git a/spec/lazy_load.spec.js b/spec/lazy_load.spec.js new file mode 100644 index 0000000..95bab3f --- /dev/null +++ b/spec/lazy_load.spec.js @@ -0,0 +1,141 @@ +var lazy_load = require('../src/lazy_load'), + config = require('../src/config'), + util = require('../src/util'), + shell = require('shelljs'), + path = require('path'), + hooker = require('../src/hooker'), + https = require('follow-redirects').https, + fs = require('fs'), + platforms = require('../platforms'); + +describe('lazy_load module', function() { + var custom_path; + beforeEach(function() { + custom_path = spyOn(config, 'has_custom_path').andReturn(false); + }); + describe('cordova method (loads stock cordova libs)', function() { + var custom; + beforeEach(function() { + custom = spyOn(lazy_load, 'custom'); + }); + it('should throw if platform is not a stock cordova platform', function() { + expect(function() { + lazy_load.cordova('atari'); + }).toThrow('Cordova library "atari" not recognized.'); + }); + it('should invoke lazy_load.custom with appropriate url, platform, and version as specified in platforms manifest', function() { + lazy_load.cordova('android'); + expect(custom).toHaveBeenCalledWith(platforms.android.url + ';a=snapshot;h=' + platforms.android.version + ';sf=tgz', 'cordova', 'android', platforms.android.version, jasmine.any(Function)); + }); + }); + + describe('custom method (loads custom cordova libs)', function() { + var mkdir, exists, fire, rm, sym; + beforeEach(function() { + mkdir = spyOn(shell, 'mkdir'); + rm = spyOn(shell, 'rm'); + sym = spyOn(fs, 'symlinkSync'); + exists = spyOn(fs, 'existsSync').andReturn(false); + fire = spyOn(hooker, 'fire').andCallFake(function(evt, data, cb) { + cb(); + }); + }); + + it('should callback with no errors and not fire event hooks if library already exists', function(done) { + exists.andReturn(true); + lazy_load.custom('some url', 'some id', 'platform X', 'three point five', function(err) { + expect(err).not.toBeDefined(); + expect(fire).not.toHaveBeenCalled() + done(); + }); + }); + it('should fire a before_library_download event before it starts downloading a library', function() { + lazy_load.custom('some url', 'some id', 'platform X', 'three point five'); + expect(fire).toHaveBeenCalledWith('before_library_download', {platform:'platform X', url:'some url', id:'some id', version:'three point five'}, jasmine.any(Function)); + }); + + describe('remove URLs for libraries', function() { + var req, write_stream, http_on; + beforeEach(function() { + write_spy = jasmine.createSpy('write stream write'); + write_stream = spyOn(fs, 'createWriteStream').andReturn({ + write:write_spy + }); + http_on = jasmine.createSpy('https result on'); + // TODO: jasmien does not support chaning both andCallFake + andReturn... + req = spyOn(https, 'request').andCallFake(function(opts, cb) { + cb({ + on:http_on + }); + }).andReturn({ + on:function(){}, + end:function(){} + }); + }); + + it('should call into https request with appopriate url params', function() { + lazy_load.custom('https://github.com/apache/someplugin', 'random', 'android', '1.0'); + expect(req).toHaveBeenCalledWith({ + hostname:'github.com', + path:'/apache/someplugin' + }, jasmine.any(Function)); + }); + // TODO: jasmine does not support chaning andCallFake andReturn. Cannot test the below. + xit('should fire download events as the https request receives data events, and write to a file stream', function() { + http_on.andCallFake(function(evt, cb) { + console.log(evt); + if (evt == 'data') { + cb('chunk'); + } + }); + lazy_load.custom('https://github.com/apache/someplugin', 'random', 'android', '1.0'); + expect(fire).toHaveBeenCalledWith('library_download', { + platform:'android', + url:'https://github.com/apache/someplugin', + id:'random', + version:'1.0', + chunk:'chunk' + }); + expect(write_spy).toHaveBeenCalledWith('chunk', 'binary'); + }); + }); + + describe('local paths for libraries', function() { + it('should symlink to local path', function() { + lazy_load.custom('/some/random/lib', 'id', 'X', 'three point five') + expect(sym).toHaveBeenCalledWith('/some/random/lib', path.join(util.libDirectory, 'X', 'id', 'three point five'), 'dir'); + }); + it('should fire after hook once done', function() { + lazy_load.custom('/some/random/lib', 'id', 'X', 'three point five') + expect(fire).toHaveBeenCalledWith('after_library_download', {platform:'X',url:'/some/random/lib',id:'id',version:'three point five',path:path.join(util.libDirectory, 'X', 'id', 'three point five')}, jasmine.any(Function)); + }); + }); + }); + + describe('based_on_config method', function() { + var cordova, custom; + beforeEach(function() { + cordova = spyOn(lazy_load, 'cordova'); + custom = spyOn(lazy_load, 'custom'); + }); + it('should invoke custom if a custom lib is specified', function() { + var read = spyOn(config, 'read').andReturn({ + lib:{ + maybe:{ + uri:'you or eye?', + id:'eye dee', + version:'four point twenty' + } + } + }); + var p = '/some/random/custom/path'; + custom_path.andReturn(p); + lazy_load.based_on_config('yup', 'maybe'); + expect(custom).toHaveBeenCalledWith('you or eye?', 'eye dee', 'maybe', 'four point twenty', undefined); + }); + it('should invoke cordova if no custom lib is specified', function() { + lazy_load.based_on_config('yup', 'ios'); + expect(cordova).toHaveBeenCalledWith('ios', undefined); + }); + }); +}); http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/262a2f9c/spec/platform.spec.js ---------------------------------------------------------------------- diff --git a/spec/platform.spec.js b/spec/platform.spec.js index a74e2fb..48bec1b 100644 --- a/spec/platform.spec.js +++ b/spec/platform.spec.js @@ -33,7 +33,7 @@ var supported_platforms = Object.keys(platforms).filter(function(p) { return p ! var project_dir = '/some/path'; describe('platform command', function() { - var is_cordova, list_platforms, fire, config_parser, find_plugins, config_read, load_custom, load_cordova, rm, mkdir, existsSync, supports, pkg, name, exec, prep_spy, plugman_install, parsers = {}; + var is_cordova, list_platforms, fire, config_parser, find_plugins, config_read, load, load_custom, rm, mkdir, existsSync, supports, pkg, name, exec, prep_spy, plugman_install, parsers = {}; beforeEach(function() { supported_platforms.forEach(function(p) { parsers[p] = spyOn(platforms[p], 'parser').andReturn({ @@ -54,10 +54,10 @@ describe('platform command', function() { find_plugins = spyOn(util, 'findPlugins').andReturn([]); list_platforms = spyOn(util, 'listPlatforms').andReturn(supported_platforms); config_read = spyOn(config, 'read').andReturn({}); - load_custom = spyOn(lazy_load, 'custom').andCallFake(function(uri, id, platform, version, cb) { + load = spyOn(lazy_load, 'based_on_config').andCallFake(function(root, platform, cb) { cb(); }); - load_cordova = spyOn(lazy_load, 'cordova').andCallFake(function(platform, cb) { + load_custom = spyOn(lazy_load, 'custom').andCallFake(function(url, id, p, v, cb) { cb(); }); rm = spyOn(shell, 'rm'); @@ -131,7 +131,8 @@ describe('platform command', function() { expect(exec.mostRecentCall.args[0]).toMatch(/lib.wp8.cordova.2.8.0.bin.create/gi); expect(exec.mostRecentCall.args[0]).toContain(project_dir); }); - it('should support using custom versions of libraries by calling into lazy_load.custom', function() { + it('should call into lazy_load.custom if there is a user-specified configruation for consuming custom libraries', function() { + load.andCallThrough(); config_read.andReturn({ lib:{ 'wp7':{ http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/262a2f9c/spec/prepare.spec.js ---------------------------------------------------------------------- diff --git a/spec/prepare.spec.js b/spec/prepare.spec.js index 2f3921c..fba7cb6 100644 --- a/spec/prepare.spec.js +++ b/spec/prepare.spec.js @@ -22,6 +22,7 @@ var cordova = require('../cordova'), path = require('path'), fs = require('fs'), util = require('../src/util'), + lazy_load = require('../src/lazy_load'), platforms = require('../platforms'), hooker = require('../src/hooker'), fixtures = path.join(__dirname, 'fixtures'), @@ -32,7 +33,7 @@ var supported_platforms = Object.keys(platforms).filter(function(p) { return p ! var supported_platforms_paths = supported_platforms.map(function(p) { return path.join(project_dir, 'platforms', p, 'www'); }); describe('prepare command', function() { - var is_cordova, list_platforms, fire, config_parser, parsers = {}, plugman_prepare, find_plugins, plugman_get_json; + var is_cordova, list_platforms, fire, config_parser, parsers = {}, plugman_prepare, find_plugins, plugman_get_json, load; beforeEach(function() { is_cordova = spyOn(util, 'isCordova').andReturn(project_dir); list_platforms = spyOn(util, 'listPlatforms').andReturn(supported_platforms); @@ -52,6 +53,7 @@ describe('prepare command', function() { plugman_prepare = spyOn(plugman, 'prepare'); find_plugins = spyOn(util, 'findPlugins').andReturn([]); plugman_get_json = spyOn(plugman.config_changes, 'get_platform_json').andReturn({}); + load = spyOn(lazy_load, 'based_on_config').andCallFake(function(root, platform, cb) { cb(); }); }); describe('failure', function() { @@ -85,6 +87,12 @@ describe('prepare command', function() { expect(parsers[p]).toHaveBeenCalled(); }); }); + it('should invoke lazy_load for each platform to make sure platform libraries are loaded', function() { + cordova.prepare(); + supported_platforms.forEach(function(p) { + expect(load).toHaveBeenCalledWith(project_dir, p, jasmine.any(Function)); + }); + }); describe('plugman integration', function() { it('should invoke plugman.prepare after update_project', function() { cordova.prepare(); http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/262a2f9c/src/lazy_load.js ---------------------------------------------------------------------- diff --git a/src/lazy_load.js b/src/lazy_load.js index 6ffcb29..d49cef0 100644 --- a/src/lazy_load.js +++ b/src/lazy_load.js @@ -21,6 +21,7 @@ var path = require('path'), shell = require('shelljs'), platforms = require('../platforms'), events = require('./events'), + config = require('./config'), hooker = require('./hooker'), https = require('follow-redirects').https, zlib = require('zlib'), @@ -51,9 +52,8 @@ module.exports = { shell.mkdir('-p', id_dir); var download_dir = path.join(id_dir, version); if (fs.existsSync(download_dir)) { - events.emit('log', 'Platform library for "' + platform + '" already exists. No need to download. Continuing.'); - if (callback) callback(); - return; + events.emit('log', id + ' library for "' + platform + '" already exists. No need to download. Continuing.'); + if (callback) return callback(); } hooker.fire('before_library_download', { platform:platform, @@ -151,5 +151,14 @@ module.exports = { }); } }); + }, + based_on_config:function(project_root, platform, callback) { + var custom_path = config.has_custom_path(project_root, platform); + if (custom_path) { + var dot_file = config.read(project_root); + module.exports.custom(dot_file.lib[platform].uri, dot_file.lib[platform].id, platform, dot_file.lib[platform].version, callback); + } else { + module.exports.cordova(platform, callback); + } } }; http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/262a2f9c/src/platform.js ---------------------------------------------------------------------- diff --git a/src/platform.js b/src/platform.js index 7694b13..2057a77 100644 --- a/src/platform.js +++ b/src/platform.js @@ -96,34 +96,25 @@ module.exports = function platform(command, targets, callback) { } }); }); - var config_json = config.read(projectRoot); hooks.fire('before_platform_add', opts, function(err) { if (err) { if (callback) callback(err); else throw err; } else { + var config_json = config.read(projectRoot); targets.forEach(function(t) { - if (config_json.lib && config_json.lib[t]) { - events.emit('log', 'Using custom cordova platform library for "' + t + '".'); - lazy_load.custom(config_json.lib[t].uri, config_json.lib[t].id, t, config_json.lib[t].version, function(err) { - if (err) { - if (callback) callback(err); - else throw err; - } else { + lazy_load.based_on_config(projectRoot, t, function(err) { + if (err) { + if (callback) callback(err); + else throw err; + } else { + if (config_json.lib && config_json.lib[t]) { call_into_create(t, projectRoot, cfg, config_json.lib[t].id, config_json.lib[t].version, callback, end); - } - }); - } else { - events.emit('log', 'Using stock cordova platform library for "' + t + '".'); - lazy_load.cordova(t, function(err) { - if (err) { - if (callback) callback(err); - else throw err; } else { call_into_create(t, projectRoot, cfg, 'cordova', platforms[t].version, callback, end); } - }); - } + } + }); }); } }); http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/262a2f9c/src/prepare.js ---------------------------------------------------------------------- diff --git a/src/prepare.js b/src/prepare.js index f7c9d11..fd134a9 100644 --- a/src/prepare.js +++ b/src/prepare.js @@ -24,6 +24,8 @@ var cordova_util = require('./util'), shell = require('shelljs'), et = require('elementtree'), hooker = require('./hooker'), + lazy_load = require('./lazy_load'), + config = require('./config'), events = require('./events'), n = require('ncallbacks'), prompt = require('prompt'), @@ -86,27 +88,34 @@ module.exports = function prepare(platformList, callback) { // Iterate over each added platform platformList.forEach(function(platform) { - var platformPath = path.join(projectRoot, 'platforms', platform); - var parser = new platforms[platform].parser(platformPath); - parser.update_project(cfg, function() { - // Call plugman --prepare for this platform. sets up js-modules appropriately. - var plugins_dir = path.join(projectRoot, 'plugins'); - events.emit('log', 'Calling plugman.prepare for platform "' + platform + '"'); - plugman.prepare(platformPath, (platform=='blackberry'?'blackberry10':platform), plugins_dir); - // Make sure that config changes for each existing plugin is in place - var plugins = cordova_util.findPlugins(plugins_dir); - var platform_json = plugman.config_changes.get_platform_json(plugins_dir, (platform=='blackberry'?'blackberry10':platform)); - plugins && plugins.forEach(function(plugin_id) { - if (platform_json.installed_plugins[plugin_id]) { - events.emit('log', 'Ensuring plugin "' + plugin_id + '" is installed correctly...'); - plugman.config_changes.add_plugin_changes((platform=='blackberry'?'blackberry10':platform), platformPath, plugins_dir, plugin_id, /* variables for plugin */ platform_json.installed_plugins[plugin_id], /* top level plugin? */ true, /* should increment config munge? cordova-cli never should, only plugman */ false); - } else if (platform_json.dependent_plugins[plugin_id]) { - events.emit('log', 'Ensuring plugin "' + plugin_id + '" is installed correctly...'); - plugman.config_changes.add_plugin_changes((platform=='blackberry'?'blackberry10':platform), platformPath, plugins_dir, plugin_id, /* variables for plugin */ platform_json.dependent_plugins[plugin_id], /* top level plugin? */ false, /* should increment config munge? cordova-cli never should, only plugman */ false); - } - events.emit('log', 'Plugin "' + plugin_id + '" is good to go.'); - }); - end(); + lazy_load.based_on_config(projectRoot, platform, function(err) { + if (err) { + if (callback) callback(err); + else throw err; + } else { + var platformPath = path.join(projectRoot, 'platforms', platform); + var parser = new platforms[platform].parser(platformPath); + parser.update_project(cfg, function() { + // Call plugman --prepare for this platform. sets up js-modules appropriately. + var plugins_dir = path.join(projectRoot, 'plugins'); + events.emit('log', 'Calling plugman.prepare for platform "' + platform + '"'); + plugman.prepare(platformPath, (platform=='blackberry'?'blackberry10':platform), plugins_dir); + // Make sure that config changes for each existing plugin is in place + var plugins = cordova_util.findPlugins(plugins_dir); + var platform_json = plugman.config_changes.get_platform_json(plugins_dir, (platform=='blackberry'?'blackberry10':platform)); + plugins && plugins.forEach(function(plugin_id) { + if (platform_json.installed_plugins[plugin_id]) { + events.emit('log', 'Ensuring plugin "' + plugin_id + '" is installed correctly...'); + plugman.config_changes.add_plugin_changes((platform=='blackberry'?'blackberry10':platform), platformPath, plugins_dir, plugin_id, /* variables for plugin */ platform_json.installed_plugins[plugin_id], /* top level plugin? */ true, /* should increment config munge? cordova-cli never should, only plugman */ false); + } else if (platform_json.dependent_plugins[plugin_id]) { + events.emit('log', 'Ensuring plugin "' + plugin_id + '" is installed correctly...'); + plugman.config_changes.add_plugin_changes((platform=='blackberry'?'blackberry10':platform), platformPath, plugins_dir, plugin_id, /* variables for plugin */ platform_json.dependent_plugins[plugin_id], /* top level plugin? */ false, /* should increment config munge? cordova-cli never should, only plugman */ false); + } + events.emit('log', 'Plugin "' + plugin_id + '" is good to go.'); + }); + end(); + }); + } }); }); }