You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by lo...@apache.org on 2014/06/06 22:25:43 UTC

[3/4] git commit: [CB-6879] removed ConfigParser implementation from cordova

[CB-6879] removed ConfigParser implementation from cordova


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/fdd23139
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/fdd23139
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/fdd23139

Branch: refs/heads/configparser_module
Commit: fdd231396b13f04078ff2bba66515eaa8bca1bdc
Parents: 350b23e
Author: Lorin Beer <lo...@gmail.com>
Authored: Fri Jun 6 11:32:57 2014 -0700
Committer: Lorin Beer <lo...@gmail.com>
Committed: Fri Jun 6 11:32:57 2014 -0700

----------------------------------------------------------------------
 cordova-lib/spec-cordova/ConfigParser.spec.js |  99 ------------
 cordova-lib/src/cordova/ConfigParser.js       | 179 ---------------------
 2 files changed, 278 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/fdd23139/cordova-lib/spec-cordova/ConfigParser.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/ConfigParser.spec.js b/cordova-lib/spec-cordova/ConfigParser.spec.js
deleted file mode 100644
index a1ba102..0000000
--- a/cordova-lib/spec-cordova/ConfigParser.spec.js
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
-    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.
-*/
-var path = require('path'),
-    fs = require('fs'),
-    ConfigParser = require('../src/cordova/ConfigParser'),
-    xml = path.join(__dirname, 'test-config.xml'),
-    xml_contents = fs.readFileSync(xml, 'utf-8');
-
-describe('config.xml parser', function () {
-    var readFile;
-    beforeEach(function() {
-        readFile = spyOn(fs, 'readFileSync').andReturn(xml_contents);
-    });
-
-    it('should create an instance based on an xml file', function() {
-        var cfg;
-        expect(function () {
-            cfg = new ConfigParser(xml);
-        }).not.toThrow();
-        expect(cfg).toBeDefined();
-        expect(cfg.doc).toBeDefined();
-    });
-
-    describe('methods', function() {
-        var cfg;
-        beforeEach(function() {
-            cfg = new ConfigParser(xml);
-        });
-
-        describe('package name / id', function() {
-            it('should get the (default) packagename', function() {
-                expect(cfg.packageName()).toEqual('io.cordova.hellocordova');
-            });
-            it('should allow setting the packagename', function() {
-                cfg.setPackageName('this.is.bat.country');
-                expect(cfg.packageName()).toEqual('this.is.bat.country');
-            });
-        });
-
-        describe('version', function() {
-            it('should get the version', function() {
-                expect(cfg.version()).toEqual('0.0.1');
-            });
-            it('should allow setting the version', function() {
-                cfg.setVersion('2.0.1');
-                expect(cfg.version()).toEqual('2.0.1');
-            });
-        });
-
-        describe('app name', function() {
-            it('should get the (default) app name', function() {
-                expect(cfg.name()).toEqual('Hello Cordova');
-            });
-            it('should allow setting the app name', function() {
-                cfg.setName('this.is.bat.country');
-                expect(cfg.name()).toEqual('this.is.bat.country');
-            });
-        });
-        describe('preference', function() {
-            it('should get value of existing preference', function() {
-                expect(cfg.getPreference('fullscreen')).toEqual('true');
-            });
-            it('should get undefined as non existing preference', function() {
-                expect(cfg.getPreference('zimzooo!')).toEqual(undefined);
-            });
-        });
-        describe('feature',function(){
-            it('should allow adding a new feature', function(){
-                cfg.addFeature('myfeature');
-                var features = cfg.doc.findall('feature');
-                expect(features[0].attrib.name).toEqual('myfeature');
-            });
-            it('should allow adding features with params', function(){
-                cfg.addFeature('afeature', JSON.parse('[{"name":"paraname", "value":"paravalue"}]'));
-                var features = cfg.doc.findall('feature');
-                expect(features[0].attrib.name).toEqual('afeature');
-                var params = features[0].findall('param');
-                expect(params[0].attrib.name).toEqual('paraname');
-                expect(params[0].attrib.value).toEqual('paravalue');
-            });
-        });
-    });
-});

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/fdd23139/cordova-lib/src/cordova/ConfigParser.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/ConfigParser.js b/cordova-lib/src/cordova/ConfigParser.js
deleted file mode 100644
index 2df38d3..0000000
--- a/cordova-lib/src/cordova/ConfigParser.js
+++ /dev/null
@@ -1,179 +0,0 @@
-/**
-    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.
-*/
-var et = require('elementtree'),
-    xml= require('../util/xml-helpers'),
-    CordovaError = require('../CordovaError'),
-    fs = require('fs');
-
-/** Wraps a config.xml file */
-function ConfigParser(path) {
-    this.path = path;
-    try {
-        this.doc = xml.parseElementtreeSync(path);
-    } 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(content);
-    }
-    return ret;
-}
-
-ConfigParser.prototype = {
-    packageName: function(id) {
-        return this.doc.getroot().attrib['id'];
-    },
-    setPackageName: 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;
-    },
-    description: function() {
-        return this.doc.find('description').text.trim();
-    },
-    setDescription: function(text) {
-        this.doc.find('description').text = text;
-        var el = findOrCreate(this.doc, 'description');
-    },
-    version: function() {
-        return this.doc.getroot().attrib['version'];
-    },
-    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'));
-    },
-    getPreference: function(name) {
-        var preferences = this.doc.findall('preference');
-        var ret = null;
-        preferences.forEach(function (preference) {
-            // Take the last one that matches.
-            if (preference.attrib.name.toLowerCase() === name.toLowerCase()) {
-                ret = preference.attrib.value;
-            }
-        });
-        return ret;
-    },
-    /**
-     * Returns all icons for the platform specified.
-     * @param  {String} platform The platform.
-     * @return {Array} Icons for the platform specified.
-     */
-    getIcons: function(platform) {
-        var ret = [];
-            iconElements = [];
-
-        if (platform) { // platform specific icons
-            this.doc.findall('platform[@name=\'' + platform + '\']/icon').forEach(function(elt){
-                elt.platform = platform; // mark as platform specific icon
-                iconElements.push(elt)
-            });
-        }
-        // root level icons
-        iconElements = iconElements.concat(this.doc.findall('icon'));
-        // parse icon elements
-        iconElements.forEach(function (elt) {
-            var icon = {};
-            icon.src = elt.attrib.src;
-            icon.density = elt.attrib['density'] || elt.attrib['cdv:density'] || elt.attrib['gap:density'];
-            icon.platform = elt.platform || null; // null means icon represents default icon (shared between platforms)
-            icon.width = elt.attrib.width;
-            icon.height = elt.attrib.height;
-            // If one of width or Height is undefined, assume they are equal.
-            icon.width = icon.width || icon.height;
-            icon.height = icon.height || icon.width;
-
-            // default icon
-            if (!icon.width && !icon.height && !icon.density) {
-                ret.defaultIcon = icon;
-            }
-            ret.push(icon);
-        });
-
-        /**
-         * Returns icon with specified width and height
-         * @param  {number} w  Width of icon
-         * @param  {number} h  Height of icon
-         * @return {Icon}      Icon object or null if not found
-         */
-        ret.getIconBySize = function(w, h){
-            // If only one of width and height is given
-            // then we assume that they are equal.
-            var width = w || h, height = h || w;
-            for (var idx in this) {
-                var icon = this[idx];
-                if (width == icon.width && height == icon.width) return icon;
-            }
-            return null;
-        };
-        /** Returns default icons */
-        ret.getDefault = function() {
-            return ret.defaultIcon;
-        }
-
-        return ret;
-    },
-    /**
-     *This does not check for duplicate feature entries
-     */
-    addFeature: function (name, params){
-      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);
-          });
-        }
-        this.doc.getroot().append(el);
-    },
-    write:function() {
-        fs.writeFileSync(this.path, this.doc.write({indent: 4}), 'utf-8');
-    }
-};
-
-module.exports = ConfigParser;