You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2013/05/01 01:15:18 UTC

[1/2] git commit: added more variable documentation to README. added support for platform-agnostic config changes using top-level element. add support for wildcard xpath selectors in xml helpers. added tests for prune/graftXML helper method

Updated Branches:
  refs/heads/master f1822e59e -> d597d3473


added more variable documentation to README. added support for platform-agnostic config changes using top-level <config-file> element. add support for wildcard xpath selectors in xml helpers. added tests for prune/graftXML helper methods. factored out common parent resolution from xml helper methods. factored out common post-install prepare steps from install module.


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

Branch: refs/heads/master
Commit: 45c4b9db9a942e490d2fa7ae3c866416e2acff8b
Parents: f1822e5
Author: Fil Maj <ma...@gmail.com>
Authored: Tue Apr 30 16:14:35 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Tue Apr 30 16:14:35 2013 -0700

----------------------------------------------------------------------
 README.md                                |    9 +-
 main.js                                  |    2 +-
 spec/plugins/ChildBrowser/plugin.xml     |    6 +-
 spec/plugins/DummyPlugin/plugin.xml      |    6 +-
 spec/plugins/FaultyPlugin/plugin.xml     |    7 +-
 spec/plugins/WebNotifications/plugin.xml |    8 +-
 spec/plugins/WeblessPlugin/plugin.xml    |    6 +-
 spec/plugins/cordova.echo/plugin.xml     |    3 +-
 spec/util/config-changes.spec.js         |   22 +++-
 spec/util/xml-helpers.spec.js            |  122 ++++++++++++++++++-------
 src/install.js                           |   20 +++--
 src/util/config-changes.js               |   63 +++++++------
 src/util/xml-helpers.js                  |   72 ++++++---------
 13 files changed, 213 insertions(+), 133 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/45c4b9db/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index aeab284..2ed7bd9 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@ This document defines tool usage and the plugin format specification.
 ## Usage
 
     plugman --fetch --plugin <directory|git-url|name> [--plugins_dir <directory>]
-    plugman --install --platform <ios|android|bb10> --project <directory> --plugin <name|url> [--plugins_dir <directory>]
+    plugman --install --platform <ios|android|bb10> --project <directory> --plugin <name|url> [--plugins_dir <directory>] [--variable <name>=<value> [--variable <name>=<value> ...]]
     plugman --uninstall --platform <ios|android|bb10> --project <directory> --plugin <name> [--plugins_dir <directory>]
     plugman --list [--plugins_dir <directory>]
     plugman --prepare --platform <ios|android|bb10> --project <directory> [--plugins_dir <directory>]
@@ -29,9 +29,12 @@ This document defines tool usage and the plugin format specification.
 * `--list`: Lists all `--fetch`'ed plugins
 * `--prepare`: Based on all installed plugins, will set up properly injecting plugin JavaScript code and setting up permissions properly. Implicitly called after `--install` and `--uninstall` commands. See below for more details.
 
-`--plugins_dir` defaults to `<project>/cordova/plugins`, but can be any directory containing a subdirectory for each fetched plugin
+Other parameters: 
 
-Note that `--fetch` deals with the local cache of the plugin's files and doesn't care about platforms, while `--install` and `--uninstall` require specifying the target platform and the location of the project, and actually do installation of plugin code and assets.
+* `--plugins_dir` defaults to `<project>/cordova/plugins`, but can be any directory containing a subdirectory for each fetched plugin.
+* `--variable` allows to specify certain variables at install time, necessary for certain plugins requiring API keys or other custom, user-defined parameters.
+
+Note that `--fetch` deals with the local cache of the plugin's files (in the `--plugins_dir` location) and doesn't care about platforms, while `--install` and `--uninstall` require specifying the target platform and the location of the project, and actually do installation of plugin code and assets.
 
 
 ### Supported Platforms

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/45c4b9db/main.js
----------------------------------------------------------------------
diff --git a/main.js b/main.js
index 4b882d9..0398201 100755
--- a/main.js
+++ b/main.js
@@ -96,7 +96,7 @@ function printUsage() {
     platforms = known_opts.platform.join('|');
     console.log('Usage\n---------');
     console.log('Fetch a plugin:\n\t' + package.name + ' --fetch --plugin <directory|git-url|name> [--plugins_dir <directory>]\n');
-    console.log('Install an already fetched plugin:\n\t' + package.name + ' --platform <'+ platforms +'> --project <directory> --plugin <name> [--plugins_dir <directory>]\n');
+    console.log('Install a plugin (will call fetch if cannot be found):\n\t' + package.name + ' --platform <'+ platforms +'> --project <directory> --plugin <name> [--plugins_dir <directory>] [--variable <name>=<value>]\n');
     console.log('Uninstall a plugin:\n\t' + package.name + ' --uninstall --platform <'+ platforms +'> --project <directory> --plugin <name> [--plugins_dir <directory>]\n');
     console.log('List plugins:\n\t' + package.name + ' --list [--plugins_dir <directory>]\n');
     console.log('Prepare project:\n\t' + package.name + ' --prepare --platform <ios|android|bb10> --project <directory> [--plugins_dir <directory>]');

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/45c4b9db/spec/plugins/ChildBrowser/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/plugins/ChildBrowser/plugin.xml b/spec/plugins/ChildBrowser/plugin.xml
index 1f40d57..c39c69e 100644
--- a/spec/plugins/ChildBrowser/plugin.xml
+++ b/spec/plugins/ChildBrowser/plugin.xml
@@ -32,8 +32,10 @@
         <clobbers target="childbrowser" />
     </js-module>
 
-    <access origin="build.phonegap.com" />
-    <access origin="s3.amazonaws.com" />
+    <config-file target="config.xml" parent="/*">
+        <access origin="build.phonegap.com" />
+        <access origin="s3.amazonaws.com" />
+    </config-file>
 
     <!-- android -->
     <platform name="android">

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/45c4b9db/spec/plugins/DummyPlugin/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/plugins/DummyPlugin/plugin.xml b/spec/plugins/DummyPlugin/plugin.xml
index 06b99eb..44e18f1 100644
--- a/spec/plugins/DummyPlugin/plugin.xml
+++ b/spec/plugins/DummyPlugin/plugin.xml
@@ -28,8 +28,10 @@
     <asset src="www/dummyplugin.js" target="dummyplugin.js" />
     <asset src="www/dummyplugin" target="dummyplugin" />
 
-	<access origin="build.phonegap.com" />
-	<access origin="s3.amazonaws.com" />
+    <config-file target="config.xml" parent="/*">
+        <access origin="build.phonegap.com" />
+        <access origin="s3.amazonaws.com" />
+    </config-file>
 	
     <!-- android -->
     <platform name="android">

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/45c4b9db/spec/plugins/FaultyPlugin/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/plugins/FaultyPlugin/plugin.xml b/spec/plugins/FaultyPlugin/plugin.xml
index 4c49a06..4909123 100644
--- a/spec/plugins/FaultyPlugin/plugin.xml
+++ b/spec/plugins/FaultyPlugin/plugin.xml
@@ -28,8 +28,11 @@
 	<access origin="build.phonegap.com" />
 	<access origin="s3.amazonaws.com" />
     <!-- file doesn't exist -->
-    <asset src="www/main.js" target="faultyplugin/main.js" />
-    <asset src="www/index.js" target="faultyplugin/index.js" />
+
+    <config-file target="config.xml" parent="/widget">
+        <asset src="www/main.js" target="faultyplugin/main.js" />
+        <asset src="www/index.js" target="faultyplugin/index.js" />
+    </config-file>
 	
     <!-- android -->
     <platform name="android">

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/45c4b9db/spec/plugins/WebNotifications/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/plugins/WebNotifications/plugin.xml b/spec/plugins/WebNotifications/plugin.xml
index d6528a0..5fe344f 100644
--- a/spec/plugins/WebNotifications/plugin.xml
+++ b/spec/plugins/WebNotifications/plugin.xml
@@ -27,12 +27,14 @@
 
     <asset src="www/webnotifications.js" target="webnotifications.js" />
 
-	<access origin="build.phonegap.com" />
-	<access origin="s3.amazonaws.com" />
+    <config-file target="config.xml" parent="/*">
+        <access origin="build.phonegap.com" />
+        <access origin="s3.amazonaws.com" />
+    </config-file>
 	
     <!-- ios -->
     <platform name="ios">
-        <config-file target="config.xml" parent="/widget/plugins">
+        <config-file target="config.xml" parent="/*/plugins">
             <plugin name="WebNotifications"
                 value="WebNotifications"/>
         </config-file>

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/45c4b9db/spec/plugins/WeblessPlugin/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/plugins/WeblessPlugin/plugin.xml b/spec/plugins/WeblessPlugin/plugin.xml
index 0056636..078e468 100644
--- a/spec/plugins/WeblessPlugin/plugin.xml
+++ b/spec/plugins/WeblessPlugin/plugin.xml
@@ -25,8 +25,10 @@
 
     <name>Webless Plugin</name>
 
-	<access origin="build.phonegap.com" />
-	<access origin="s3.amazonaws.com" />
+    <config-file target="config.xml" parent="/*">
+        <access origin="build.phonegap.com" />
+        <access origin="s3.amazonaws.com" />
+    </config-file>
 	
     <!-- android -->
     <platform name="android">

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/45c4b9db/spec/plugins/cordova.echo/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/plugins/cordova.echo/plugin.xml b/spec/plugins/cordova.echo/plugin.xml
index 8468ec1..dde71bf 100644
--- a/spec/plugins/cordova.echo/plugin.xml
+++ b/spec/plugins/cordova.echo/plugin.xml
@@ -8,7 +8,6 @@
     </engines>
     
     <name>cordova echo</name>
-
     
     <platform name="blackberry">    
         <config-file target="config.xml" parent="/widget">
@@ -21,4 +20,4 @@
         <source-file src="src/blackberry/device/echoJnext.so" target-dir="ext-qnx/cordova.echo/device" />
         <source-file src="src/blackberry/simulator/echoJnext.so" target-dir="ext-qnx/cordova.echo/simulator" />
     </platform>
-</plugin>
\ No newline at end of file
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/45c4b9db/spec/util/config-changes.spec.js
----------------------------------------------------------------------
diff --git a/spec/util/config-changes.spec.js b/spec/util/config-changes.spec.js
index de0936a..15d4618 100644
--- a/spec/util/config-changes.spec.js
+++ b/spec/util/config-changes.spec.js
@@ -195,6 +195,12 @@ describe('config-changes module', function() {
             var munge = configChanges.generate_plugin_config_munge(childrenplugin, 'android', temp, {PACKAGE_NAME:'ca.filmaj.plugins'});
             expect(munge['AndroidManifest.xml']['/manifest']['<uses-permission android:name="ca.filmaj.plugins.permission.C2D_MESSAGE" />']).toBeDefined();
         });
+        it('should create munges for platform-agnostic config.xml changes', function() {
+            shell.cp('-rf', android_two_project, temp);
+            var munge = configChanges.generate_plugin_config_munge(dummyplugin, 'android', temp, {});
+            expect(munge['config.xml']['/*']['<access origin="build.phonegap.com" />']).toBeDefined();
+            expect(munge['config.xml']['/*']['<access origin="s3.amazonaws.com" />']).toBeDefined();
+        });
         it('should automatically add on ios bundle identifier as PACKAGE_NAME variable for ios config munges', function() {
             shell.cp('-rf', ios_config_xml, temp);
             var munge = configChanges.generate_plugin_config_munge(varplugin, 'ios', temp, {});
@@ -253,9 +259,11 @@ describe('config-changes module', function() {
                 var manifest_doc = new et.ElementTree(et.XML(fs.readFileSync(path.join(temp, 'AndroidManifest.xml'), 'utf-8')));
                 var munge = dummy_xml.find('./platform[@name="android"]/config-file[@target="AndroidManifest.xml"]');
                 configChanges.process(plugins_dir, temp, 'android');
-                expect(spy.calls.length).toEqual(2);
-                expect(spy.argsForCall[0][2]).toEqual('/manifest/application');
-                expect(spy.argsForCall[1][2]).toEqual('/cordova/plugins');
+                expect(spy.calls.length).toEqual(4);
+                expect(spy.argsForCall[0][2]).toEqual('/*');
+                expect(spy.argsForCall[1][2]).toEqual('/*');
+                expect(spy.argsForCall[2][2]).toEqual('/manifest/application');
+                expect(spy.argsForCall[3][2]).toEqual('/cordova/plugins');
             });
             it('should not call graftXML for a config munge that already exists from another plugin', function() {
                 shell.cp('-rf', android_two_project, temp);
@@ -331,9 +339,11 @@ describe('config-changes module', function() {
                 configChanges.add_uninstalled_plugin_to_prepare_queue(plugins_dir, 'DummyPlugin', 'android');
                 var spy = spyOn(xml_helpers, 'pruneXML').andReturn(true);
                 configChanges.process(plugins_dir, temp, 'android');
-                expect(spy.calls.length).toEqual(2);
-                expect(spy.argsForCall[0][2]).toEqual('/manifest/application');
-                expect(spy.argsForCall[1][2]).toEqual('/cordova/plugins');
+                expect(spy.calls.length).toEqual(4);
+                expect(spy.argsForCall[0][2]).toEqual('/*');
+                expect(spy.argsForCall[1][2]).toEqual('/*');
+                expect(spy.argsForCall[2][2]).toEqual('/manifest/application');
+                expect(spy.argsForCall[3][2]).toEqual('/cordova/plugins');
             });
             it('should generate a config munge that interpolates variables into config changes, if applicable', function() {
                 shell.cp('-rf', android_two_project, temp);

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/45c4b9db/spec/util/xml-helpers.spec.js
----------------------------------------------------------------------
diff --git a/spec/util/xml-helpers.spec.js b/spec/util/xml-helpers.spec.js
index 5ba0460..0bf2946 100644
--- a/spec/util/xml-helpers.spec.js
+++ b/spec/util/xml-helpers.spec.js
@@ -31,42 +31,98 @@ var path = require('path')
   , goodbyeTag = et.XML("<h1>GOODBYE</h1>")
   , helloTagTwo = et.XML("<h1>  HELLO  </h1>");
 
+
 describe('xml-helpers', function(){
-    it('should return false for different tags', function(){
-        expect(xml_helpers.equalNodes(usesNetworkOne, title)).toBe(false);
+    describe('equalNodes', function() {
+        it('should return false for different tags', function(){
+            expect(xml_helpers.equalNodes(usesNetworkOne, title)).toBe(false);
+        });
+
+        it('should return true for identical tags', function(){
+            expect(xml_helpers.equalNodes(usesNetworkOne, usesNetworkTwo)).toBe(true);
+        });   
+        
+        it('should return false for different attributes', function(){
+            expect(xml_helpers.equalNodes(usesNetworkOne, usesReceive)).toBe(false);
+        });  
+        
+        it('should distinguish between text', function(){
+            expect(xml_helpers.equalNodes(helloTagOne, goodbyeTag)).toBe(false);
+        });  
+        
+        it('should ignore whitespace in text', function(){
+            expect(xml_helpers.equalNodes(helloTagOne, helloTagTwo)).toBe(true);
+        });    
+        
+        describe('should compare children', function(){
+            it('by child quantity', function(){
+                var one = et.XML('<i><b>o</b></i>'),
+                    two = et.XML('<i><b>o</b><u></u></i>');
+        
+                expect(xml_helpers.equalNodes(one, two)).toBe(false);        
+            });
+            
+            it('by child equality', function(){
+                var one = et.XML('<i><b>o</b></i>'),
+                    two = et.XML('<i><u></u></i>'),
+                    uno = et.XML('<i>\n<b>o</b>\n</i>');
+        
+                expect(xml_helpers.equalNodes(one, uno)).toBe(true); 
+                expect(xml_helpers.equalNodes(one, two)).toBe(false);       
+            });
+        }); 
     });
+    describe('pruneXML', function() {
+        var config_xml;
 
-    it('should return true for identical tags', function(){
-        expect(xml_helpers.equalNodes(usesNetworkOne, usesNetworkTwo)).toBe(true);
-    });   
-    
-    it('should return false for different attributes', function(){
-        expect(xml_helpers.equalNodes(usesNetworkOne, usesReceive)).toBe(false);
-    });  
-    
-    it('should distinguish between text', function(){
-        expect(xml_helpers.equalNodes(helloTagOne, goodbyeTag)).toBe(false);
-    });  
-    
-    it('should ignore whitespace in text', function(){
-        expect(xml_helpers.equalNodes(helloTagOne, helloTagTwo)).toBe(true);
-    });    
-    
-    describe('should compare children', function(){
-        it('by child quantity', function(){
-            var one = et.XML('<i><b>o</b></i>'),
-                two = et.XML('<i><b>o</b><u></u></i>');
-    
-            expect(xml_helpers.equalNodes(one, two)).toBe(false);        
+        beforeEach(function() {
+            config_xml = xml_helpers.parseElementtreeSync(path.join(__dirname, '..', 'projects', 'android_two', 'res', 'xml', 'config.xml'));
         });
-        
-        it('by child equality', function(){
-            var one = et.XML('<i><b>o</b></i>'),
-                two = et.XML('<i><u></u></i>'),
-                uno = et.XML('<i>\n<b>o</b>\n</i>');
-    
-            expect(xml_helpers.equalNodes(one, uno)).toBe(true); 
-            expect(xml_helpers.equalNodes(one, two)).toBe(false);       
+
+        it('should remove any children that match the specified selector', function() {
+            var children = config_xml.findall('plugins/plugin');
+            xml_helpers.pruneXML(config_xml, children, 'plugins');
+            expect(config_xml.find('plugins').getchildren().length).toEqual(0);
+        });
+        it('should do nothing if the children cannot be found', function() {
+            var children = [title];
+            xml_helpers.pruneXML(config_xml, children, 'plugins');
+            expect(config_xml.find('plugins').getchildren().length).toEqual(17);
         });
-    }); 
+        it('should be able to handle absolute selectors', function() {
+            var children = config_xml.findall('plugins/plugin');
+            xml_helpers.pruneXML(config_xml, children, '/cordova/plugins');
+            expect(config_xml.find('plugins').getchildren().length).toEqual(0);
+        });
+        it('should be able to handle absolute selectors with wildcards', function() {
+            var children = config_xml.findall('plugins/plugin');
+            xml_helpers.pruneXML(config_xml, children, '/*/plugins');
+            expect(config_xml.find('plugins').getchildren().length).toEqual(0);
+        });
+    });
+
+    describe('graftXML', function() {
+        var config_xml, plugin_xml;
+
+        beforeEach(function() {
+            config_xml = xml_helpers.parseElementtreeSync(path.join(__dirname, '..', 'projects', 'android_two', 'res', 'xml', 'config.xml'));
+            plugin_xml = xml_helpers.parseElementtreeSync(path.join(__dirname, '..', 'plugins', 'ChildBrowser', 'plugin.xml'));
+        });
+
+        it('should add children to the specified selector', function() {
+            var children = plugin_xml.find('config-file').getchildren();
+            xml_helpers.graftXML(config_xml, children, 'plugins');
+            expect(config_xml.find('plugins').getchildren().length).toEqual(19);
+        });
+        it('should be able to handle absolute selectors', function() {
+            var children = plugin_xml.find('config-file').getchildren();
+            xml_helpers.graftXML(config_xml, children, '/cordova');
+            expect(config_xml.findall('access').length).toEqual(3);
+        });
+        it('should be able to handle absolute selectors with wildcards', function() {
+            var children = plugin_xml.find('config-file').getchildren();
+            xml_helpers.graftXML(config_xml, children, '/*');
+            expect(config_xml.findall('access').length).toEqual(3);
+        });
+    });
 });

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/45c4b9db/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index 2ecaedb..b07540c 100644
--- a/src/install.js
+++ b/src/install.js
@@ -86,8 +86,7 @@ function runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variable
         // Either this plugin doesn't support this platform, or it's a JS-only plugin.
         // Either way, return now.
         // should call prepare probably!
-        require('./../plugman').prepare(project_dir, platform, plugins_dir);
-        if (callback) callback();
+        finalizeInstall(project_dir, plugins_dir, platform, plugin_basename, filtered_variables, callback);
         return;
     }
 
@@ -127,17 +126,22 @@ function runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variable
             }
         } else {
             // WIN!
-            // queue up the plugin so prepare knows what to do.
-            config_changes.add_installed_plugin_to_prepare_queue(plugins_dir, path.basename(plugin_dir), platform, filtered_variables);
-            // call prepare after a successful install
-            require('./../plugman').prepare(project_dir, platform, plugins_dir);
-
             // Log out plugin INFO element contents in case additional install steps are necessary
             var info = platformTag.findall('./info');
             if(info.length) {
                 console.log(info[0].text);
             }
-            if (callback) callback();
+
+            finalizeInstall(project_dir, plugins_dir, platform, plugin_basename, filtered_variables, callback);
         }
     });
 }
+
+function finalizeInstall(project_dir, plugins_dir, platform, plugin_name, variables, callback) {
+    // queue up the plugin so prepare knows what to do.
+    config_changes.add_installed_plugin_to_prepare_queue(plugins_dir, plugin_name, platform, variables);
+    // call prepare after a successful install
+    require('./../plugman').prepare(project_dir, platform, plugins_dir);
+
+    if (callback) callback();
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/45c4b9db/src/util/config-changes.js
----------------------------------------------------------------------
diff --git a/src/util/config-changes.js b/src/util/config-changes.js
index 059fd1b..4ff30e9 100644
--- a/src/util/config-changes.js
+++ b/src/util/config-changes.js
@@ -83,27 +83,35 @@ module.exports = {
         var plugin_xml = new et.ElementTree(et.XML(fs.readFileSync(path.join(plugin_dir, 'plugin.xml'), 'utf-8')));
 
         var platformTag = plugin_xml.find('platform[@name="' + platform + '"]');
-        var changes = platformTag.findall('config-file');
-        // note down plugins-plist munges in special section of munge obj
-        var plugins_plist = platformTag.findall('plugins-plist');
-        plugins_plist.forEach(function(pl) {
-            if (!munge['plugins-plist']) {
-                munge['plugins-plist'] = {};
-            }
-            var key = pl.attrib['key'];
-            var value = pl.attrib['string'];
-            if (!munge['plugins-plist'][key]) {
-                munge['plugins-plist'][key] = value;
-            }
-        });
+        var changes = [];
+        // add platform-agnostic config changes
+        changes = changes.concat(plugin_xml.findall('config-file'));
+        if (platformTag) {
+            // add platform-specific config changes if they exist
+            changes = changes.concat(platformTag.findall('config-file'));
+
+            // note down plugins-plist munges in special section of munge obj
+            var plugins_plist = platformTag.findall('plugins-plist');
+            plugins_plist.forEach(function(pl) {
+                if (!munge['plugins-plist']) {
+                    munge['plugins-plist'] = {};
+                }
+                var key = pl.attrib['key'];
+                var value = pl.attrib['string'];
+                if (!munge['plugins-plist'][key]) {
+                    munge['plugins-plist'][key] = value;
+                }
+            });
+        }
 
         changes.forEach(function(change) {
             var target = change.attrib['target'];
+            var parent = change.attrib['parent'];
             if (!munge[target]) {
                 munge[target] = {};
             }
-            if (!munge[target][change.attrib['parent']]) {
-                munge[target][change.attrib['parent']] = {};
+            if (!munge[target][parent]) {
+                munge[target][parent] = {};
             }
             var xmls = change.getchildren();
             xmls.forEach(function(xml) {
@@ -115,10 +123,10 @@ module.exports = {
                     stringified = stringified.replace(regExp, vars[key]);
                 });
                 // 2. add into munge
-                if (!munge[target][change.attrib['parent']][stringified]) {
-                    munge[target][change.attrib['parent']][stringified] = 0;
+                if (!munge[target][parent][stringified]) {
+                    munge[target][parent][stringified] = 0;
                 }
-                munge[target][change.attrib['parent']][stringified] += 1;
+                munge[target][parent][stringified] += 1;
             });
         });
         return munge;
@@ -171,14 +179,14 @@ module.exports = {
                                         var filepath = resolveConfigFilePath(project_dir, platform, file);
                                         if (fs.existsSync(filepath)) {
                                             if (path.extname(filepath) == '.xml') {
-                                                var xml_to_prune = [new et.ElementTree(et.XML(xml_child)).getroot()];
+                                                var xml_to_prune = [et.XML(xml_child)];
                                                 var doc = new et.ElementTree(et.XML(fs.readFileSync(filepath, 'utf-8')));
                                                 if (xml_helpers.pruneXML(doc, xml_to_prune, selector)) {
                                                     // were good, write out the file!
                                                     fs.writeFileSync(filepath, doc.write(), 'utf-8');
                                                 } else {
                                                     // uh oh
-                                                    throw new Error('pruning xml during config uninstall went bad :(');
+                                                    throw new Error('pruning xml at selector "' + selector + '" from "' + filepath + '" during config uninstall went bad :(');
                                                 }
                                             } else {
                                                 // plist file
@@ -187,7 +195,7 @@ module.exports = {
                                                 if (plist_helpers.prunePLIST(plistObj, xml_child, selector)) {
                                                     fs.writeFileSync(filepath, plist.build(plistObj));
                                                 } else {
-                                                    throw new Error('grafting to plist during config install went bad :(');
+                                                    throw new Error('grafting to plist "' + filepath + '" during config install went bad :(');
                                                 }
                                             }
                                         }
@@ -257,14 +265,14 @@ module.exports = {
                                 if (fs.existsSync(filepath)) {
                                     // look at ext and do proper config change based on file type
                                     if (path.extname(filepath) == '.xml') {
-                                        var xml_to_graft = [new et.ElementTree(et.XML(xml_child)).getroot()];
+                                        var xml_to_graft = [et.XML(xml_child)];
                                         var doc = new et.ElementTree(et.XML(fs.readFileSync(filepath, 'utf-8')));
                                         if (xml_helpers.graftXML(doc, xml_to_graft, selector)) {
                                             // were good, write out the file!
                                             fs.writeFileSync(filepath, doc.write(), 'utf-8');
                                         } else {
                                             // uh oh
-                                            throw new Error('grafting xml during config install went bad :(');
+                                            throw new Error('grafting xml at selector "' + selector + '" from "' + filepath + '" during config install went bad :(');
                                         }
                                     } else {
                                         // plist file
@@ -273,7 +281,7 @@ module.exports = {
                                         if (plist_helpers.graftPLIST(plistObj, xml_child, selector)) {
                                             fs.writeFileSync(filepath, plist.build(plistObj));
                                         } else {
-                                            throw new Error('grafting to plist during config install went bad :(');
+                                            throw new Error('grafting to plist "' + filepath + '" during config install went bad :(');
                                         }
                                     }
                                 }
@@ -313,9 +321,10 @@ function resolveConfigFilePath(project_dir, platform, file) {
         var matches = glob.sync(path.join(project_dir, '**', file));
         if (matches.length) filepath = matches[0];
     } else {
-        // ios has a special-case config.xml target that is just "config.xml". this should be resolved to the real location of the file.
-        if (platform == 'ios' && file == 'config.xml') {
-            filepath = glob.sync(path.join(project_dir, '**', 'config.xml'))[0];
+        // special-case config.xml target that is just "config.xml". this should be resolved to the real location of the file.
+        if (file == 'config.xml') {
+            var matches = glob.sync(path.join(project_dir, '**', 'config.xml'));
+            if (matches.length) filepath = matches[0];
         }
     }
     return filepath;

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/45c4b9db/src/util/xml-helpers.js
----------------------------------------------------------------------
diff --git a/src/util/xml-helpers.js b/src/util/xml-helpers.js
index ba6e5b3..667a307 100644
--- a/src/util/xml-helpers.js
+++ b/src/util/xml-helpers.js
@@ -73,27 +73,8 @@ module.exports = {
 
     // adds node to doc at selector
     graftXML: function(doc, nodes, selector) {
-        var ROOT = /^\/([^\/]*)/
-          , ABSOLUTE = /^\/([^\/]*)\/(.*)/
-          , parent, tagName, subSelector;
-
-        // handle absolute selector (which elementtree doesn't like)
-        if (ROOT.test(selector)) {
-            tagName = selector.match(ROOT)[1];
-            if (tagName === doc._root.tag) {
-                parent = doc._root;
-
-                // could be an absolute path, but not selecting the root
-                if (ABSOLUTE.test(selector)) {
-                    subSelector = selector.match(ABSOLUTE)[2];
-                    parent = parent.find(subSelector)
-                }
-            } else {
-                return false;
-            }
-        } else {
-            parent = doc.find(selector)
-        }
+        var parent = resolveParent(doc, selector);
+        if (!parent) return false;
 
         nodes.forEach(function (node) {
             // check if child is unique first
@@ -107,27 +88,9 @@ module.exports = {
 
     // removes node from doc at selector
     pruneXML: function(doc, nodes, selector) {
-        var ROOT = /^\/([^\/]*)/
-          , ABSOLUTE = /^\/([^\/]*)\/(.*)/
-          , parent, tagName, subSelector;
-
-        // handle absolute selector (which elementtree doesn't like)
-        if (ROOT.test(selector)) {
-            tagName = selector.match(ROOT)[1];
-            if (tagName === doc._root.tag) {
-                parent = doc._root;
-
-                // could be an absolute path, but not selecting the root
-                if (ABSOLUTE.test(selector)) {
-                    subSelector = selector.match(ABSOLUTE)[2];
-                    parent = parent.find(subSelector)
-                }
-            } else {
-                return false;
-            }
-        } else {
-            parent = doc.find(selector)
-        }
+        var parent = resolveParent(doc, selector);
+        if (!parent) return false;
+
         nodes.forEach(function (node) {
             var matchingKid = null;
             if ((matchingKid = findChild(node, parent)) != null) {
@@ -174,3 +137,28 @@ function uniqueChild(node, parent) {
     }
 }
 
+var ROOT = /^\/([^\/]*)/,
+    ABSOLUTE = /^\/([^\/]*)\/(.*)/;
+function resolveParent(doc, selector) {
+    var parent, tagName, subSelector;
+
+    // handle absolute selector (which elementtree doesn't like)
+    if (ROOT.test(selector)) {
+        tagName = selector.match(ROOT)[1];
+        // test for wildcard "any-tag" root selector
+        if (tagName == '*' || tagName === doc._root.tag) {
+            parent = doc._root;
+
+            // could be an absolute path, but not selecting the root
+            if (ABSOLUTE.test(selector)) {
+                subSelector = selector.match(ABSOLUTE)[2];
+                parent = parent.find(subSelector)
+            }
+        } else {
+            return false;
+        }
+    } else {
+        parent = doc.find(selector)
+    }
+    return parent;
+}


[2/2] git commit: 0.6.2 version bump

Posted by fi...@apache.org.
0.6.2 version bump


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

Branch: refs/heads/master
Commit: d597d3473511a2cee7d5c48394158cbfa7f9a5fa
Parents: 45c4b9d
Author: Fil Maj <ma...@gmail.com>
Authored: Tue Apr 30 16:15:14 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Tue Apr 30 16:15:14 2013 -0700

----------------------------------------------------------------------
 package.json |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/d597d347/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 97511cf..6eb5ceb 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
   "author": "Andrew Lunny <al...@gmail.com>",
   "name": "plugman",
   "description": "install/uninstall Cordova plugins",
-  "version": "0.6.1",
+  "version": "0.6.2",
   "repository": {
     "type": "git",
     "url": "git://git-wip-us.apache.org/repos/asf/cordova-plugman.git"