[CB-4036] - added more tests and fixed up some logic
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/9d6b99ea Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/9d6b99ea Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/9d6b99ea Branch: refs/heads/master Commit: 9d6b99ea3512b6cb326ecd3e7365750e0407eb23 Parents: 0414fe4 Author: Tim Kim <[email protected]> Authored: Wed Aug 21 15:10:18 2013 -0700 Committer: Tim Kim <[email protected]> Committed: Mon Aug 26 16:47:17 2013 -0700 ---------------------------------------------------------------------- spec/install.spec.js | 18 ++++++++ spec/plugins/EnginePlugin/plugin.xml | 5 +-- spec/plugins/EnginePluginAndroid/plugin.xml | 31 +++++++++++++ src/install.js | 56 +++++++++++------------- src/util/default-engines.js | 22 +++++----- 5 files changed, 87 insertions(+), 45 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/9d6b99ea/spec/install.spec.js ---------------------------------------------------------------------- diff --git a/spec/install.spec.js b/spec/install.spec.js index f3f2e51..22740ef 100644 --- a/spec/install.spec.js +++ b/spec/install.spec.js @@ -74,6 +74,17 @@ describe('install', function() { install('android', temp, 'engineplugin', plugins_dir, {}); expect(spy).toHaveBeenCalledWith('3.0.0-rc1','>=2.3.0'); }); + it('should check specific platform version if specified', function() { + var spy = spyOn(semver, 'satisfies').andReturn(true); + exec.andReturn({code:0,output:"3.1.0"}); + install('android', temp, 'enginepluginAndroid', plugins_dir, {}); + expect(spy).toHaveBeenCalledWith('3.1.0','>=3.1.0'); + }); + it('should check plugmans version', function() { + var spy = spyOn(semver, 'satisfies').andReturn(true); + install('android', temp, 'engineplugin', plugins_dir, {}); + expect(spy).toHaveBeenCalledWith(null,'>=0.10.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); @@ -135,5 +146,12 @@ describe('install', function() { install('android', temp, 'https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git', plugins_dir, {}); }).toThrow('"git" command line tool is not installed: make sure it is accessible on your PATH.'); }); + it('should throw if plugin version is less than the minimum requirement', function(){ + var spy = spyOn(semver, 'satisfies').andReturn(false); + exec.andReturn({code:0,output:"0.0.1"}); + expect(function() { + install('android', temp, 'engineplugin', plugins_dir, {}); + }).toThrow('Plugin doesn\'t support this project\'s cordova version. cordova: 0.0.1, failed version requirement: >=2.3.0'); + }); }); }); http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/9d6b99ea/spec/plugins/EnginePlugin/plugin.xml ---------------------------------------------------------------------- diff --git a/spec/plugins/EnginePlugin/plugin.xml b/spec/plugins/EnginePlugin/plugin.xml index 72bf190..4d9332f 100644 --- a/spec/plugins/EnginePlugin/plugin.xml +++ b/spec/plugins/EnginePlugin/plugin.xml @@ -24,9 +24,8 @@ <name>Engine Choo Choo</name> <engines> - <engine name="cordova" version=">=2.3.0" platform="*" /> - <engine name="cordova-plugman" version=">=0.10.0" platform="*" /> - <engine name="cordova-android" version=">=3.1.0" platform="*" /> + <engine name="cordova" version=">=2.3.0"/> + <engine name="cordova-plugman" version=">=0.10.0" /> </engines> </plugin> http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/9d6b99ea/spec/plugins/EnginePluginAndroid/plugin.xml ---------------------------------------------------------------------- diff --git a/spec/plugins/EnginePluginAndroid/plugin.xml b/spec/plugins/EnginePluginAndroid/plugin.xml new file mode 100644 index 0000000..894bd02 --- /dev/null +++ b/spec/plugins/EnginePluginAndroid/plugin.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + +--> + +<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0" + xmlns="http://www.phonegap.com/ns/plugins/1.0" + id="com.cordova.engine" + version="1.0.0"> + + <name>Engine Choo Choo</name> + + <engines> + <engine name="cordova" version=">=3.0.0"/> + <engine name="cordova-android" version=">=3.1.0"/> + </engines> + +</plugin> http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/9d6b99ea/src/install.js ---------------------------------------------------------------------- diff --git a/src/install.js b/src/install.js index 59334dc..cfaead9 100644 --- a/src/install.js +++ b/src/install.js @@ -99,20 +99,20 @@ function callEngineScripts(engines) { var engineScriptVersion; engines.forEach(function(engine){ - if(fs.existsSync(engine.scriptTarget)){ - fs.chmodSync(engine.scriptTarget, '755'); - engineScript = shell.exec(engine.scriptTarget, {silent: true}); + if(fs.existsSync(engine.scriptSrc)){ + fs.chmodSync(engine.scriptSrc, '755'); + engineScript = shell.exec(engine.scriptSrc, {silent: true}); if (engineScript.code === 0) { engineScriptVersion = cleanVersionOutput(engineScript.output, engine.platform) }else{ engineScriptVersion = null; - require('../plugman').emit('log', 'Cordova project '+ engine.scriptTarget +' script failed (has a '+ engine.scriptTarget +' script, but something went wrong executing it), continuing anyways.'); + require('../plugman').emit('log', 'Cordova project '+ engine.scriptSrc +' script failed (has a '+ engine.scriptSrc +' script, but something went wrong executing it), continuing anyways.'); } }else if(engine.currentVersion){ engineScriptVersion = cleanVersionOutput(engine.currentVersion, engine.platform) }else{ engineScriptVersion = null; - require('../plugman').emit('log', 'Cordova project '+ engine.scriptTarget +' not detected (lacks a '+ engine.scriptTarget +' script), continuing.'); + require('../plugman').emit('log', 'Cordova project '+ engine.scriptSrc +' not detected (lacks a '+ engine.scriptSrc +' script), continuing.'); } engine.currentVersion = engineScriptVersion; }); @@ -125,34 +125,28 @@ function getEngines(pluginElement, platform, project_dir){ var engines = pluginElement.findall('engines/engine'); var defaultEngines = require('./util/default-engines'); var uncheckedEngines = []; - var tempEngine; - var cordovaEngineIndex; - var cordovaPlatformEngineIndex; - - var theName; + var tempEngine, cordovaEngineIndex, cordovaPlatformEngineIndex, theName; // load in known defaults and update when necessary engines.forEach(function(engine){ - if(engine.attrib["platform"] === platform || engine.attrib["platform"] === '*'){ - theName = engine.attrib["name"]; - if(defaultEngines[theName]){ - defaultEngines[theName].minVersion = defaultEngines[theName].minVersion ? defaultEngines[theName].minVersion : engine.attrib["version"]; - defaultEngines[theName].currentVersion = defaultEngines[theName].currentVersion ? defaultEngines[theName].currentVersion : null; - defaultEngines[theName].scriptTarget = defaultEngines[theName].scriptTarget ? path.join(project_dir, defaultEngines[theName].scriptTarget) : 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]); - - }else{ - // check for other engines - tempEngine = {}; - tempEngine[theName] = { 'platform': engine.attrib["platform"], 'scriptTarget':path.join(project_dir,engine.attrib["scriptTarget"]), 'minVersion' : engine.attrib["version"]}; - uncheckedEngines.push(tempEngine); - } - } + theName = engine.attrib["name"]; + 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 ? path.join(project_dir, 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]); + + }else if(engine.attrib["platform"] === platform || engine.attrib["platform"] === '*'){ + // check for other engines + tempEngine = {}; + tempEngine[theName] = { 'platform': engine.attrib["platform"], 'scriptSrc':engine.attrib["scriptSrc"], 'minVersion' : engine.attrib["version"]}; + uncheckedEngines.push(tempEngine); + } }); // make sure we check for platform req's and not just cordova reqs http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/9d6b99ea/src/util/default-engines.js ---------------------------------------------------------------------- diff --git a/src/util/default-engines.js b/src/util/default-engines.js index b041951..0ab9b4f 100644 --- a/src/util/default-engines.js +++ b/src/util/default-engines.js @@ -6,38 +6,38 @@ var path = require('path'); module.exports = { 'cordova': - { 'platform':'*', 'scriptTarget': path.join('cordova','version') }, + { 'platform':'*', 'scriptSrc': path.join('cordova','version') }, // no location needed for plugman as this should be the calling process 'cordova-plugman': { 'platform':'*', 'currentVersion': process.version }, 'cordova-android': - { 'platform':'android', 'scriptTarget': path.join('cordova','version') }, + { 'platform':'android', 'scriptSrc': path.join('cordova','version') }, 'cordova-ios': - { 'platform':'ios', 'scriptTarget': path.join('cordova','version') }, + { 'platform':'ios', 'scriptSrc': path.join('cordova','version') }, 'cordova-blackberry10': - { 'platform':'blackberry10', 'scriptTarget': path.join('cordova','version') }, + { 'platform':'blackberry10', 'scriptSrc': path.join('cordova','version') }, 'cordova-wp7': - { 'platform':'wp7', 'scriptTarget': path.join('cordova','version') }, + { 'platform':'wp7', 'scriptSrc': path.join('cordova','version') }, 'cordova-wp8': - { 'platform':'wp8', 'scriptTarget': path.join('cordova','version') }, + { 'platform':'wp8', 'scriptSrc': path.join('cordova','version') }, 'cordova-windows8': - { 'platform':'windows8', 'scriptTarget': path.join('cordova','version') }, + { 'platform':'windows8', 'scriptSrc': path.join('cordova','version') }, // ideally these sdk versions will be known via a script // that calls the sdk's version command - the idea would be that // these version scripts output all in the same way and parse // the appropriate blob of info returned from the sdk version command 'apple-xcode' : - { 'platform':'ios', 'scriptTarget': '' }, + { 'platform':'ios', 'scriptSrc': '' }, 'apple-ios' : - { 'platform':'ios', 'scriptTarget': '' }, + { 'platform':'ios', 'scriptSrc': '' }, 'blackberry-webworks' : // use path to sdk/Framework/lib/webworks-info.js // will export as version number // currently though, all versions of webworks sdk should be good to go // so this is technically *not* needed right now - { 'platform':'blackberry10', 'scriptTarget': '' }, + { 'platform':'blackberry10', 'scriptSrc': '' }, 'android-sdk' : // will have to parse string output from android list targets - { 'platform':'android', 'scriptTarget': '' } + { 'platform':'android', 'scriptSrc': '' } };
