Return-Path: X-Original-To: apmail-cordova-dev-archive@www.apache.org Delivered-To: apmail-cordova-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3CED2177B1 for ; Tue, 10 Mar 2015 05:27:51 +0000 (UTC) Received: (qmail 74842 invoked by uid 500); 10 Mar 2015 05:27:51 -0000 Delivered-To: apmail-cordova-dev-archive@cordova.apache.org Received: (qmail 74804 invoked by uid 500); 10 Mar 2015 05:27:50 -0000 Mailing-List: contact dev-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 dev@cordova.apache.org Received: (qmail 74793 invoked by uid 99); 10 Mar 2015 05:27:50 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Mar 2015 05:27:50 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 74258E1849; Tue, 10 Mar 2015 05:27:50 +0000 (UTC) From: omefire To: dev@cordova.apache.org Reply-To: dev@cordova.apache.org References: In-Reply-To: Subject: [GitHub] cordova-lib pull request: Deprecate the old feature syntax from co... Content-Type: text/plain Message-Id: <20150310052750.74258E1849@git1-us-west.apache.org> Date: Tue, 10 Mar 2015 05:27:50 +0000 (UTC) Github user omefire commented on a diff in the pull request: https://github.com/apache/cordova-lib/pull/182#discussion_r26099612 --- Diff: cordova-lib/src/configparser/ConfigParser.js --- @@ -279,113 +269,108 @@ ConfigParser.prototype = { return scriptElements.filter(filterScriptByHookType); }, - + /** + * Returns a list of plugin (IDs) + * @return {string[]} Array of plugin IDs + */ + getPluginIdList: function () { + var plugins = this.doc.findall('plugin'); + var result = plugins.map(function(plugin){ + return plugin.attrib.name; + }); + var features = this.doc.findall('feature'); + features.forEach(function(element ){ + var idTag = element.find('./param[@name="id"]'); + if(idTag){ + result.push(idTag.attrib.value); + } + }); + return result; + }, /** - * Returns a list of features (IDs) - * @return {string[]} Array of feature IDs + * Adds a plugin element. Does not check for duplicates. + * @name addPlugin + * @function + * @param {object} attributes name, version and src are supported + * @param {Array} variables name, value */ - getFeatureIdList: function () { - var features = this.doc.findall('feature'), - feature, idTag, id, - result = []; - - // Check for valid features that have IDs set - for (var i = 0, l = features.length; i < l; ++i) { - feature = features[i]; - idTag = feature.find('./param[@name="id"]'); - if (null === idTag) { - // Invalid feature - continue; - } - id = idTag.attrib.value; - if (!!id) { - // Has id and id is non-empty - result.push(id); - } + addPlugin: function(attributes, variables){ + if ( !attributes && !attributes.name ) return; + var el = new et.Element('plugin'); + el.attrib.name =attributes.name; + if ( attributes.version) { + el.attrib.version =attributes.version; } - - return result; + if ( attributes.src){ + el.attrib.src = attributes.src; + } + if(variables){ + variables.forEach(function(variable){ + var v = new et.Element('variable'); + v.attrib.name=variable.name; + v.attrib.value=variable.value; + el.append(v); + }); + } + this.doc.getroot().append(el); }, - /** - * Gets feature info - * @param {string} id Feature id - * @returns {Feature} Feature object + * Retrives the plugin with the given id or null if not found. + * @name getPlugin + * @function + * @param {String} id + * @returns {object} plugin including any variables */ - getFeature: function(id) { - if (!id) { + getPlugin: function(id){ + if(!id){ return undefined; } - var feature = this.doc.find('./feature/param[@name="id"][@value="' + id + '"]/..'); - if (null === feature) { + var pluginElement = this.doc.find('./plugin/[@name="' + id + '"]'); + if (null === pluginElement) { + var legacyFeature = this.doc.find('./feature/param[@name="id"][@value="' + id + '"]/..'); + if(legacyFeature){ + var events = require('../events'); + events.emit('log', 'Found deprecated feature entry for ' + id +' in config.xml.'); + return featureToPlugin(legacyFeature); + } return undefined; } - - var result = {}; - result.id = id; - result.name = feature.attrib.name; - - // Iterate params and fill-in 'params' structure - // For special cases like 'id', 'url, 'version' - copy to the main space - result.params = processChildren ( - 'param', - function(name, value) { - if (FEATURE_SPECIAL_PARAMS.indexOf(name) >= 0) { - result[name] = value; - } + var plugin = {}; + plugin.name = pluginElement.attrib.name; + plugin.version = pluginElement.attrib.version; + plugin.src = pluginElement.attrib.src; + plugin.variables = {}; + var variableElements = pluginElement.findall('variable'); + variableElements.forEach(function(varElement){ + var name = varElement.attrib.name; + var value = varElement.attrib.value; + if(name){ + plugin.variables[name] = value; } - ); - - // Iterate preferences - result.variables = processChildren('param'); - - return result; - - /** - * Processes a set of children - * having a pair of 'name' and 'value' attributes - * filling in 'output' object - * @param {string} xPath Search expression - * @param {function} [specialProcessing] Performs some additional actions on each valid element - * @return {object} A transformed object - */ - function processChildren (xPath, specialProcessing) { - var result = {}; - var needsProcessing = 'function' === typeof specialProcessing; - var nodes = feature.findall(xPath); - nodes.forEach(function(param){ - var name = param.attrib.name; - var value = param.attrib.value; - if (name) { - result[name] = value; - if (needsProcessing) { - specialProcessing(name, value); - } - } - }); - return result; - } + }); + return plugin; }, - - /** - *This does not check for duplicate feature entries + * Remove the plugin entry with give name (id) + * @name removePlugin + * @function + * @param id name of the plugin */ - addFeature: function (name, params){ - if(!name) return; - var el = new et.Element('feature'); - el.attrib.name = name; - if (params) { - params.forEach(function(param){ - var p = new et.Element('param'); - p.attrib.name = param.name; - p.attrib.value = param.value; - el.append(p); - }); + removePlugin: function(id){ + if(id){ + var theElement = this.doc.find('./plugin/[@name="' + id + '"]'); + if(!theElement){ + theElement = this.doc.find('./feature/param[@name="id"][@value="' + id + '"]/..'); + } + if(theElement){ + var childs = this.doc.getroot().getchildren(); --- End diff -- childs -> children --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org For additional commands, e-mail: dev-help@cordova.apache.org