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 4174A10AC3 for ; Mon, 26 Aug 2013 23:47:36 +0000 (UTC) Received: (qmail 18405 invoked by uid 500); 26 Aug 2013 23:47:36 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 18349 invoked by uid 500); 26 Aug 2013 23:47:36 -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 18268 invoked by uid 99); 26 Aug 2013 23:47:36 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Aug 2013 23:47:36 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id D64361E262; Mon, 26 Aug 2013 23:47:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: timkim@apache.org To: commits@cordova.apache.org Date: Mon, 26 Aug 2013 23:47:37 -0000 Message-Id: <18c6dd86708245b0b21d54c5da896e87@git.apache.org> In-Reply-To: <6120ab4aec714c3ba9f489710934fc48@git.apache.org> References: <6120ab4aec714c3ba9f489710934fc48@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [03/17] git commit: [CB-4036] - another pass at the engine/platform check problem [CB-4036] - another pass at the engine/platform check problem Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/078f9bfb Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/078f9bfb Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/078f9bfb Branch: refs/heads/master Commit: 078f9bfb01e5bec8b6c1a7bf5076918e5f6b3cfd Parents: eadd4ce Author: Tim Kim Authored: Wed Aug 7 15:03:54 2013 -0700 Committer: Tim Kim Committed: Mon Aug 26 16:47:16 2013 -0700 ---------------------------------------------------------------------- spec/plugins/EnginePlugin/plugin.xml | 2 +- src/install.js | 159 ++++++++++++------------------ src/util/default-engines.js | 32 ++++++ 3 files changed, 97 insertions(+), 96 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/078f9bfb/spec/plugins/EnginePlugin/plugin.xml ---------------------------------------------------------------------- diff --git a/spec/plugins/EnginePlugin/plugin.xml b/spec/plugins/EnginePlugin/plugin.xml index 62233e3..fe875a3 100644 --- a/spec/plugins/EnginePlugin/plugin.xml +++ b/spec/plugins/EnginePlugin/plugin.xml @@ -24,7 +24,7 @@ Engine Choo Choo - + http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/078f9bfb/src/install.js ---------------------------------------------------------------------- diff --git a/src/install.js b/src/install.js index d54ed1d..fee217e 100644 --- a/src/install.js +++ b/src/install.js @@ -65,104 +65,74 @@ function possiblyFetch(actions, platform, project_dir, id, plugins_dir, options, } } -function checkMinimumReq(currentProjectInfo, minRequirements, platform, callback) { - if(currentProjectInfo.cordovaVersion) { - if(currentProjectInfo.cordovaVersion == 'dev' || semver.satisfies(currentProjectInfo.cordovaVersion, minRequirements.cordovaMinVersion)){ +function checkMinimumReq(engines, callback) { + engines.forEach(function(engine){ + if(engine.currentVersion == 'dev' || semver.satisfies(engine.currentVersion, engine.minVersion || engine.currentVersion == null)){ // engine ok! - } else { - var err = new Error('Plugin doesn\'t support this project\'s Cordova version. Project version: ' + currentProjectInfo.cordovaVersion + ', failed version requirement: ' + minRequirements.cordovaMinVersion); - if (callback) return callback(err); - else throw err; - } - } - - if(currentProjectInfo.min_os_version) { - if(semver.satisfies(currentProjectInfo.min_os_version, minRequirements.platformMinOS)) { - // min-os version ok - } else { - var err = new Error('Plugin doesn\'t support ' + platform + ' minimum os version. ' + platform + ' minimum os version: ' + currentProjectInfo.min_os_version + ', failed version requirement: ' + minRequirements.platformMinOS); - if (callback) return callback(err); - else throw err; - } - } - - if(currentProjectInfo.min_sdk_version) { - if(semver.satisfies(currentProjectInfo.min_sdk_version, minRequirements.platformMinSDK)) { - // min-sdk version ok - } else { - var err = new Error('Plugin doesn\'t support ' + platform + ' minimum sdk version. ' + platform + ' minimum sdk version: ' + currentProjectInfo.min_sdk_version + ', failed version requirement: ' + minRequirements.platformMinSDK); + }else{ + var err = new Error('Plugin doesn\'t support this project\'s '+engine.name+' version. '+engine.name+': ' + engine.currentVersion + ', failed version requirement: ' + engine.minVersion); if (callback) return callback(err); else throw err; - } - } + } + }); } -// use the project level cordova scripts to get the current cordova version and platform information -function getCurrentProjectVersion(versionPath, platformPath) { - // need to think about a more graceful way of handling when these scripts break or when they are not detected - // setting version/platform to null if they do fail or do not exist and then just continuing - - var cordovaVersion, platformInfo; - - if (fs.existsSync(versionPath)) { - fs.chmodSync(versionPath, '755'); - var versionScript = shell.exec(versionPath, {silent: true}); - if (versionScript.code === 0) { - cordovaVersion = versionScript.output.trim(); - var rc_index = cordovaVersion.indexOf('rc'); - if (rc_index > -1) { - cordovaVersion = cordovaVersion.substr(0, rc_index) + '-' + cordovaVersion.substr(rc_index); - } - }else{ - cordovaVersion = null; - require('../plugman').emit('log', 'Cordova project version script failed (has a ./cordova/version script, but something went wrong executing it), continuing anyways.'); - } - }else{ - cordovaVersion = null; - require('../plugman').emit('log', 'Cordova project version not detected (lacks a ./cordova/version script), continuing.'); - } +// exec engine scripts in order to get the current engine version +function callEngineScripts(engines) { + var engineScript; + var engineScriptVersion; - if (fs.existsSync(platformPath)) { - fs.chmodSync(platformPath, '755'); - var platformScript = shell.exec(platformPath, {silent: true}); - if (platformScript.code === 0) { - // thinking platformScript.output would be a JSON string like: - // { min_os_version: "5.0.0" , min_sdk_version: "1.0.0" } - platformInfo = platformScript.output; + engines.forEach(function(engine){ + if(fs.exists(engine.scriptTarget)){ + fs.chmodSync(engine.scriptTarget, '755'); + engineScript = shell.exec(versionPath, {silent: true}); + + if (engineScript.code === 0) { + engineScriptVersion = engineScript.output.trim(); + var rc_index = engineScriptVersion.indexOf('rc'); + if (rc_index > -1) { + engineScriptVersion = engineScriptVersion.substr(0, rc_index) + '-' + engineScriptVersion.substr(rc_index); + } + + }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.'); + } }else{ - platformInfo = null; - require('../plugman').emit('log', 'Cordova project platformReq script failed (has a ./cordova/platformReq script, but something went wrong executing it), continuing anyways.'); - } - }else{ - platformInfo = null; - require('../plugman').emit('log', 'Cordova project version not detected (lacks a ./cordova/version script), continuing.'); - } + engineScriptVersion = null; + require('../plugman').emit('log', 'Cordova project '+ engine.scriptTarget +' not detected (lacks a '+ engine.scriptTarget +' script), continuing.'); + } + engine.currentVersion = engineScriptVersion; + + }); - return { 'cordovaVersion' : cordovaVersion, 'platformInfo' : platformInfo }; + return engines; } -function getMinReq(pluginElement, platform){ - - var cordovaMinVersion, platformMinOS, platformMinSDK; - +// return only the engines we care about/need +function getEngines(pluginElement, platform, project_dir){ var engines = pluginElement.findall('engines/engine'); - engines.forEach(function(engine){ - if(engine.attrib["name"].toLowerCase() === "cordova"){ - cordovaMinVersion = engine.attrib["version"]; - }else{ - // check for other engines - if found, shove the info into return statement - } - }); - - - // these elements are still in flux - most likely to change when the platforms start implementing these scripts - platformMinOS = pluginElement.findall('./platform[@name="'+platform+'"][@min-os-version]'); - platformMinOS = platformMinOS[0] ? platformMinOS[0].attrib["min-os-version"] : null - - platformMinSDK = pluginElement.findall('./platform[@name="'+platform+'"][@min-sdk-version]'); - platformMinSDK = platformMinSDK[0] ? platformMinSDK[0].attrib["min-sdk-version"] : null; - - return { 'cordovaMinVersion': cordovaMinVersion, 'platformMinOS' : platformMinOS, 'platformMinSDK' : platformMinSDK }; + var defaultEngines = require('./util/default-engines'); + var uncheckedEngines = []; + var tempEngine; + + // load in all known defaults and compare + engines.forEach(function(engine){ + // this may need some changes - what to do for default platforms - why need to specify platforms? + if(engine.attrib["platform"] === platform || engine.attrib["platform"] === '*'){ + if(defaultEngines[engine.attrib["name"]]){ + defaultEngines[engine.attrib["name"]].minVersion = defaultEngines[engine.attrib["version"]]; + defaultEngines[engine.attrib["name"]].scriptTarget = path.join(project_dir, defaultEngines[engine.attrib["name"]].scriptTarget); + uncheckedEngines.push(defaultEngines[engine.attrib["name"]]); + }else{ + // check for other engines + tempEngine = {}; + tempEngine[engine.attrib["name"]] = { 'platform': engine.attrib["platform"], 'scriptTarget':path.join(project_dir,engine.attrib["scriptTarget"]), 'minVersion' : engine.attrib["version"]}; + uncheckedEngines.push(tempEngine); + } + } + }); + return uncheckedEngines; } @@ -194,19 +164,18 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt if (callback) callback(); return; } - - var versionPath = path.join(project_dir, 'cordova', 'version'); + + //var versionPath = path.join(project_dir, 'cordova', 'version'); // windows8, wp7, wp8 all use a .bat file + /* if (platform === "windows8" || platform === "wp7" || platform === "wp8") { versionPath += ".bat"; } - - var platformPath = path.join(project_dir, 'cordova', 'platformReq'); - - var currentProjectInfo = getCurrentProjectVersion(versionPath, platformPath); - var minRequirements = getMinReq(plugin_et, platform); + */ - checkMinimumReq(currentProjectInfo, minRequirements, platform, callback); + var theEngines = getEngines(plugin_et, platform, project_dir); + theEngines = callEngineScripts(theEngines); + checkMinimumReq(theEngines, callback); // checking preferences, if certain variables are not provided, we should throw. prefs = plugin_et.findall('./preference') || []; http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/078f9bfb/src/util/default-engines.js ---------------------------------------------------------------------- diff --git a/src/util/default-engines.js b/src/util/default-engines.js new file mode 100644 index 0000000..4499df6 --- /dev/null +++ b/src/util/default-engines.js @@ -0,0 +1,32 @@ +var path = require('path'); + +// wondering how to nicely store paths here... +// it'd be nice to just point to this file and get the correct path +// since these scripts should ideally be accessed from the cordova project folder + +module.exports = { + 'cordova': + { 'platform':'*', 'scriptTarget': path.join('cordova','version') }, + 'cordova-plugman': + { 'platform':'*', 'scriptTarget': '' }, + 'cordova-android': + { 'platform':'android', 'scriptTarget': '' }, + 'cordova-ios': + { 'platform':'ios', 'scriptTarget': '' }, + 'cordova-blackberry10': + { 'platform':'blackberry10', 'scriptTarget': '' }, + 'cordova-wp7': + { 'platform':'wp7', 'scriptTarget': '' }, + 'cordova-wp8': + { 'platform':'wp8', 'scriptTarget': '' }, + 'cordova-windows8': + { 'platform':'windows8', 'scriptTarget': '' }, + 'apple-xcode' : + { 'platform':'ios', 'scriptTarget': '' }, + 'apple-ios' : + { 'platform':'ios', 'scriptTarget': '' }, + 'blackberry-webworks' : + { 'platform':'blackberry10', 'scriptTarget': '' }, + 'android-sdk' : + { 'platform':'android', 'scriptTarget': '' } +};