[CB-4036] - added ability to list multiple platforms in plugin.xml
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/2e03e732 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/2e03e732 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/2e03e732 Branch: refs/heads/master Commit: 2e03e73225c91c9125c1687521706d22bdb2c528 Parents: 0da4b35 Author: Tim Kim <[email protected]> Authored: Mon Aug 26 16:30:43 2013 -0700 Committer: Tim Kim <[email protected]> Committed: Mon Aug 26 16:47:18 2013 -0700 ---------------------------------------------------------------------- spec/install.spec.js | 10 +++++++++ spec/plugins/EnginePlugin/plugin.xml | 1 + src/install.js | 36 +++++++++++++++++++------------ 3 files changed, 33 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/2e03e732/spec/install.spec.js ---------------------------------------------------------------------- diff --git a/spec/install.spec.js b/spec/install.spec.js index ccee749..04fd7c2 100644 --- a/spec/install.spec.js +++ b/spec/install.spec.js @@ -96,6 +96,16 @@ describe('install', function() { install('android', temp, 'engineplugin', plugins_dir, {}); expect(spy).toHaveBeenCalledWith(null,'>=1.0.0'); }); + it('should check custom engine version that supports multiple platforms', function() { + var spy = spyOn(semver, 'satisfies').andReturn(true); + install('android', temp, 'engineplugin', plugins_dir, {}); + expect(spy).toHaveBeenCalledWith(null,'>=3.0.0'); + }); + it('should not check custom engine version that is not supported for platform', function() { + var spy = spyOn(semver, 'satisfies').andReturn(true); + install('blackberry10', temp, 'engineplugin', plugins_dir, {}); + expect(spy).not.toHaveBeenCalledWith(null,'>=3.0.0'); + }); it('should queue up actions as appropriate for that plugin and call process on the action stack', function() { install('android', temp, dummyplugin, plugins_dir, {}); expect(actions_push.calls.length).toEqual(3); http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/2e03e732/spec/plugins/EnginePlugin/plugin.xml ---------------------------------------------------------------------- diff --git a/spec/plugins/EnginePlugin/plugin.xml b/spec/plugins/EnginePlugin/plugin.xml index a855d1b..a58f19e 100644 --- a/spec/plugins/EnginePlugin/plugin.xml +++ b/spec/plugins/EnginePlugin/plugin.xml @@ -27,6 +27,7 @@ <engine name="cordova" version=">=2.3.0"/> <engine name="cordova-plugman" version=">=0.10.0" /> <engine name="mega-fun-plugin" version=">=1.0.0" scriptSrc="megaFunVersion" platform="*" /> + <engine name="mega-boring-plugin" version=">=3.0.0" scriptSrc="megaBoringVersion" platform="ios|android" /> </engines> </plugin> http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/2e03e732/src/install.js ---------------------------------------------------------------------- diff --git a/src/install.js b/src/install.js index 9934d82..1959f07 100644 --- a/src/install.js +++ b/src/install.js @@ -130,25 +130,33 @@ function getEngines(pluginElement, platform, project_dir, plugin_dir){ var engines = pluginElement.findall('engines/engine'); var defaultEngines = require('./util/default-engines')(project_dir); var uncheckedEngines = []; - var cordovaEngineIndex, cordovaPlatformEngineIndex, theName; + var cordovaEngineIndex, cordovaPlatformEngineIndex, theName, platformIndex, defaultPlatformIndex; // load in known defaults and update when necessary engines.forEach(function(engine){ theName = engine.attrib["name"]; + // check to see if the engine is listed as a default engine - if(defaultEngines[theName] && (defaultEngines[theName].platform === platform || defaultEngines[theName].platform === '*')){ - defaultEngines[theName].minVersion = defaultEngines[theName].minVersion ? defaultEngines[theName].minVersion : engine.attrib["version"]; - defaultEngines[theName].currentVersion = defaultEngines[theName].currentVersion ? defaultEngines[theName].currentVersion : null; - defaultEngines[theName].scriptSrc = defaultEngines[theName].scriptSrc ? defaultEngines[theName].scriptSrc : null; - defaultEngines[theName].name = theName; - - // set the indices so we can pop the cordova engine when needed - if(theName==='cordova') cordovaEngineIndex = uncheckedEngines.length; - if(theName==='cordova-'+platform) cordovaPlatformEngineIndex = uncheckedEngines.length; - - uncheckedEngines.push(defaultEngines[theName]); + if(defaultEngines[theName]){ + // make sure engine is for platform we are installing on + defaultPlatformIndex = defaultEngines[theName].platform.indexOf(platform); + if(defaultPlatformIndex > -1 || defaultEngines[theName].platform === '*'){ + defaultEngines[theName].minVersion = defaultEngines[theName].minVersion ? defaultEngines[theName].minVersion : engine.attrib["version"]; + defaultEngines[theName].currentVersion = defaultEngines[theName].currentVersion ? defaultEngines[theName].currentVersion : null; + defaultEngines[theName].scriptSrc = defaultEngines[theName].scriptSrc ? defaultEngines[theName].scriptSrc : null; + defaultEngines[theName].name = theName; + + // set the indices so we can pop the cordova engine when needed + if(theName==='cordova') cordovaEngineIndex = uncheckedEngines.length; + if(theName==='cordova-'+platform) cordovaPlatformEngineIndex = uncheckedEngines.length; + + uncheckedEngines.push(defaultEngines[theName]); + } // check for other engines - }else if(engine.attrib["platform"] === platform || engine.attrib["platform"] === '*'){ - uncheckedEngines.push({ 'name': theName, 'platform': engine.attrib["platform"], 'scriptSrc':path.resolve(plugin_dir, engine.attrib["scriptSrc"]), 'minVersion' : engine.attrib["version"]}); + }else{ + platformIndex = engine.attrib["platform"].indexOf(platform); + if(platformIndex > -1 || engine.attrib["platform"] === '*'){ + uncheckedEngines.push({ 'name': theName, 'platform': engine.attrib["platform"], 'scriptSrc':path.resolve(plugin_dir, engine.attrib["scriptSrc"]), 'minVersion' : engine.attrib["version"]}); + } } });
