[BlackBerry10] Process plugin clobbers and merges Reviewed by Jeffrey Heifetz <jheif...@blackberry.com>
Project: http://git-wip-us.apache.org/repos/asf/cordova-js/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-js/commit/d4fa7d39 Tree: http://git-wip-us.apache.org/repos/asf/cordova-js/tree/d4fa7d39 Diff: http://git-wip-us.apache.org/repos/asf/cordova-js/diff/d4fa7d39 Branch: refs/heads/master Commit: d4fa7d3921ee1d11d450c9d38531c4ba01bab3bc Parents: d2f5266 Author: Bryan Higgins <bhigg...@blackberry.com> Authored: Mon Mar 18 14:16:22 2013 -0400 Committer: Bryan Higgins <bhigg...@blackberry.com> Committed: Fri May 3 09:49:31 2013 -0400 ---------------------------------------------------------------------- .../plugin/blackberry10/pluginUtils.js | 16 +++++++++ test/blackberry10/test.pluginUtils.js | 27 ++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-js/blob/d4fa7d39/lib/blackberry10/plugin/blackberry10/pluginUtils.js ---------------------------------------------------------------------- diff --git a/lib/blackberry10/plugin/blackberry10/pluginUtils.js b/lib/blackberry10/plugin/blackberry10/pluginUtils.js index 9a52a25..88f03c5 100644 --- a/lib/blackberry10/plugin/blackberry10/pluginUtils.js +++ b/lib/blackberry10/plugin/blackberry10/pluginUtils.js @@ -19,6 +19,21 @@ * */ +function build(plugins) { + var builder = require('cordova/builder'), + plugin; + for (plugin in plugins) { + if (plugins.hasOwnProperty(plugin)) { + if (plugins[plugin].clobbers) { + builder.buildIntoAndClobber(plugins[plugin].clobbers, window); + } + if (plugins[plugin].merges) { + builder.buildIntoAndMerge(plugins[plugin].merges, window); + } + } + } +} + module.exports = { loadClientJs: function (plugins, callback) { @@ -33,6 +48,7 @@ module.exports = { script.src = 'plugins/' + plugin + '/' + plugins[plugin].modules[i]; script.onload = function () { if (--count === 0 && typeof callback === 'function') { + build(plugins); callback(); } }; http://git-wip-us.apache.org/repos/asf/cordova-js/blob/d4fa7d39/test/blackberry10/test.pluginUtils.js ---------------------------------------------------------------------- diff --git a/test/blackberry10/test.pluginUtils.js b/test/blackberry10/test.pluginUtils.js index 37f0e9c..6b5a24a 100644 --- a/test/blackberry10/test.pluginUtils.js +++ b/test/blackberry10/test.pluginUtils.js @@ -21,7 +21,8 @@ describe('blackberry10 pluginUtils', function () { - var pluginUtils = require('cordova/plugin/blackberry10/pluginUtils'); + var pluginUtils = require('cordova/plugin/blackberry10/pluginUtils'), + builder = require('cordova/builder'); describe('loadClientJs', function () { @@ -35,6 +36,8 @@ describe('blackberry10 pluginUtils', function () { }); spyOn(document.head, "appendChild"); callback = jasmine.createSpy(); + spyOn(builder, "buildIntoAndClobber"); + spyOn(builder, "buildIntoAndMerge"); }); it('does nothing for 0 plugins', function () { @@ -46,7 +49,7 @@ describe('blackberry10 pluginUtils', function () { }); it('adds a script tag for 1 plugin', function () { - var plugins = { foo : { client: ['bar.js'] } }; + var plugins = { foo : { modules: ['bar.js'] } }; pluginUtils.loadClientJs(plugins, callback); expect(document.createElement).toHaveBeenCalled(); expect(script.src).toEqual('plugins/foo/bar.js'); @@ -56,7 +59,7 @@ describe('blackberry10 pluginUtils', function () { }); it('adds multiple script tags for 1 plugin', function () { - var plugins = { foo: { client: ['bar.js', '2.js'] } }; + var plugins = { foo: { modules: ['bar.js', '2.js'] } }; pluginUtils.loadClientJs(plugins, callback); expect(document.createElement.callCount).toBe(2); expect(document.head.appendChild.callCount).toBe(2); @@ -66,7 +69,7 @@ describe('blackberry10 pluginUtils', function () { }); it('adds script tags for multiple plugins', function () { - var plugins = { foo: { client: ['1.js'] }, bar: { client: ['1.js', '2.js' ] } }; + var plugins = { foo: { modules: ['1.js'] }, bar: { modules: ['1.js', '2.js' ] } }; pluginUtils.loadClientJs(plugins, callback); expect(document.createElement.callCount).toBe(3); expect(document.head.appendChild.callCount).toBe(3); @@ -76,6 +79,22 @@ describe('blackberry10 pluginUtils', function () { expect(callback.callCount).toBe(1); }); + it('calls clobber', function () { + var plugins = { foo: { modules : ['bar.js'], clobbers: { bar: { path: 'foo.bar' } } } }; + pluginUtils.loadClientJs(plugins, callback); + script.onload(); + expect(callback.callCount).toBe(1); + expect(builder.buildIntoAndClobber).toHaveBeenCalledWith(plugins.foo.clobbers, window); + }); + + it('calls merge', function () { + var plugins = { foo: { modules : ['bar.js'], merges: { bar: { path: 'foo.bar' } } } }; + pluginUtils.loadClientJs(plugins, callback); + script.onload(); + expect(callback.callCount).toBe(1); + expect(builder.buildIntoAndMerge).toHaveBeenCalledWith(plugins.foo.merges, window); + }); + }); describe('getPlugins', function () {