cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject git commit: a couple of test stubs re package name interpolation inside the config handler. removed config-file and plugins-plist handling from platform-level handlers. added custom config file / wildcard filepaths for config file handling (as it was bef
Date Mon, 29 Apr 2013 21:37:23 GMT
Updated Branches:
  refs/heads/master 6ee050398 -> 050da5c6f


a couple of test stubs re package name interpolation inside the config handler. removed config-file
and plugins-plist handling from platform-level handlers. added custom config file / wildcard
filepaths for config file handling (as it was before more or less)


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

Branch: refs/heads/master
Commit: 050da5c6f425b134270802f21c1d119e6916a8b1
Parents: 6ee0503
Author: Fil Maj <maj.fil@gmail.com>
Authored: Mon Apr 29 14:37:17 2013 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Mon Apr 29 14:37:17 2013 -0700

----------------------------------------------------------------------
 spec/plugins/ChildBrowser/plugin.xml              |    7 +-
 spec/projects/ios-config-xml/SampleApp-Info.plist |   78 ---------------
 spec/util/config-changes.spec.js                  |   28 +++---
 src/install.js                                    |    2 -
 src/platforms/android.js                          |   22 ----
 src/platforms/blackberry.js                       |   22 ----
 src/platforms/ios.js                              |   83 +---------------
 src/uninstall.js                                  |    9 +--
 src/util/config-changes.js                        |   66 +++++++++---
 src/util/plist-helpers.js                         |   36 +++----
 10 files changed, 89 insertions(+), 264 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/050da5c6/spec/plugins/ChildBrowser/plugin.xml
----------------------------------------------------------------------
diff --git a/spec/plugins/ChildBrowser/plugin.xml b/spec/plugins/ChildBrowser/plugin.xml
index ee5e2ba..1f40d57 100644
--- a/spec/plugins/ChildBrowser/plugin.xml
+++ b/spec/plugins/ChildBrowser/plugin.xml
@@ -90,10 +90,9 @@
             </array>
         </config-file>
 
-        <header-file src="ChildBrowserCommand.h" />
-        <header-file src="ChildBrowserViewController.h" />
-        <header-file src="preserveDirs/PreserveDirsTest.h" preserve-dirs="true" />
-        <header-file src="TargetDirTest.h" target-dir="targetDir"/>
+        <header-file src="src/ios/ChildBrowserCommand.h" />
+        <header-file src="src/ios/ChildBrowserViewController.h" />
+        <header-file src="src/ios/TargetDirTest.h" target-dir="targetDir"/>
 
         <source-file src="src/ios/ChildBrowserCommand.m" />
         <source-file src="src/ios/ChildBrowserViewController.m" />

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/050da5c6/spec/projects/ios-config-xml/SampleApp-Info.plist
----------------------------------------------------------------------
diff --git a/spec/projects/ios-config-xml/SampleApp-Info.plist b/spec/projects/ios-config-xml/SampleApp-Info.plist
deleted file mode 100644
index 6010b61..0000000
--- a/spec/projects/ios-config-xml/SampleApp-Info.plist
+++ /dev/null
@@ -1,78 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<!--
-#
-# 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.
-#
--->
-<plist version="1.0">
-<dict>
-	<key>CFBundleIcons</key>
-	<dict>
-		<key>CFBundlePrimaryIcon</key>
-		<dict>
-			<key>CFBundleIconFiles</key>
-			<array>
-                <string>icon.png</string>
-                <string>icon@2x.png</string>
-                <string>icon-72.png</string>
-                <string>icon-72@2x.png</string>
-			</array>
-			<key>UIPrerenderedIcon</key>
-			<false/>
-		</dict>
-	</dict>
-	<key>UISupportedInterfaceOrientations~ipad</key>
-	<array>
-		<string>UIInterfaceOrientationPortrait</string>
-		<string>UIInterfaceOrientationLandscapeLeft</string>
-		<string>UIInterfaceOrientationPortraitUpsideDown</string>
-		<string>UIInterfaceOrientationLandscapeRight</string>
-	</array>
-	<key>UISupportedInterfaceOrientations</key>
-	<array>
-		<string>UIInterfaceOrientationPortrait</string>
-	</array>
-	<key>CFBundleDevelopmentRegion</key>
-	<string>English</string>
-	<key>CFBundleDisplayName</key>
-	<string>${PRODUCT_NAME}</string>
-	<key>CFBundleExecutable</key>
-	<string>${EXECUTABLE_NAME}</string>
-	<key>CFBundleIconFile</key>
-	<string>icon.png</string>
-	<key>CFBundleIdentifier</key>
-	<string>com.example.friendstring</string>
-	<key>CFBundleInfoDictionaryVersion</key>
-	<string>6.0</string>
-	<key>CFBundleName</key>
-	<string>${PRODUCT_NAME}</string>
-	<key>CFBundlePackageType</key>
-	<string>APPL</string>
-	<key>CFBundleSignature</key>
-	<string>????</string>
-	<key>CFBundleVersion</key>
-	<string>1.0</string>
-	<key>LSRequiresIPhoneOS</key>
-	<true/>
-	<key>NSMainNibFile</key>
-	<string></string>
-	<key>NSMainNibFile~ipad</key>
-	<string></string>
-</dict>
-</plist>

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/050da5c6/spec/util/config-changes.spec.js
----------------------------------------------------------------------
diff --git a/spec/util/config-changes.spec.js b/spec/util/config-changes.spec.js
index ddf7af5..49a5978 100644
--- a/spec/util/config-changes.spec.js
+++ b/spec/util/config-changes.spec.js
@@ -8,6 +8,7 @@ var configChanges = require('../../src/util/config-changes'),
     shell   = require('shelljs'),
     temp    = path.join(os.tmpdir(), 'plugman'),
     dummyplugin = path.join(__dirname, '..', 'plugins', 'DummyPlugin'),
+    cbplugin = path.join(__dirname, '..', 'plugins', 'ChildBrowser'),
     childrenplugin = path.join(__dirname, '..', 'plugins', 'multiple-children'),
     shareddepsplugin = path.join(__dirname, '..', 'plugins', 'shared-deps-multi-child'),
     configplugin = path.join(__dirname, '..', 'plugins', 'ConfigTestPlugin'),
@@ -189,6 +190,8 @@ describe('config-changes module', function() {
             var munge = configChanges.generate_plugin_config_munge(childrenplugin, 'android',
{PACKAGE_NAME:'ca.filmaj.plugins'});
             expect(munge['AndroidManifest.xml']['/manifest']['<uses-permission android:name="ca.filmaj.plugins.permission.C2D_MESSAGE"
/>']).toBeDefined();
         });
+        it('should automatically add on ios bundle identifier as PACKAGE_NAME variable for
ios config munges');
+        it('should automatically add on app java identifier as PACKAGE_NAME variable for
android config munges');
         it('should special case plugins-plist elements into own property', function() {
             var munge = configChanges.generate_plugin_config_munge(dummyplugin, 'ios', {});
             expect(munge['plugins-plist']).toBeDefined();
@@ -241,9 +244,7 @@ describe('config-changes module', function() {
             it('should not call graftXML for a config munge that already exists from another
plugin', function() {
                 shell.cp('-rf', android_two_project, temp);
                 shell.cp('-rf', configplugin, plugins_dir);
-                var cfg = configChanges.get_platform_json(plugins_dir, 'android');
-                cfg.prepare_queue.installed = [{'plugin':'ConfigTestPlugin', 'vars':{}}];
-                configChanges.save_platform_json(cfg, plugins_dir, 'android');
+                configChanges.add_installed_plugin_to_prepare_queue(plugins_dir, 'ConfigTestPlugin',
'android', {});
 
                 var spy = spyOn(xml_helpers, 'graftXML').andReturn(true);
                 configChanges.process(plugins_dir, temp, 'android');
@@ -251,20 +252,25 @@ describe('config-changes module', function() {
             });
             it('should not call graftXML for a config munge targeting a config file that
does not exist', function() {
                 shell.cp('-rf', android_two_project, temp);
-                var cfg = configChanges.get_platform_json(plugins_dir, 'android');
-                cfg.prepare_queue.installed = [{'plugin':'DummyPlugin', 'vars':{}}];
-                configChanges.save_platform_json(cfg, plugins_dir, 'android');
+                configChanges.add_installed_plugin_to_prepare_queue(plugins_dir, 'DummyPlugin',
'android', {});
 
                 var spy = spyOn(fs, 'readFileSync').andCallThrough();
 
                 configChanges.process(plugins_dir, temp, 'android');
                 expect(spy).not.toHaveBeenCalledWith(path.join(temp, 'res', 'xml', 'plugins.xml'),
'utf-8');
             });
+            it('should resolve wildcard config-file targets to the project, if applicable',
function() {
+                shell.cp('-rf', ios_config_xml, temp);
+                shell.cp('-rf', cbplugin, plugins_dir);
+                configChanges.add_installed_plugin_to_prepare_queue(plugins_dir, 'ChildBrowser',
'ios', {});
+                var spy = spyOn(fs, 'readFileSync').andCallThrough();
+
+                configChanges.process(plugins_dir, temp, 'ios');
+                expect(spy).toHaveBeenCalledWith(path.join(temp, 'SampleApp', 'SampleApp-Info.plist'),
'utf8');
+            });
             it('should move successfully installed plugins from queue to installed plugins
section, and include/retain vars if applicable', function() {
                 shell.cp('-rf', varplugin, plugins_dir);
-                var cfg = configChanges.get_platform_json(plugins_dir, 'android');
-                cfg.prepare_queue.installed = [{'plugin':'VariablePlugin', 'vars':{"API_KEY":"hi"}}];
-                configChanges.save_platform_json(cfg, plugins_dir, 'android');
+                configChanges.add_installed_plugin_to_prepare_queue(plugins_dir, 'VariablePlugin',
'android', {"API_KEY":"hi"});
 
                 configChanges.process(plugins_dir, temp, 'android');
 
@@ -276,9 +282,7 @@ describe('config-changes module', function() {
             it('should save changes to global config munge after completing an install',
function() {
                 shell.cp('-rf', android_two_project, temp);
                 shell.cp('-rf', varplugin, plugins_dir);
-                var cfg = configChanges.get_platform_json(plugins_dir, 'android');
-                cfg.prepare_queue.installed = [{'plugin':'VariablePlugin', 'vars':{"API_KEY":"hi"}}];
-                configChanges.save_platform_json(cfg, plugins_dir, 'android');
+                configChanges.add_installed_plugin_to_prepare_queue(plugins_dir, 'VariablePlugin',
'android', {"API_KEY":"hi"});
 
                 var spy = spyOn(configChanges, 'save_platform_json');
                 configChanges.process(plugins_dir, temp, 'android');

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/050da5c6/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index 001f5e6..2ecaedb 100644
--- a/src/install.js
+++ b/src/install.js
@@ -80,8 +80,6 @@ function runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variable
         else throw err;
         return;
     }
-    // TODO: handle asset elements
-
     // TODO: if plugin does not have platform tag but has platform-agnostic config changes,
should we queue it up?
     var platformTag = plugin_et.find('./platform[@name="'+platform+'"]');
     if (!platformTag) {

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/050da5c6/src/platforms/android.js
----------------------------------------------------------------------
diff --git a/src/platforms/android.js b/src/platforms/android.js
index 1234746..3aa9114 100644
--- a/src/platforms/android.js
+++ b/src/platforms/android.js
@@ -64,28 +64,6 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir,
variables
                         common.deleteJava(project_dir, destFile);
                     }
                     break;
-                case 'config-file':
-                    // Only modify config files that exist.
-                    var config_file = path.resolve(project_dir, mod.attrib['target']);
-                    if (fs.existsSync(config_file)) {
-                        var xmlDoc = xml_helpers.parseElementtreeSync(config_file);
-                        var selector = mod.attrib["parent"];
-                        var children = mod.findall('*');
-
-                        if (action == 'install') {
-                            if (!xml_helpers.graftXML(xmlDoc, children, selector)) {
-                                throw new Error('failed to add config-file children to "'
+ selector + '" to "'+ config_file + '"');
-                            }
-                        } else {
-                            if (!xml_helpers.pruneXML(xmlDoc, children, selector)) {
-                                throw new Error('failed to remove config-file children from
"' + selector + '" from "' + config_file + '"');
-                            }
-                        }
-
-                        var output = xmlDoc.write({indent: 4});
-                        fs.writeFileSync(config_file, output);
-                    }
-                    break;
                 case 'asset':
                     var src = mod.attrib['src'];
                     var target = mod.attrib['target'];

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/050da5c6/src/platforms/blackberry.js
----------------------------------------------------------------------
diff --git a/src/platforms/blackberry.js b/src/platforms/blackberry.js
index 6d20036..5136222 100644
--- a/src/platforms/blackberry.js
+++ b/src/platforms/blackberry.js
@@ -52,28 +52,6 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir,
variables
                         common.deleteJava(project_dir, destFile);
                     }
                     break;
-                case 'config-file':
-                    // Only modify config files that exist.
-                    var config_file = path.resolve(project_dir, mod.attrib['target']);
-                    if (fs.existsSync(config_file)) {
-                        var xmlDoc = xml_helpers.parseElementtreeSync(config_file);
-                        var selector = mod.attrib["parent"];
-                        var children = mod.findall('*');
-
-                        if (action == 'install') {
-                            if (!xml_helpers.graftXML(xmlDoc, children, selector)) {
-                                throw new Error('failed to add config-file children to "'
+ filename + '"');
-                            }
-                        } else {
-                            if (!xml_helpers.pruneXML(xmlDoc, children, selector)) {
-                                throw new Error('failed to remove config-file children from
"' + filename + '"');
-                            }
-                        }
-
-                        var output = xmlDoc.write({indent: 4});
-                        fs.writeFileSync(config_file, output);
-                    }
-                    break;
                 case 'asset':
                     var src = mod.attrib['src'];
                     var target = mod.attrib['target'];

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/050da5c6/src/platforms/ios.js
----------------------------------------------------------------------
diff --git a/src/platforms/ios.js b/src/platforms/ios.js
index 101062a..70bc539 100644
--- a/src/platforms/ios.js
+++ b/src/platforms/ios.js
@@ -112,85 +112,6 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir,
variables
                         shell.rm('-rf', targetDir);    
                     }
                     break;
-                case 'plugins-plist':
-                    var name = mod.attrib.key;
-                    var value = mod.attrib.string;
-                    // Tack on stuff into plist if this is an old-style project
-                    if (path.extname(config_file) == '.plist') {
-                        // determine if this is a binary or ascii plist and choose the parser
-                        // TODO: this is temporary until binary support is added to node-plist
-                        var pl = (isBinaryPlist(config_file) ? bplist : plist);
-                        var plistObj = pl.parseFileSync(config_file);
-                        
-                        if (action == 'install') {
-                            // TODO: move to prepare?
-                            // add hosts to whitelist (ExternalHosts) in plist
-                            /*
-                            hosts && hosts.forEach(function(host) {
-                                plistObj.ExternalHosts.push(host.attrib['origin']);
-                            });
-                            */
-
-                            // add plugin to plist
-                            plistObj.Plugins[name] = value;
-                        } else {
-                            delete plistObj.Plugins[name];
-                        }
-                        
-                        // write out plist
-                        fs.writeFileSync(config_file, plist.build(plistObj));
-                    } else {
-                        // If it's a config.xml-based project, we should still add/remove
plugin entry to config.xml
-                        var xmlDoc = xml_helpers.parseElementtreeSync(config_file);
-                        var pluginsEl = xmlDoc.find('plugins');
-                        // Only add if it's not already there.
-                        if (pluginsEl.findall('./plugin[@name="' + name + '"]').length ===
0) {
-                            if ( action == 'install') {
-                                var new_plugin = new et.Element('plugin');
-                                new_plugin.attrib.name = name;
-                                new_plugin.attrib.value = value;
-                                pluginsEl.append(new_plugin);
-                            } else {
-                                var culprit = pluginsEl.find("plugin[@name='"+name+"']");
-                                pluginsEl.remove(0, culprit);
-                            }
-                            var output = xmlDoc.write({indent: 4});
-                            fs.writeFileSync(config_file, output);
-                        }
-                    }
-                    break;
-                case 'config-file':
-                    // Only use config file appropriate for the current cordova-ios project
-                    if (mod.attrib['target'] == config_filename) {
-                        // edit configuration files
-                        var xmlDoc = xml_helpers.parseElementtreeSync(config_file);
-
-                        var selector = mod.attrib["parent"],
-                            children = mod.findall('*');
-
-                        if( action == 'install') {
-                            // Throw error if plugin was already added.
-                            if (children.length == 1 && children[0].tag.toLowerCase()
== 'plugin' && (xmlDoc.find('plugins').findall('./plugin[@name="' + children[0].attrib.name
+ '"]').length === 1)
-                                ||(xmlDoc.find('plugins').findall('./plugin[@value="' + children[0].attrib.value
+ '"]').length === 1)){
-                                throw new Error('faild to add '+children[0].attrib.name+'
to config.xml because it already exists');
-                            }
-
-                            if (!xml_helpers.graftXML(xmlDoc, children, selector)) {
-                                throw new Error('failed to add config-file children to xpath
"' + selector + '" in "' + config_file + '" because xpath selector could not be resolved.');
-                            }
-                        } else {
-                            // Ignore if plugin was already removed.
-                            if (children.length == 1 && children[0].tag.toLowerCase()
== 'plugin' && xmlDoc.find('plugins').findall('./plugin[@name="' + children[0].attrib.name
+ '"]').length === 0) break;
-
-                            if (!xml_helpers.pruneXML(xmlDoc, children, selector)) {
-                                throw new Error('failed to remove config-file children from
"' + selector + '" from "' + config_path + '"');
-                            }
-                        }
-
-                        var output = xmlDoc.write({indent: 4});
-                        fs.writeFileSync(config_file, output);
-                    }
-                    break;
                 case 'asset':
                     var src = mod.attrib['src'];
                     var target = mod.attrib['target'];
@@ -198,7 +119,7 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir,
variables
                         common.copyFile(plugin_dir, src, module.exports.www_dir(project_dir),
target);
                     } else {
                         common.removeFile(module.exports.www_dir(project_dir), target);
-                        common.removeFile(path.resolve(module.exports.www_dir(project_dir),
'plugins', plugin_id));
+                        common.removeFile(path.join(module.exports.www_dir(project_dir),
'plugins'), plugin_id);
                     }
                     break;
                 case 'header-file':
@@ -246,7 +167,7 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir,
variables
                     }
                     break;
                 default:
-                    throw new Error('Unrecognized plugin.xml element/action in android installer:
' + mod.tag);
+                    throw new Error('Unrecognized plugin.xml element/action in ios installer:
' + mod.tag);
                     break;
             }
         } catch(e) {

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/050da5c6/src/uninstall.js
----------------------------------------------------------------------
diff --git a/src/uninstall.js b/src/uninstall.js
index a740d4f..0868b7e 100644
--- a/src/uninstall.js
+++ b/src/uninstall.js
@@ -32,9 +32,6 @@ function runUninstall(platform, project_dir, plugin_dir, plugins_dir, cli_variab
     var name         = plugin_et.findall('name').text;
     var plugin_id    = plugin_et._root.attrib['id'];
 
-    // TODO: remove any asset elements
-
-    var platformTag = plugin_et.find('./platform[@name="'+platform+'"]');
     var platformTag = plugin_et.find('./platform[@name="'+platform+'"]');
     if (!platformTag) {
         // Either this plugin doesn't support this platform, or it's a JS-only plugin.
@@ -52,12 +49,10 @@ function runUninstall(platform, project_dir, plugin_dir, plugins_dir,
cli_variab
         headerFiles = platformTag.findall('./header-file'),
         resourceFiles = platformTag.findall('./resource-file'),
         assets = platformTag.findall('./asset'),
-        frameworks = platformTag.findall('./framework'),
-        pluginsPlist = platformTag.findall('./plugins-plist'),
-        configChanges = platformTag.findall('./config-file');
+        frameworks = platformTag.findall('./framework');
     assets = assets.concat(plugin_et.findall('./asset'));
     
-    txs = txs.concat(sourceFiles, headerFiles, resourceFiles, frameworks, configChanges,
assets, pluginsPlist);
+    txs = txs.concat(sourceFiles, headerFiles, resourceFiles, frameworks, assets);
 
     // pass platform-specific transactions into uninstall
     handler.uninstall(txs, plugin_id, project_dir, plugin_dir, function(err) {

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/050da5c6/src/util/config-changes.js
----------------------------------------------------------------------
diff --git a/src/util/config-changes.js b/src/util/config-changes.js
index e6b9963..a79fa49 100644
--- a/src/util/config-changes.js
+++ b/src/util/config-changes.js
@@ -24,7 +24,8 @@ var fs   = require('fs'),
     bplist = require('bplist-parser'),
     et   = require('elementtree'),
     platforms = require('./../platforms'),
-    xml_helpers = require('./../util/xml-helpers');
+    xml_helpers = require('./../util/xml-helpers'),
+    plist_helpers = require('./../util/plist-helpers');
 
 function checkPlatform(platform) {
     if (!(platform in platforms)) throw new Error('platform "' + platform + '" not recognized.');
@@ -162,14 +163,25 @@ module.exports = {
                                         // config.xml referenced in ios config changes refer
to the project's config.xml, which we need to glob for.
                                         var filepath = resolveConfigFilePath(project_dir,
platform, file);
                                         if (fs.existsSync(filepath)) {
-                                            var doc = new et.ElementTree(et.XML(fs.readFileSync(filepath,
'utf-8')));
-                                            var xml_to_prune = [new et.ElementTree(et.XML(xml_child)).getroot()];
-                                            if (xml_helpers.pruneXML(doc, xml_to_prune, selector))
{
-                                                // were good, write out the file!
-                                                fs.writeFileSync(filepath, doc.write(), 'utf-8');
+                                            if (path.extname(filepath) == '.xml') {
+                                                var xml_to_prune = [new et.ElementTree(et.XML(xml_child)).getroot()];
+                                                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 :(');
+                                                }
                                             } else {
-                                                // uh oh
-                                                throw new Error('pruning xml during config
uninstall went bad :(');
+                                                // plist file
+                                                var pl = (isBinaryPlist(filepath) ? bplist
: plist);
+                                                var plistObj = pl.parseFileSync(filepath);
+                                                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 :(');
+                                                }
                                             }
                                         }
                                         delete global_munge[file][selector][xml_child];
@@ -236,14 +248,26 @@ module.exports = {
                                 // config file may be in a place not exactly specified in
the target
                                 var filepath = resolveConfigFilePath(project_dir, platform,
file);
                                 if (fs.existsSync(filepath)) {
-                                    var doc = new et.ElementTree(et.XML(fs.readFileSync(filepath,
'utf-8')));
-                                    var xml_to_graft = [new et.ElementTree(et.XML(xml_child)).getroot()];
-                                    if (xml_helpers.graftXML(doc, xml_to_graft, selector))
{
-                                        // were good, write out the file!
-                                        fs.writeFileSync(filepath, doc.write(), 'utf-8');
+                                    // 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 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 :(');
+                                        }
                                     } else {
-                                        // uh oh
-                                        throw new Error('grafting xml during config install
went bad :(');
+                                        // plist file
+                                        var pl = (isBinaryPlist(filepath) ? bplist : plist);
+                                        var plistObj = pl.parseFileSync(filepath);
+                                        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 :(');
+                                        }
                                     }
                                 }
                             }
@@ -274,10 +298,18 @@ function isBinaryPlist(filename) {
     return buf.substring(0, 6) === 'bplist';
 }
 
+// Some config-file target attributes are not qualified with a full leading directory, or
contain wildcards. resolve to a real path in this function
 function resolveConfigFilePath(project_dir, platform, file) {
     var filepath = path.join(project_dir, file);
-    if (platform == 'ios' && file == 'config.xml') {
-        filepath = glob.sync(path.join(project_dir, '**', 'config.xml'))[0];
+    if (file.indexOf('*') > -1) {
+        // handle wildcards in targets using glob.
+        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];
+        }
     }
     return filepath;
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/050da5c6/src/util/plist-helpers.js
----------------------------------------------------------------------
diff --git a/src/util/plist-helpers.js b/src/util/plist-helpers.js
index 9a49feb..02af836 100644
--- a/src/util/plist-helpers.js
+++ b/src/util/plist-helpers.js
@@ -23,27 +23,26 @@ var et = require('elementtree'),
     plist = require('plist');
  
 // adds node to doc at selector
-exports.graftPLIST = function (doc, nodes, selector) {
-    var text = et.tostring(nodes, { xml_declaration: false });
-        obj = plist.parseStringSync("<plist>"+text+"</plist>");
+module.exports = {
+    graftPLIST:function (doc, xml, selector) {
+        var obj = plist.parseStringSync("<plist>"+xml+"</plist>");
 
-    var node = doc[selector];
-    if (node && Array.isArray(node) && Array.isArray(obj))
-        doc[selector] = node.concat(obj);
-    else
-        doc[selector] = obj;
+        var node = doc[selector];
+        if (node && Array.isArray(node) && Array.isArray(obj))
+            doc[selector] = node.concat(obj);
+        else
+            doc[selector] = obj;
 
-    return true;
-}
-
-// removes node from doc at selector
-exports.prunePLIST = function(doc, nodes, selector) {
-    var text = et.tostring(nodes, { xml_declaration: false }),
-        obj = plist.parseStringSync("<plist>"+text+"</plist>");
-        
-    pruneOBJECT(doc, selector, obj);
+        return true;
+    },
+    // removes node from doc at selector
+    prunePLIST:function(doc, xml, selector) {
+        var obj = plist.parseStringSync("<plist>"+xml+"</plist>");
+            
+        pruneOBJECT(doc, selector, obj);
 
-    return true;
+        return true;
+    }
 }
 
 function pruneOBJECT(doc, selector, fragment) {
@@ -87,4 +86,3 @@ function nodeEqual(node1, node2) {
 function escapeRE(str) {
      return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\$&");
 };
- 


Mime
View raw message