You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2015/10/31 03:50:30 UTC
[2/4] android commit: updated node_modules
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/4f7721b4/node_modules/cordova-common/src/ConfigChanges/munge-util.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-common/src/ConfigChanges/munge-util.js b/node_modules/cordova-common/src/ConfigChanges/munge-util.js
index 2e01445..307b3c1 100644
--- a/node_modules/cordova-common/src/ConfigChanges/munge-util.js
+++ b/node_modules/cordova-common/src/ConfigChanges/munge-util.js
@@ -1,160 +1,160 @@
-/*
- * 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.
- *
-*/
-/* jshint sub:true */
-
-var _ = require('underscore');
-
-// add the count of [key1][key2]...[keyN] to obj
-// return true if it didn't exist before
-exports.deep_add = function deep_add(obj, keys /* or key1, key2 .... */ ) {
- if ( !Array.isArray(keys) ) {
- keys = Array.prototype.slice.call(arguments, 1);
- }
-
- return exports.process_munge(obj, true/*createParents*/, function (parentArray, k) {
- var found = _.find(parentArray, function(element) {
- return element.xml == k.xml;
- });
- if (found) {
- found.after = found.after || k.after;
- found.count += k.count;
- } else {
- parentArray.push(k);
- }
- return !found;
- }, keys);
-};
-
-// decrement the count of [key1][key2]...[keyN] from obj and remove if it reaches 0
-// return true if it was removed or not found
-exports.deep_remove = function deep_remove(obj, keys /* or key1, key2 .... */ ) {
- if ( !Array.isArray(keys) ) {
- keys = Array.prototype.slice.call(arguments, 1);
- }
-
- var result = exports.process_munge(obj, false/*createParents*/, function (parentArray, k) {
- var index = -1;
- var found = _.find(parentArray, function (element) {
- index++;
- return element.xml == k.xml;
- });
- if (found) {
- found.count -= k.count;
- if (found.count > 0) {
- return false;
- }
- else {
- parentArray.splice(index, 1);
- }
- }
- return undefined;
- }, keys);
-
- return typeof result === 'undefined' ? true : result;
-};
-
-// search for [key1][key2]...[keyN]
-// return the object or undefined if not found
-exports.deep_find = function deep_find(obj, keys /* or key1, key2 .... */ ) {
- if ( !Array.isArray(keys) ) {
- keys = Array.prototype.slice.call(arguments, 1);
- }
-
- return exports.process_munge(obj, false/*createParents?*/, function (parentArray, k) {
- return _.find(parentArray, function (element) {
- return element.xml == (k.xml || k);
- });
- }, keys);
-};
-
-// Execute func passing it the parent array and the xmlChild key.
-// When createParents is true, add the file and parent items they are missing
-// When createParents is false, stop and return undefined if the file and/or parent items are missing
-
-exports.process_munge = function process_munge(obj, createParents, func, keys /* or key1, key2 .... */ ) {
- if ( !Array.isArray(keys) ) {
- keys = Array.prototype.slice.call(arguments, 1);
- }
- var k = keys[0];
- if (keys.length == 1) {
- return func(obj, k);
- } else if (keys.length == 2) {
- if (!obj.parents[k] && !createParents) {
- return undefined;
- }
- obj.parents[k] = obj.parents[k] || [];
- return exports.process_munge(obj.parents[k], createParents, func, keys.slice(1));
- } else if (keys.length == 3){
- if (!obj.files[k] && !createParents) {
- return undefined;
- }
- obj.files[k] = obj.files[k] || { parents: {} };
- return exports.process_munge(obj.files[k], createParents, func, keys.slice(1));
- } else {
- throw new Error('Invalid key format. Must contain at most 3 elements (file, parent, xmlChild).');
- }
-};
-
-// All values from munge are added to base as
-// base[file][selector][child] += munge[file][selector][child]
-// Returns a munge object containing values that exist in munge
-// but not in base.
-exports.increment_munge = function increment_munge(base, munge) {
- var diff = { files: {} };
-
- for (var file in munge.files) {
- for (var selector in munge.files[file].parents) {
- for (var xml_child in munge.files[file].parents[selector]) {
- var val = munge.files[file].parents[selector][xml_child];
- // if node not in base, add it to diff and base
- // else increment it's value in base without adding to diff
- var newlyAdded = exports.deep_add(base, [file, selector, val]);
- if (newlyAdded) {
- exports.deep_add(diff, file, selector, val);
- }
- }
- }
- }
- return diff;
-};
-
-// Update the base munge object as
-// base[file][selector][child] -= munge[file][selector][child]
-// nodes that reached zero value are removed from base and added to the returned munge
-// object.
-exports.decrement_munge = function decrement_munge(base, munge) {
- var zeroed = { files: {} };
-
- for (var file in munge.files) {
- for (var selector in munge.files[file].parents) {
- for (var xml_child in munge.files[file].parents[selector]) {
- var val = munge.files[file].parents[selector][xml_child];
- // if node not in base, add it to diff and base
- // else increment it's value in base without adding to diff
- var removed = exports.deep_remove(base, [file, selector, val]);
- if (removed) {
- exports.deep_add(zeroed, file, selector, val);
- }
- }
- }
- }
- return zeroed;
-};
-
-// For better readability where used
-exports.clone_munge = function clone_munge(munge) {
- return exports.increment_munge({}, munge);
-};
+/*
+ * 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.
+ *
+*/
+/* jshint sub:true */
+
+var _ = require('underscore');
+
+// add the count of [key1][key2]...[keyN] to obj
+// return true if it didn't exist before
+exports.deep_add = function deep_add(obj, keys /* or key1, key2 .... */ ) {
+ if ( !Array.isArray(keys) ) {
+ keys = Array.prototype.slice.call(arguments, 1);
+ }
+
+ return exports.process_munge(obj, true/*createParents*/, function (parentArray, k) {
+ var found = _.find(parentArray, function(element) {
+ return element.xml == k.xml;
+ });
+ if (found) {
+ found.after = found.after || k.after;
+ found.count += k.count;
+ } else {
+ parentArray.push(k);
+ }
+ return !found;
+ }, keys);
+};
+
+// decrement the count of [key1][key2]...[keyN] from obj and remove if it reaches 0
+// return true if it was removed or not found
+exports.deep_remove = function deep_remove(obj, keys /* or key1, key2 .... */ ) {
+ if ( !Array.isArray(keys) ) {
+ keys = Array.prototype.slice.call(arguments, 1);
+ }
+
+ var result = exports.process_munge(obj, false/*createParents*/, function (parentArray, k) {
+ var index = -1;
+ var found = _.find(parentArray, function (element) {
+ index++;
+ return element.xml == k.xml;
+ });
+ if (found) {
+ found.count -= k.count;
+ if (found.count > 0) {
+ return false;
+ }
+ else {
+ parentArray.splice(index, 1);
+ }
+ }
+ return undefined;
+ }, keys);
+
+ return typeof result === 'undefined' ? true : result;
+};
+
+// search for [key1][key2]...[keyN]
+// return the object or undefined if not found
+exports.deep_find = function deep_find(obj, keys /* or key1, key2 .... */ ) {
+ if ( !Array.isArray(keys) ) {
+ keys = Array.prototype.slice.call(arguments, 1);
+ }
+
+ return exports.process_munge(obj, false/*createParents?*/, function (parentArray, k) {
+ return _.find(parentArray, function (element) {
+ return element.xml == (k.xml || k);
+ });
+ }, keys);
+};
+
+// Execute func passing it the parent array and the xmlChild key.
+// When createParents is true, add the file and parent items they are missing
+// When createParents is false, stop and return undefined if the file and/or parent items are missing
+
+exports.process_munge = function process_munge(obj, createParents, func, keys /* or key1, key2 .... */ ) {
+ if ( !Array.isArray(keys) ) {
+ keys = Array.prototype.slice.call(arguments, 1);
+ }
+ var k = keys[0];
+ if (keys.length == 1) {
+ return func(obj, k);
+ } else if (keys.length == 2) {
+ if (!obj.parents[k] && !createParents) {
+ return undefined;
+ }
+ obj.parents[k] = obj.parents[k] || [];
+ return exports.process_munge(obj.parents[k], createParents, func, keys.slice(1));
+ } else if (keys.length == 3){
+ if (!obj.files[k] && !createParents) {
+ return undefined;
+ }
+ obj.files[k] = obj.files[k] || { parents: {} };
+ return exports.process_munge(obj.files[k], createParents, func, keys.slice(1));
+ } else {
+ throw new Error('Invalid key format. Must contain at most 3 elements (file, parent, xmlChild).');
+ }
+};
+
+// All values from munge are added to base as
+// base[file][selector][child] += munge[file][selector][child]
+// Returns a munge object containing values that exist in munge
+// but not in base.
+exports.increment_munge = function increment_munge(base, munge) {
+ var diff = { files: {} };
+
+ for (var file in munge.files) {
+ for (var selector in munge.files[file].parents) {
+ for (var xml_child in munge.files[file].parents[selector]) {
+ var val = munge.files[file].parents[selector][xml_child];
+ // if node not in base, add it to diff and base
+ // else increment it's value in base without adding to diff
+ var newlyAdded = exports.deep_add(base, [file, selector, val]);
+ if (newlyAdded) {
+ exports.deep_add(diff, file, selector, val);
+ }
+ }
+ }
+ }
+ return diff;
+};
+
+// Update the base munge object as
+// base[file][selector][child] -= munge[file][selector][child]
+// nodes that reached zero value are removed from base and added to the returned munge
+// object.
+exports.decrement_munge = function decrement_munge(base, munge) {
+ var zeroed = { files: {} };
+
+ for (var file in munge.files) {
+ for (var selector in munge.files[file].parents) {
+ for (var xml_child in munge.files[file].parents[selector]) {
+ var val = munge.files[file].parents[selector][xml_child];
+ // if node not in base, add it to diff and base
+ // else increment it's value in base without adding to diff
+ var removed = exports.deep_remove(base, [file, selector, val]);
+ if (removed) {
+ exports.deep_add(zeroed, file, selector, val);
+ }
+ }
+ }
+ }
+ return zeroed;
+};
+
+// For better readability where used
+exports.clone_munge = function clone_munge(munge) {
+ return exports.increment_munge({}, munge);
+};
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/4f7721b4/node_modules/cordova-common/src/ConfigParser/ConfigParser.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-common/src/ConfigParser/ConfigParser.js b/node_modules/cordova-common/src/ConfigParser/ConfigParser.js
index 03b4f1a..7abddf6 100644
--- a/node_modules/cordova-common/src/ConfigParser/ConfigParser.js
+++ b/node_modules/cordova-common/src/ConfigParser/ConfigParser.js
@@ -1,499 +1,499 @@
-/**
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you 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.
-*/
-
-/* jshint sub:true */
-
-var et = require('elementtree'),
- xml= require('../util/xml-helpers'),
- CordovaError = require('../CordovaError/CordovaError'),
- fs = require('fs'),
- events = require('../events');
-
-
-/** Wraps a config.xml file */
-function ConfigParser(path) {
- this.path = path;
- try {
- this.doc = xml.parseElementtreeSync(path);
- this.cdvNamespacePrefix = getCordovaNamespacePrefix(this.doc);
- et.register_namespace(this.cdvNamespacePrefix, 'http://cordova.apache.org/ns/1.0');
- } catch (e) {
- console.error('Parsing '+path+' failed');
- throw e;
- }
- var r = this.doc.getroot();
- if (r.tag !== 'widget') {
- throw new CordovaError(path + ' has incorrect root node name (expected "widget", was "' + r.tag + '")');
- }
-}
-
-function getNodeTextSafe(el) {
- return el && el.text && el.text.trim();
-}
-
-function findOrCreate(doc, name) {
- var ret = doc.find(name);
- if (!ret) {
- ret = new et.Element(name);
- doc.getroot().append(ret);
- }
- return ret;
-}
-
-function getCordovaNamespacePrefix(doc){
- var rootAtribs = Object.getOwnPropertyNames(doc.getroot().attrib);
- var prefix = 'cdv';
- for (var j = 0; j < rootAtribs.length; j++ ) {
- if(rootAtribs[j].indexOf('xmlns:') === 0 &&
- doc.getroot().attrib[rootAtribs[j]] === 'http://cordova.apache.org/ns/1.0'){
- var strings = rootAtribs[j].split(':');
- prefix = strings[1];
- break;
- }
- }
- return prefix;
-}
-
-/**
- * Finds the value of an element's attribute
- * @param {String} attributeName Name of the attribute to search for
- * @param {Array} elems An array of ElementTree nodes
- * @return {String}
- */
-function findElementAttributeValue(attributeName, elems) {
-
- elems = Array.isArray(elems) ? elems : [ elems ];
-
- var value = elems.filter(function (elem) {
- return elem.attrib.name.toLowerCase() === attributeName.toLowerCase();
- }).map(function (filteredElems) {
- return filteredElems.attrib.value;
- }).pop();
-
- return value ? value : '';
-}
-
-ConfigParser.prototype = {
- packageName: function(id) {
- return this.doc.getroot().attrib['id'];
- },
- setPackageName: function(id) {
- this.doc.getroot().attrib['id'] = id;
- },
- android_packageName: function() {
- return this.doc.getroot().attrib['android-packageName'];
- },
- android_activityName: function() {
- return this.doc.getroot().attrib['android-activityName'];
- },
- ios_CFBundleIdentifier: function() {
- return this.doc.getroot().attrib['ios-CFBundleIdentifier'];
- },
- name: function() {
- return getNodeTextSafe(this.doc.find('name'));
- },
- setName: function(name) {
- var el = findOrCreate(this.doc, 'name');
- el.text = name;
- },
- description: function() {
- return getNodeTextSafe(this.doc.find('description'));
- },
- setDescription: function(text) {
- var el = findOrCreate(this.doc, 'description');
- el.text = text;
- },
- version: function() {
- return this.doc.getroot().attrib['version'];
- },
- windows_packageVersion: function() {
- return this.doc.getroot().attrib('windows-packageVersion');
- },
- android_versionCode: function() {
- return this.doc.getroot().attrib['android-versionCode'];
- },
- ios_CFBundleVersion: function() {
- return this.doc.getroot().attrib['ios-CFBundleVersion'];
- },
- setVersion: function(value) {
- this.doc.getroot().attrib['version'] = value;
- },
- author: function() {
- return getNodeTextSafe(this.doc.find('author'));
- },
- getGlobalPreference: function (name) {
- return findElementAttributeValue(name, this.doc.findall('preference'));
- },
- setGlobalPreference: function (name, value) {
- var pref = this.doc.find('preference[@name="' + name + '"]');
- if (!pref) {
- pref = new et.Element('preference');
- pref.attrib.name = name;
- this.doc.getroot().append(pref);
- }
- pref.attrib.value = value;
- },
- getPlatformPreference: function (name, platform) {
- return findElementAttributeValue(name, this.doc.findall('platform[@name=\'' + platform + '\']/preference'));
- },
- getPreference: function(name, platform) {
-
- var platformPreference = '';
-
- if (platform) {
- platformPreference = this.getPlatformPreference(name, platform);
- }
-
- return platformPreference ? platformPreference : this.getGlobalPreference(name);
-
- },
- /**
- * Returns all resources for the platform specified.
- * @param {String} platform The platform.
- * @param {string} resourceName Type of static resources to return.
- * "icon" and "splash" currently supported.
- * @return {Array} Resources for the platform specified.
- */
- getStaticResources: function(platform, resourceName) {
- var ret = [],
- staticResources = [];
- if (platform) { // platform specific icons
- this.doc.findall('platform[@name=\'' + platform + '\']/' + resourceName).forEach(function(elt){
- elt.platform = platform; // mark as platform specific resource
- staticResources.push(elt);
- });
- }
- // root level resources
- staticResources = staticResources.concat(this.doc.findall(resourceName));
- // parse resource elements
- var that = this;
- staticResources.forEach(function (elt) {
- var res = {};
- res.src = elt.attrib.src;
- res.density = elt.attrib['density'] || elt.attrib[that.cdvNamespacePrefix+':density'] || elt.attrib['gap:density'];
- res.platform = elt.platform || null; // null means icon represents default icon (shared between platforms)
- res.width = +elt.attrib.width || undefined;
- res.height = +elt.attrib.height || undefined;
-
- // default icon
- if (!res.width && !res.height && !res.density) {
- ret.defaultResource = res;
- }
- ret.push(res);
- });
-
- /**
- * Returns resource with specified width and/or height.
- * @param {number} width Width of resource.
- * @param {number} height Height of resource.
- * @return {Resource} Resource object or null if not found.
- */
- ret.getBySize = function(width, height) {
- return ret.filter(function(res) {
- if (!res.width && !res.height) {
- return false;
- }
- return ((!res.width || (width == res.width)) &&
- (!res.height || (height == res.height)));
- })[0] || null;
- };
-
- /**
- * Returns resource with specified density.
- * @param {string} density Density of resource.
- * @return {Resource} Resource object or null if not found.
- */
- ret.getByDensity = function(density) {
- return ret.filter(function(res) {
- return res.density == density;
- })[0] || null;
- };
-
- /** Returns default icons */
- ret.getDefault = function() {
- return ret.defaultResource;
- };
-
- return ret;
- },
-
- /**
- * Returns all icons for specific platform.
- * @param {string} platform Platform name
- * @return {Resource[]} Array of icon objects.
- */
- getIcons: function(platform) {
- return this.getStaticResources(platform, 'icon');
- },
-
- /**
- * Returns all splash images for specific platform.
- * @param {string} platform Platform name
- * @return {Resource[]} Array of Splash objects.
- */
- getSplashScreens: function(platform) {
- return this.getStaticResources(platform, 'splash');
- },
-
- /**
- * Returns all hook scripts for the hook type specified.
- * @param {String} hook The hook type.
- * @param {Array} platforms Platforms to look for scripts into (root scripts will be included as well).
- * @return {Array} Script elements.
- */
- getHookScripts: function(hook, platforms) {
- var self = this;
- var scriptElements = self.doc.findall('./hook');
-
- if(platforms) {
- platforms.forEach(function (platform) {
- scriptElements = scriptElements.concat(self.doc.findall('./platform[@name="' + platform + '"]/hook'));
- });
- }
-
- function filterScriptByHookType(el) {
- return el.attrib.src && el.attrib.type && el.attrib.type.toLowerCase() === hook;
- }
-
- return scriptElements.filter(filterScriptByHookType);
- },
- /**
- * Returns a list of plugin (IDs).
- *
- * This function also returns any plugin's that
- * were defined using the legacy <feature> tags.
- * @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;
- },
- getPlugins: function () {
- return this.getPluginIdList().map(function (pluginId) {
- return this.getPlugin(pluginId);
- }, this);
- },
- /**
- * Adds a plugin element. Does not check for duplicates.
- * @name addPlugin
- * @function
- * @param {object} attributes name and spec are supported
- * @param {Array|object} variables name, value or arbitary object
- */
- addPlugin: function (attributes, variables) {
- if (!attributes && !attributes.name) return;
- var el = new et.Element('plugin');
- el.attrib.name = attributes.name;
- if (attributes.spec) {
- el.attrib.spec = attributes.spec;
- }
-
- // support arbitrary object as variables source
- if (variables && typeof variables === 'object' && !Array.isArray(variables)) {
- variables = Object.keys(variables)
- .map(function (variableName) {
- return {name: variableName, value: variables[variableName]};
- });
- }
-
- if (variables) {
- variables.forEach(function (variable) {
- el.append(new et.Element('variable', { name: variable.name, value: variable.value }));
- });
- }
- this.doc.getroot().append(el);
- },
- /**
- * Retrives the plugin with the given id or null if not found.
- *
- * This function also returns any plugin's that
- * were defined using the legacy <feature> tags.
- * @name getPlugin
- * @function
- * @param {String} id
- * @returns {object} plugin including any variables
- */
- getPlugin: function(id){
- if(!id){
- return undefined;
- }
- var pluginElement = this.doc.find('./plugin/[@name="' + id + '"]');
- if (null === pluginElement) {
- var legacyFeature = this.doc.find('./feature/param[@name="id"][@value="' + id + '"]/..');
- if(legacyFeature){
- events.emit('log', 'Found deprecated feature entry for ' + id +' in config.xml.');
- return featureToPlugin(legacyFeature);
- }
- return undefined;
- }
- var plugin = {};
-
- plugin.name = pluginElement.attrib.name;
- plugin.spec = pluginElement.attrib.spec || pluginElement.attrib.src || pluginElement.attrib.version;
- 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;
- }
- });
- return plugin;
- },
- /**
- * Remove the plugin entry with give name (id).
- *
- * This function also operates on any plugin's that
- * were defined using the legacy <feature> tags.
- * @name removePlugin
- * @function
- * @param id name of the plugin
- */
- removePlugin: function(id){
- if(id){
- var plugins = this.doc.findall('./plugin/[@name="' + id + '"]')
- .concat(this.doc.findall('./feature/param[@name="id"][@value="' + id + '"]/..'));
- var children = this.doc.getroot().getchildren();
- plugins.forEach(function (plugin) {
- var idx = children.indexOf(plugin);
- if (idx > -1) {
- children.splice(idx, 1);
- }
- });
- }
- },
-
- // Add any element to the root
- addElement: function(name, attributes) {
- var el = et.Element(name);
- for (var a in attributes) {
- el.attrib[a] = attributes[a];
- }
- this.doc.getroot().append(el);
- },
-
- /**
- * Adds an engine. Does not check for duplicates.
- * @param {String} name the engine name
- * @param {String} spec engine source location or version (optional)
- */
- addEngine: function(name, spec){
- if(!name) return;
- var el = et.Element('engine');
- el.attrib.name = name;
- if(spec){
- el.attrib.spec = spec;
- }
- this.doc.getroot().append(el);
- },
- /**
- * Removes all the engines with given name
- * @param {String} name the engine name.
- */
- removeEngine: function(name){
- var engines = this.doc.findall('./engine/[@name="' +name+'"]');
- for(var i=0; i < engines.length; i++){
- var children = this.doc.getroot().getchildren();
- var idx = children.indexOf(engines[i]);
- if(idx > -1){
- children.splice(idx,1);
- }
- }
- },
- getEngines: function(){
- var engines = this.doc.findall('./engine');
- return engines.map(function(engine){
- var spec = engine.attrib.spec || engine.attrib.version;
- return {
- 'name': engine.attrib.name,
- 'spec': spec ? spec : null
- };
- });
- },
- /* Get all the access tags */
- getAccesses: function() {
- var accesses = this.doc.findall('./access');
- return accesses.map(function(access){
- var minimum_tls_version = access.attrib['minimum-tls-version']; /* String */
- var requires_forward_secrecy = access.attrib['requires-forward-secrecy']; /* Boolean */
- return {
- 'origin': access.attrib.origin,
- 'minimum_tls_version': minimum_tls_version,
- 'requires_forward_secrecy' : requires_forward_secrecy
- };
- });
- },
- /* Get all the allow-navigation tags */
- getAllowNavigations: function() {
- var allow_navigations = this.doc.findall('./allow-navigation');
- return allow_navigations.map(function(allow_navigation){
- var minimum_tls_version = allow_navigation.attrib['minimum-tls-version']; /* String */
- var requires_forward_secrecy = allow_navigation.attrib['requires-forward-secrecy']; /* Boolean */
- return {
- 'href': allow_navigation.attrib.href,
- 'minimum_tls_version': minimum_tls_version,
- 'requires_forward_secrecy' : requires_forward_secrecy
- };
- });
- },
- write:function() {
- fs.writeFileSync(this.path, this.doc.write({indent: 4}), 'utf-8');
- }
-};
-
-function featureToPlugin(featureElement) {
- var plugin = {};
- plugin.variables = [];
- var pluginVersion,
- pluginSrc;
-
- var nodes = featureElement.findall('param');
- nodes.forEach(function (element) {
- var n = element.attrib.name;
- var v = element.attrib.value;
- if (n === 'id') {
- plugin.name = v;
- } else if (n === 'version') {
- pluginVersion = v;
- } else if (n === 'url' || n === 'installPath') {
- pluginSrc = v;
- } else {
- plugin.variables[n] = v;
- }
- });
-
- var spec = pluginSrc || pluginVersion;
- if (spec) {
- plugin.spec = spec;
- }
-
- return plugin;
-}
-module.exports = ConfigParser;
+/**
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+*/
+
+/* jshint sub:true */
+
+var et = require('elementtree'),
+ xml= require('../util/xml-helpers'),
+ CordovaError = require('../CordovaError/CordovaError'),
+ fs = require('fs'),
+ events = require('../events');
+
+
+/** Wraps a config.xml file */
+function ConfigParser(path) {
+ this.path = path;
+ try {
+ this.doc = xml.parseElementtreeSync(path);
+ this.cdvNamespacePrefix = getCordovaNamespacePrefix(this.doc);
+ et.register_namespace(this.cdvNamespacePrefix, 'http://cordova.apache.org/ns/1.0');
+ } catch (e) {
+ console.error('Parsing '+path+' failed');
+ throw e;
+ }
+ var r = this.doc.getroot();
+ if (r.tag !== 'widget') {
+ throw new CordovaError(path + ' has incorrect root node name (expected "widget", was "' + r.tag + '")');
+ }
+}
+
+function getNodeTextSafe(el) {
+ return el && el.text && el.text.trim();
+}
+
+function findOrCreate(doc, name) {
+ var ret = doc.find(name);
+ if (!ret) {
+ ret = new et.Element(name);
+ doc.getroot().append(ret);
+ }
+ return ret;
+}
+
+function getCordovaNamespacePrefix(doc){
+ var rootAtribs = Object.getOwnPropertyNames(doc.getroot().attrib);
+ var prefix = 'cdv';
+ for (var j = 0; j < rootAtribs.length; j++ ) {
+ if(rootAtribs[j].indexOf('xmlns:') === 0 &&
+ doc.getroot().attrib[rootAtribs[j]] === 'http://cordova.apache.org/ns/1.0'){
+ var strings = rootAtribs[j].split(':');
+ prefix = strings[1];
+ break;
+ }
+ }
+ return prefix;
+}
+
+/**
+ * Finds the value of an element's attribute
+ * @param {String} attributeName Name of the attribute to search for
+ * @param {Array} elems An array of ElementTree nodes
+ * @return {String}
+ */
+function findElementAttributeValue(attributeName, elems) {
+
+ elems = Array.isArray(elems) ? elems : [ elems ];
+
+ var value = elems.filter(function (elem) {
+ return elem.attrib.name.toLowerCase() === attributeName.toLowerCase();
+ }).map(function (filteredElems) {
+ return filteredElems.attrib.value;
+ }).pop();
+
+ return value ? value : '';
+}
+
+ConfigParser.prototype = {
+ packageName: function(id) {
+ return this.doc.getroot().attrib['id'];
+ },
+ setPackageName: function(id) {
+ this.doc.getroot().attrib['id'] = id;
+ },
+ android_packageName: function() {
+ return this.doc.getroot().attrib['android-packageName'];
+ },
+ android_activityName: function() {
+ return this.doc.getroot().attrib['android-activityName'];
+ },
+ ios_CFBundleIdentifier: function() {
+ return this.doc.getroot().attrib['ios-CFBundleIdentifier'];
+ },
+ name: function() {
+ return getNodeTextSafe(this.doc.find('name'));
+ },
+ setName: function(name) {
+ var el = findOrCreate(this.doc, 'name');
+ el.text = name;
+ },
+ description: function() {
+ return getNodeTextSafe(this.doc.find('description'));
+ },
+ setDescription: function(text) {
+ var el = findOrCreate(this.doc, 'description');
+ el.text = text;
+ },
+ version: function() {
+ return this.doc.getroot().attrib['version'];
+ },
+ windows_packageVersion: function() {
+ return this.doc.getroot().attrib('windows-packageVersion');
+ },
+ android_versionCode: function() {
+ return this.doc.getroot().attrib['android-versionCode'];
+ },
+ ios_CFBundleVersion: function() {
+ return this.doc.getroot().attrib['ios-CFBundleVersion'];
+ },
+ setVersion: function(value) {
+ this.doc.getroot().attrib['version'] = value;
+ },
+ author: function() {
+ return getNodeTextSafe(this.doc.find('author'));
+ },
+ getGlobalPreference: function (name) {
+ return findElementAttributeValue(name, this.doc.findall('preference'));
+ },
+ setGlobalPreference: function (name, value) {
+ var pref = this.doc.find('preference[@name="' + name + '"]');
+ if (!pref) {
+ pref = new et.Element('preference');
+ pref.attrib.name = name;
+ this.doc.getroot().append(pref);
+ }
+ pref.attrib.value = value;
+ },
+ getPlatformPreference: function (name, platform) {
+ return findElementAttributeValue(name, this.doc.findall('platform[@name=\'' + platform + '\']/preference'));
+ },
+ getPreference: function(name, platform) {
+
+ var platformPreference = '';
+
+ if (platform) {
+ platformPreference = this.getPlatformPreference(name, platform);
+ }
+
+ return platformPreference ? platformPreference : this.getGlobalPreference(name);
+
+ },
+ /**
+ * Returns all resources for the platform specified.
+ * @param {String} platform The platform.
+ * @param {string} resourceName Type of static resources to return.
+ * "icon" and "splash" currently supported.
+ * @return {Array} Resources for the platform specified.
+ */
+ getStaticResources: function(platform, resourceName) {
+ var ret = [],
+ staticResources = [];
+ if (platform) { // platform specific icons
+ this.doc.findall('platform[@name=\'' + platform + '\']/' + resourceName).forEach(function(elt){
+ elt.platform = platform; // mark as platform specific resource
+ staticResources.push(elt);
+ });
+ }
+ // root level resources
+ staticResources = staticResources.concat(this.doc.findall(resourceName));
+ // parse resource elements
+ var that = this;
+ staticResources.forEach(function (elt) {
+ var res = {};
+ res.src = elt.attrib.src;
+ res.density = elt.attrib['density'] || elt.attrib[that.cdvNamespacePrefix+':density'] || elt.attrib['gap:density'];
+ res.platform = elt.platform || null; // null means icon represents default icon (shared between platforms)
+ res.width = +elt.attrib.width || undefined;
+ res.height = +elt.attrib.height || undefined;
+
+ // default icon
+ if (!res.width && !res.height && !res.density) {
+ ret.defaultResource = res;
+ }
+ ret.push(res);
+ });
+
+ /**
+ * Returns resource with specified width and/or height.
+ * @param {number} width Width of resource.
+ * @param {number} height Height of resource.
+ * @return {Resource} Resource object or null if not found.
+ */
+ ret.getBySize = function(width, height) {
+ return ret.filter(function(res) {
+ if (!res.width && !res.height) {
+ return false;
+ }
+ return ((!res.width || (width == res.width)) &&
+ (!res.height || (height == res.height)));
+ })[0] || null;
+ };
+
+ /**
+ * Returns resource with specified density.
+ * @param {string} density Density of resource.
+ * @return {Resource} Resource object or null if not found.
+ */
+ ret.getByDensity = function(density) {
+ return ret.filter(function(res) {
+ return res.density == density;
+ })[0] || null;
+ };
+
+ /** Returns default icons */
+ ret.getDefault = function() {
+ return ret.defaultResource;
+ };
+
+ return ret;
+ },
+
+ /**
+ * Returns all icons for specific platform.
+ * @param {string} platform Platform name
+ * @return {Resource[]} Array of icon objects.
+ */
+ getIcons: function(platform) {
+ return this.getStaticResources(platform, 'icon');
+ },
+
+ /**
+ * Returns all splash images for specific platform.
+ * @param {string} platform Platform name
+ * @return {Resource[]} Array of Splash objects.
+ */
+ getSplashScreens: function(platform) {
+ return this.getStaticResources(platform, 'splash');
+ },
+
+ /**
+ * Returns all hook scripts for the hook type specified.
+ * @param {String} hook The hook type.
+ * @param {Array} platforms Platforms to look for scripts into (root scripts will be included as well).
+ * @return {Array} Script elements.
+ */
+ getHookScripts: function(hook, platforms) {
+ var self = this;
+ var scriptElements = self.doc.findall('./hook');
+
+ if(platforms) {
+ platforms.forEach(function (platform) {
+ scriptElements = scriptElements.concat(self.doc.findall('./platform[@name="' + platform + '"]/hook'));
+ });
+ }
+
+ function filterScriptByHookType(el) {
+ return el.attrib.src && el.attrib.type && el.attrib.type.toLowerCase() === hook;
+ }
+
+ return scriptElements.filter(filterScriptByHookType);
+ },
+ /**
+ * Returns a list of plugin (IDs).
+ *
+ * This function also returns any plugin's that
+ * were defined using the legacy <feature> tags.
+ * @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;
+ },
+ getPlugins: function () {
+ return this.getPluginIdList().map(function (pluginId) {
+ return this.getPlugin(pluginId);
+ }, this);
+ },
+ /**
+ * Adds a plugin element. Does not check for duplicates.
+ * @name addPlugin
+ * @function
+ * @param {object} attributes name and spec are supported
+ * @param {Array|object} variables name, value or arbitary object
+ */
+ addPlugin: function (attributes, variables) {
+ if (!attributes && !attributes.name) return;
+ var el = new et.Element('plugin');
+ el.attrib.name = attributes.name;
+ if (attributes.spec) {
+ el.attrib.spec = attributes.spec;
+ }
+
+ // support arbitrary object as variables source
+ if (variables && typeof variables === 'object' && !Array.isArray(variables)) {
+ variables = Object.keys(variables)
+ .map(function (variableName) {
+ return {name: variableName, value: variables[variableName]};
+ });
+ }
+
+ if (variables) {
+ variables.forEach(function (variable) {
+ el.append(new et.Element('variable', { name: variable.name, value: variable.value }));
+ });
+ }
+ this.doc.getroot().append(el);
+ },
+ /**
+ * Retrives the plugin with the given id or null if not found.
+ *
+ * This function also returns any plugin's that
+ * were defined using the legacy <feature> tags.
+ * @name getPlugin
+ * @function
+ * @param {String} id
+ * @returns {object} plugin including any variables
+ */
+ getPlugin: function(id){
+ if(!id){
+ return undefined;
+ }
+ var pluginElement = this.doc.find('./plugin/[@name="' + id + '"]');
+ if (null === pluginElement) {
+ var legacyFeature = this.doc.find('./feature/param[@name="id"][@value="' + id + '"]/..');
+ if(legacyFeature){
+ events.emit('log', 'Found deprecated feature entry for ' + id +' in config.xml.');
+ return featureToPlugin(legacyFeature);
+ }
+ return undefined;
+ }
+ var plugin = {};
+
+ plugin.name = pluginElement.attrib.name;
+ plugin.spec = pluginElement.attrib.spec || pluginElement.attrib.src || pluginElement.attrib.version;
+ 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;
+ }
+ });
+ return plugin;
+ },
+ /**
+ * Remove the plugin entry with give name (id).
+ *
+ * This function also operates on any plugin's that
+ * were defined using the legacy <feature> tags.
+ * @name removePlugin
+ * @function
+ * @param id name of the plugin
+ */
+ removePlugin: function(id){
+ if(id){
+ var plugins = this.doc.findall('./plugin/[@name="' + id + '"]')
+ .concat(this.doc.findall('./feature/param[@name="id"][@value="' + id + '"]/..'));
+ var children = this.doc.getroot().getchildren();
+ plugins.forEach(function (plugin) {
+ var idx = children.indexOf(plugin);
+ if (idx > -1) {
+ children.splice(idx, 1);
+ }
+ });
+ }
+ },
+
+ // Add any element to the root
+ addElement: function(name, attributes) {
+ var el = et.Element(name);
+ for (var a in attributes) {
+ el.attrib[a] = attributes[a];
+ }
+ this.doc.getroot().append(el);
+ },
+
+ /**
+ * Adds an engine. Does not check for duplicates.
+ * @param {String} name the engine name
+ * @param {String} spec engine source location or version (optional)
+ */
+ addEngine: function(name, spec){
+ if(!name) return;
+ var el = et.Element('engine');
+ el.attrib.name = name;
+ if(spec){
+ el.attrib.spec = spec;
+ }
+ this.doc.getroot().append(el);
+ },
+ /**
+ * Removes all the engines with given name
+ * @param {String} name the engine name.
+ */
+ removeEngine: function(name){
+ var engines = this.doc.findall('./engine/[@name="' +name+'"]');
+ for(var i=0; i < engines.length; i++){
+ var children = this.doc.getroot().getchildren();
+ var idx = children.indexOf(engines[i]);
+ if(idx > -1){
+ children.splice(idx,1);
+ }
+ }
+ },
+ getEngines: function(){
+ var engines = this.doc.findall('./engine');
+ return engines.map(function(engine){
+ var spec = engine.attrib.spec || engine.attrib.version;
+ return {
+ 'name': engine.attrib.name,
+ 'spec': spec ? spec : null
+ };
+ });
+ },
+ /* Get all the access tags */
+ getAccesses: function() {
+ var accesses = this.doc.findall('./access');
+ return accesses.map(function(access){
+ var minimum_tls_version = access.attrib['minimum-tls-version']; /* String */
+ var requires_forward_secrecy = access.attrib['requires-forward-secrecy']; /* Boolean */
+ return {
+ 'origin': access.attrib.origin,
+ 'minimum_tls_version': minimum_tls_version,
+ 'requires_forward_secrecy' : requires_forward_secrecy
+ };
+ });
+ },
+ /* Get all the allow-navigation tags */
+ getAllowNavigations: function() {
+ var allow_navigations = this.doc.findall('./allow-navigation');
+ return allow_navigations.map(function(allow_navigation){
+ var minimum_tls_version = allow_navigation.attrib['minimum-tls-version']; /* String */
+ var requires_forward_secrecy = allow_navigation.attrib['requires-forward-secrecy']; /* Boolean */
+ return {
+ 'href': allow_navigation.attrib.href,
+ 'minimum_tls_version': minimum_tls_version,
+ 'requires_forward_secrecy' : requires_forward_secrecy
+ };
+ });
+ },
+ write:function() {
+ fs.writeFileSync(this.path, this.doc.write({indent: 4}), 'utf-8');
+ }
+};
+
+function featureToPlugin(featureElement) {
+ var plugin = {};
+ plugin.variables = [];
+ var pluginVersion,
+ pluginSrc;
+
+ var nodes = featureElement.findall('param');
+ nodes.forEach(function (element) {
+ var n = element.attrib.name;
+ var v = element.attrib.value;
+ if (n === 'id') {
+ plugin.name = v;
+ } else if (n === 'version') {
+ pluginVersion = v;
+ } else if (n === 'url' || n === 'installPath') {
+ pluginSrc = v;
+ } else {
+ plugin.variables[n] = v;
+ }
+ });
+
+ var spec = pluginSrc || pluginVersion;
+ if (spec) {
+ plugin.spec = spec;
+ }
+
+ return plugin;
+}
+module.exports = ConfigParser;
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/4f7721b4/node_modules/cordova-common/src/ConfigParser/README.md
----------------------------------------------------------------------
diff --git a/node_modules/cordova-common/src/ConfigParser/README.md b/node_modules/cordova-common/src/ConfigParser/README.md
index eed1cd9..e5cd1bf 100644
--- a/node_modules/cordova-common/src/ConfigParser/README.md
+++ b/node_modules/cordova-common/src/ConfigParser/README.md
@@ -1,86 +1,86 @@
-<!--
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you 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.
-#
--->
-
-# Cordova-Lib
-
-## ConfigParser
-
-wraps a valid cordova config.xml file
-
-### Usage
-
-### Include the ConfigParser module in a projet
-
- var ConfigParser = require('cordova-lib').configparser;
-
-### Create a new ConfigParser
-
- var config = new ConfigParser('path/to/config/xml/');
-
-### Utility Functions
-
-#### packageName(id)
-returns document root 'id' attribute value
-#### Usage
-
- config.packageName: function(id)
-
-/*
- * sets document root element 'id' attribute to @id
- *
- * @id - new id value
- *
- */
-#### setPackageName(id)
-set document root 'id' attribute to
- function(id) {
- this.doc.getroot().attrib['id'] = id;
- },
-
-###
- name: function() {
- return getNodeTextSafe(this.doc.find('name'));
- },
- setName: function(name) {
- var el = findOrCreate(this.doc, 'name');
- el.text = name;
- },
-
-### read the description element
-
- config.description()
-
- var text = "New and improved description of App"
- setDescription(text)
-
-### version management
- version()
- android_versionCode()
- ios_CFBundleVersion()
- setVersion()
-
-### read author element
-
- config.author();
-
-### read preference
-
- config.getPreference(name);
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+-->
+
+# Cordova-Lib
+
+## ConfigParser
+
+wraps a valid cordova config.xml file
+
+### Usage
+
+### Include the ConfigParser module in a projet
+
+ var ConfigParser = require('cordova-lib').configparser;
+
+### Create a new ConfigParser
+
+ var config = new ConfigParser('path/to/config/xml/');
+
+### Utility Functions
+
+#### packageName(id)
+returns document root 'id' attribute value
+#### Usage
+
+ config.packageName: function(id)
+
+/*
+ * sets document root element 'id' attribute to @id
+ *
+ * @id - new id value
+ *
+ */
+#### setPackageName(id)
+set document root 'id' attribute to
+ function(id) {
+ this.doc.getroot().attrib['id'] = id;
+ },
+
+###
+ name: function() {
+ return getNodeTextSafe(this.doc.find('name'));
+ },
+ setName: function(name) {
+ var el = findOrCreate(this.doc, 'name');
+ el.text = name;
+ },
+
+### read the description element
+
+ config.description()
+
+ var text = "New and improved description of App"
+ setDescription(text)
+
+### version management
+ version()
+ android_versionCode()
+ ios_CFBundleVersion()
+ setVersion()
+
+### read author element
+
+ config.author();
+
+### read preference
+
+ config.getPreference(name);
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/4f7721b4/node_modules/cordova-common/src/CordovaError/CordovaError.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-common/src/CordovaError/CordovaError.js b/node_modules/cordova-common/src/CordovaError/CordovaError.js
index 0b14d14..7262448 100644
--- a/node_modules/cordova-common/src/CordovaError/CordovaError.js
+++ b/node_modules/cordova-common/src/CordovaError/CordovaError.js
@@ -1,91 +1,91 @@
-/**
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you 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.
-*/
-
-/* jshint proto:true */
-
-var EOL = require('os').EOL;
-
-/**
- * A derived exception class. See usage example in cli.js
- * Based on:
- * stackoverflow.com/questions/1382107/whats-a-good-way-to-extend-error-in-javascript/8460753#8460753
- * @param {String} message Error message
- * @param {Number} [code=0] Error code
- * @param {CordovaExternalToolErrorContext} [context] External tool error context object
- * @constructor
- */
-function CordovaError(message, code, context) {
- Error.captureStackTrace(this, this.constructor);
- this.name = this.constructor.name;
- this.message = message;
- this.code = code || CordovaError.UNKNOWN_ERROR;
- this.context = context;
-}
-CordovaError.prototype.__proto__ = Error.prototype;
-
-// TODO: Extend error codes according the projects specifics
-CordovaError.UNKNOWN_ERROR = 0;
-CordovaError.EXTERNAL_TOOL_ERROR = 1;
-
-/**
- * Translates instance's error code number into error code name, e.g. 0 -> UNKNOWN_ERROR
- * @returns {string} Error code string name
- */
-CordovaError.prototype.getErrorCodeName = function() {
- for(var key in CordovaError) {
- if(CordovaError.hasOwnProperty(key)) {
- if(CordovaError[key] === this.code) {
- return key;
- }
- }
- }
-};
-
-/**
- * Converts CordovaError instance to string representation
- * @param {Boolean} [isVerbose] Set up verbose mode. Used to provide more
- * details including information about error code name and context
- * @return {String} Stringified error representation
- */
-CordovaError.prototype.toString = function(isVerbose) {
- var message = '', codePrefix = '';
-
- if(this.code !== CordovaError.UNKNOWN_ERROR) {
- codePrefix = 'code: ' + this.code + (isVerbose ? (' (' + this.getErrorCodeName() + ')') : '') + ' ';
- }
-
- if(this.code === CordovaError.EXTERNAL_TOOL_ERROR) {
- if(typeof this.context !== 'undefined') {
- if(isVerbose) {
- message = codePrefix + EOL + this.context.toString(isVerbose) + '\n failed with an error: ' +
- this.message + EOL + 'Stack trace: ' + this.stack;
- } else {
- message = codePrefix + '\'' + this.context.toString(isVerbose) + '\' ' + this.message;
- }
- } else {
- message = 'External tool failed with an error: ' + this.message;
- }
- } else {
- message = isVerbose ? codePrefix + this.stack : codePrefix + this.message;
- }
-
- return message;
-};
-
-module.exports = CordovaError;
+/**
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+*/
+
+/* jshint proto:true */
+
+var EOL = require('os').EOL;
+
+/**
+ * A derived exception class. See usage example in cli.js
+ * Based on:
+ * stackoverflow.com/questions/1382107/whats-a-good-way-to-extend-error-in-javascript/8460753#8460753
+ * @param {String} message Error message
+ * @param {Number} [code=0] Error code
+ * @param {CordovaExternalToolErrorContext} [context] External tool error context object
+ * @constructor
+ */
+function CordovaError(message, code, context) {
+ Error.captureStackTrace(this, this.constructor);
+ this.name = this.constructor.name;
+ this.message = message;
+ this.code = code || CordovaError.UNKNOWN_ERROR;
+ this.context = context;
+}
+CordovaError.prototype.__proto__ = Error.prototype;
+
+// TODO: Extend error codes according the projects specifics
+CordovaError.UNKNOWN_ERROR = 0;
+CordovaError.EXTERNAL_TOOL_ERROR = 1;
+
+/**
+ * Translates instance's error code number into error code name, e.g. 0 -> UNKNOWN_ERROR
+ * @returns {string} Error code string name
+ */
+CordovaError.prototype.getErrorCodeName = function() {
+ for(var key in CordovaError) {
+ if(CordovaError.hasOwnProperty(key)) {
+ if(CordovaError[key] === this.code) {
+ return key;
+ }
+ }
+ }
+};
+
+/**
+ * Converts CordovaError instance to string representation
+ * @param {Boolean} [isVerbose] Set up verbose mode. Used to provide more
+ * details including information about error code name and context
+ * @return {String} Stringified error representation
+ */
+CordovaError.prototype.toString = function(isVerbose) {
+ var message = '', codePrefix = '';
+
+ if(this.code !== CordovaError.UNKNOWN_ERROR) {
+ codePrefix = 'code: ' + this.code + (isVerbose ? (' (' + this.getErrorCodeName() + ')') : '') + ' ';
+ }
+
+ if(this.code === CordovaError.EXTERNAL_TOOL_ERROR) {
+ if(typeof this.context !== 'undefined') {
+ if(isVerbose) {
+ message = codePrefix + EOL + this.context.toString(isVerbose) + '\n failed with an error: ' +
+ this.message + EOL + 'Stack trace: ' + this.stack;
+ } else {
+ message = codePrefix + '\'' + this.context.toString(isVerbose) + '\' ' + this.message;
+ }
+ } else {
+ message = 'External tool failed with an error: ' + this.message;
+ }
+ } else {
+ message = isVerbose ? codePrefix + this.stack : codePrefix + this.message;
+ }
+
+ return message;
+};
+
+module.exports = CordovaError;
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/4f7721b4/node_modules/cordova-common/src/CordovaError/CordovaExternalToolErrorContext.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-common/src/CordovaError/CordovaExternalToolErrorContext.js b/node_modules/cordova-common/src/CordovaError/CordovaExternalToolErrorContext.js
index 8dda16f..ca9a4aa 100644
--- a/node_modules/cordova-common/src/CordovaError/CordovaExternalToolErrorContext.js
+++ b/node_modules/cordova-common/src/CordovaError/CordovaExternalToolErrorContext.js
@@ -1,48 +1,48 @@
-/**
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you 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.
- */
-
-/* jshint proto:true */
-
-var path = require('path');
-
-/**
- * @param {String} cmd Command full path
- * @param {String[]} args Command args
- * @param {String} [cwd] Command working directory
- * @constructor
- */
-function CordovaExternalToolErrorContext(cmd, args, cwd) {
- this.cmd = cmd;
- // Helper field for readability
- this.cmdShortName = path.basename(cmd);
- this.args = args;
- this.cwd = cwd;
-}
-
-CordovaExternalToolErrorContext.prototype.toString = function(isVerbose) {
- if(isVerbose) {
- return 'External tool \'' + this.cmdShortName + '\'' +
- '\nCommand full path: ' + this.cmd + '\nCommand args: ' + this.args +
- (typeof this.cwd !== 'undefined' ? '\nCommand cwd: ' + this.cwd : '');
- }
-
- return this.cmdShortName;
-};
-
-module.exports = CordovaExternalToolErrorContext;
+/**
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+ */
+
+/* jshint proto:true */
+
+var path = require('path');
+
+/**
+ * @param {String} cmd Command full path
+ * @param {String[]} args Command args
+ * @param {String} [cwd] Command working directory
+ * @constructor
+ */
+function CordovaExternalToolErrorContext(cmd, args, cwd) {
+ this.cmd = cmd;
+ // Helper field for readability
+ this.cmdShortName = path.basename(cmd);
+ this.args = args;
+ this.cwd = cwd;
+}
+
+CordovaExternalToolErrorContext.prototype.toString = function(isVerbose) {
+ if(isVerbose) {
+ return 'External tool \'' + this.cmdShortName + '\'' +
+ '\nCommand full path: ' + this.cmd + '\nCommand args: ' + this.args +
+ (typeof this.cwd !== 'undefined' ? '\nCommand cwd: ' + this.cwd : '');
+ }
+
+ return this.cmdShortName;
+};
+
+module.exports = CordovaExternalToolErrorContext;
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/4f7721b4/node_modules/cordova-common/src/PlatformJson.js
----------------------------------------------------------------------
diff --git a/node_modules/cordova-common/src/PlatformJson.js b/node_modules/cordova-common/src/PlatformJson.js
index 68ed7c3..793e976 100644
--- a/node_modules/cordova-common/src/PlatformJson.js
+++ b/node_modules/cordova-common/src/PlatformJson.js
@@ -1,155 +1,155 @@
-/*
- * 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.
- *
-*/
-/* jshint sub:true */
-
-var fs = require('fs');
-var path = require('path');
-var shelljs = require('shelljs');
-var mungeutil = require('./ConfigChanges/munge-util');
-var pluginMappernto = require('cordova-registry-mapper').newToOld;
-var pluginMapperotn = require('cordova-registry-mapper').oldToNew;
-
-function PlatformJson(filePath, platform, root) {
- this.filePath = filePath;
- this.platform = platform;
- this.root = fix_munge(root || {});
-}
-
-PlatformJson.load = function(plugins_dir, platform) {
- var filePath = path.join(plugins_dir, platform + '.json');
- var root = null;
- if (fs.existsSync(filePath)) {
- root = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
- }
- return new PlatformJson(filePath, platform, root);
-};
-
-PlatformJson.prototype.save = function() {
- shelljs.mkdir('-p', path.dirname(this.filePath));
- fs.writeFileSync(this.filePath, JSON.stringify(this.root, null, 4), 'utf-8');
-};
-
-/**
- * Indicates whether the specified plugin is installed as a top-level (not as
- * dependency to others)
- * @method function
- * @param {String} pluginId A plugin id to check for.
- * @return {Boolean} true if plugin installed as top-level, otherwise false.
- */
-PlatformJson.prototype.isPluginTopLevel = function(pluginId) {
- var installedPlugins = this.root.installed_plugins;
- return installedPlugins[pluginId] ||
- installedPlugins[pluginMappernto[pluginId]] ||
- installedPlugins[pluginMapperotn[pluginId]];
-};
-
-/**
- * Indicates whether the specified plugin is installed as a dependency to other
- * plugin.
- * @method function
- * @param {String} pluginId A plugin id to check for.
- * @return {Boolean} true if plugin installed as a dependency, otherwise false.
- */
-PlatformJson.prototype.isPluginDependent = function(pluginId) {
- var dependentPlugins = this.root.dependent_plugins;
- return dependentPlugins[pluginId] ||
- dependentPlugins[pluginMappernto[pluginId]] ||
- dependentPlugins[pluginMapperotn[pluginId]];
-};
-
-/**
- * Indicates whether plugin is installed either as top-level or as dependency.
- * @method function
- * @param {String} pluginId A plugin id to check for.
- * @return {Boolean} true if plugin installed, otherwise false.
- */
-PlatformJson.prototype.isPluginInstalled = function(pluginId) {
- return this.isPluginTopLevel(pluginId) ||
- this.isPluginDependent(pluginId);
-};
-
-PlatformJson.prototype.addPlugin = function(pluginId, variables, isTopLevel) {
- var pluginsList = isTopLevel ?
- this.root.installed_plugins :
- this.root.dependent_plugins;
-
- pluginsList[pluginId] = variables;
-
- return this;
-};
-
-PlatformJson.prototype.removePlugin = function(pluginId, isTopLevel) {
- var pluginsList = isTopLevel ?
- this.root.installed_plugins :
- this.root.dependent_plugins;
-
- delete pluginsList[pluginId];
-
- return this;
-};
-
-PlatformJson.prototype.addInstalledPluginToPrepareQueue = function(pluginDirName, vars, is_top_level) {
- this.root.prepare_queue.installed.push({'plugin':pluginDirName, 'vars':vars, 'topLevel':is_top_level});
-};
-
-PlatformJson.prototype.addUninstalledPluginToPrepareQueue = function(pluginId, is_top_level) {
- this.root.prepare_queue.uninstalled.push({'plugin':pluginId, 'id':pluginId, 'topLevel':is_top_level});
-};
-
-/**
- * Moves plugin, specified by id to top-level plugins. If plugin is top-level
- * already, then does nothing.
- * @method function
- * @param {String} pluginId A plugin id to make top-level.
- * @return {PlatformJson} PlatformJson instance.
- */
-PlatformJson.prototype.makeTopLevel = function(pluginId) {
- var plugin = this.root.dependent_plugins[pluginId];
- if (plugin) {
- delete this.root.dependent_plugins[pluginId];
- this.root.installed_plugins[pluginId] = plugin;
- }
- return this;
-};
-
-// convert a munge from the old format ([file][parent][xml] = count) to the current one
-function fix_munge(root) {
- root.prepare_queue = root.prepare_queue || {installed:[], uninstalled:[]};
- root.config_munge = root.config_munge || {files: {}};
- root.installed_plugins = root.installed_plugins || {};
- root.dependent_plugins = root.dependent_plugins || {};
-
- var munge = root.config_munge;
- if (!munge.files) {
- var new_munge = { files: {} };
- for (var file in munge) {
- for (var selector in munge[file]) {
- for (var xml_child in munge[file][selector]) {
- var val = parseInt(munge[file][selector][xml_child]);
- for (var i = 0; i < val; i++) {
- mungeutil.deep_add(new_munge, [file, selector, { xml: xml_child, count: val }]);
- }
- }
- }
- }
- root.config_munge = new_munge;
- }
-
- return root;
-}
-
-module.exports = PlatformJson;
-
+/*
+ * 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.
+ *
+*/
+/* jshint sub:true */
+
+var fs = require('fs');
+var path = require('path');
+var shelljs = require('shelljs');
+var mungeutil = require('./ConfigChanges/munge-util');
+var pluginMappernto = require('cordova-registry-mapper').newToOld;
+var pluginMapperotn = require('cordova-registry-mapper').oldToNew;
+
+function PlatformJson(filePath, platform, root) {
+ this.filePath = filePath;
+ this.platform = platform;
+ this.root = fix_munge(root || {});
+}
+
+PlatformJson.load = function(plugins_dir, platform) {
+ var filePath = path.join(plugins_dir, platform + '.json');
+ var root = null;
+ if (fs.existsSync(filePath)) {
+ root = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
+ }
+ return new PlatformJson(filePath, platform, root);
+};
+
+PlatformJson.prototype.save = function() {
+ shelljs.mkdir('-p', path.dirname(this.filePath));
+ fs.writeFileSync(this.filePath, JSON.stringify(this.root, null, 4), 'utf-8');
+};
+
+/**
+ * Indicates whether the specified plugin is installed as a top-level (not as
+ * dependency to others)
+ * @method function
+ * @param {String} pluginId A plugin id to check for.
+ * @return {Boolean} true if plugin installed as top-level, otherwise false.
+ */
+PlatformJson.prototype.isPluginTopLevel = function(pluginId) {
+ var installedPlugins = this.root.installed_plugins;
+ return installedPlugins[pluginId] ||
+ installedPlugins[pluginMappernto[pluginId]] ||
+ installedPlugins[pluginMapperotn[pluginId]];
+};
+
+/**
+ * Indicates whether the specified plugin is installed as a dependency to other
+ * plugin.
+ * @method function
+ * @param {String} pluginId A plugin id to check for.
+ * @return {Boolean} true if plugin installed as a dependency, otherwise false.
+ */
+PlatformJson.prototype.isPluginDependent = function(pluginId) {
+ var dependentPlugins = this.root.dependent_plugins;
+ return dependentPlugins[pluginId] ||
+ dependentPlugins[pluginMappernto[pluginId]] ||
+ dependentPlugins[pluginMapperotn[pluginId]];
+};
+
+/**
+ * Indicates whether plugin is installed either as top-level or as dependency.
+ * @method function
+ * @param {String} pluginId A plugin id to check for.
+ * @return {Boolean} true if plugin installed, otherwise false.
+ */
+PlatformJson.prototype.isPluginInstalled = function(pluginId) {
+ return this.isPluginTopLevel(pluginId) ||
+ this.isPluginDependent(pluginId);
+};
+
+PlatformJson.prototype.addPlugin = function(pluginId, variables, isTopLevel) {
+ var pluginsList = isTopLevel ?
+ this.root.installed_plugins :
+ this.root.dependent_plugins;
+
+ pluginsList[pluginId] = variables;
+
+ return this;
+};
+
+PlatformJson.prototype.removePlugin = function(pluginId, isTopLevel) {
+ var pluginsList = isTopLevel ?
+ this.root.installed_plugins :
+ this.root.dependent_plugins;
+
+ delete pluginsList[pluginId];
+
+ return this;
+};
+
+PlatformJson.prototype.addInstalledPluginToPrepareQueue = function(pluginDirName, vars, is_top_level) {
+ this.root.prepare_queue.installed.push({'plugin':pluginDirName, 'vars':vars, 'topLevel':is_top_level});
+};
+
+PlatformJson.prototype.addUninstalledPluginToPrepareQueue = function(pluginId, is_top_level) {
+ this.root.prepare_queue.uninstalled.push({'plugin':pluginId, 'id':pluginId, 'topLevel':is_top_level});
+};
+
+/**
+ * Moves plugin, specified by id to top-level plugins. If plugin is top-level
+ * already, then does nothing.
+ * @method function
+ * @param {String} pluginId A plugin id to make top-level.
+ * @return {PlatformJson} PlatformJson instance.
+ */
+PlatformJson.prototype.makeTopLevel = function(pluginId) {
+ var plugin = this.root.dependent_plugins[pluginId];
+ if (plugin) {
+ delete this.root.dependent_plugins[pluginId];
+ this.root.installed_plugins[pluginId] = plugin;
+ }
+ return this;
+};
+
+// convert a munge from the old format ([file][parent][xml] = count) to the current one
+function fix_munge(root) {
+ root.prepare_queue = root.prepare_queue || {installed:[], uninstalled:[]};
+ root.config_munge = root.config_munge || {files: {}};
+ root.installed_plugins = root.installed_plugins || {};
+ root.dependent_plugins = root.dependent_plugins || {};
+
+ var munge = root.config_munge;
+ if (!munge.files) {
+ var new_munge = { files: {} };
+ for (var file in munge) {
+ for (var selector in munge[file]) {
+ for (var xml_child in munge[file][selector]) {
+ var val = parseInt(munge[file][selector][xml_child]);
+ for (var i = 0; i < val; i++) {
+ mungeutil.deep_add(new_munge, [file, selector, { xml: xml_child, count: val }]);
+ }
+ }
+ }
+ }
+ root.config_munge = new_munge;
+ }
+
+ return root;
+}
+
+module.exports = PlatformJson;
+
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org