You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2013/03/04 20:32:50 UTC

[89/91] [abbrv] git commit: [ios] add support

[ios] add <access /> support


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

Branch: refs/heads/master
Commit: ae414a1b40fff5077e7e95e08fc044d65bf8b7a8
Parents: 780c8d0
Author: Brett Rudd <br...@gmail.com>
Authored: Sun Feb 17 19:34:20 2013 -0800
Committer: Brett Rudd <br...@gmail.com>
Committed: Wed Feb 20 18:13:57 2013 -0800

----------------------------------------------------------------------
 platforms/ios.js      |   65 +++++++++++++++++++++++++++++---------------
 test/ios-install.js   |    7 ++++-
 test/ios-uninstall.js |    2 +
 3 files changed, 51 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ae414a1b/platforms/ios.js
----------------------------------------------------------------------
diff --git a/platforms/ios.js b/platforms/ios.js
index ae550fb..d3c420d 100644
--- a/platforms/ios.js
+++ b/platforms/ios.js
@@ -227,15 +227,22 @@ function updateConfigXml(action, config_path, plugin_et) {
     var hosts = plugin_et.findall('./access'),
         platformTag = plugin_et.find('./platform[@name="ios"]'), // FIXME: can probably do better than this
         plistEle = platformTag.find('./plugins-plist'), // use this for older that have plugins-plist
-        pl,
-        external_hosts = [];
+		configChanges = getConfigChanges(platformTag),
+	    base_config_path = path.basename(config_path);
 
     // edit configuration files
     var xmlDoc = xml_helpers.parseElementtreeSync(config_path),
-        output;
+        output,
+		pListOnly = plistEle;
+
+	if (configChanges[path.basename(config_path)]) {	
+		configChanges[path.basename(config_path)].forEach(function (val) {
+			if (val.find("plugin")) pListOnly = false;
+		});
+	}
 
-    if (plistEle) {
-        // if the plugin supports the old plugins-plist elemtn..
+    if (pListOnly) {
+        // if the plugin supports the old plugins-plist element only
         var name = plistEle.attrib.key;
         var value = plistEle.attrib.string;
         var pluginsEl = xmlDoc.find('plugins');
@@ -248,25 +255,39 @@ function updateConfigXml(action, config_path, plugin_et) {
             var culprit = pluginsEl.find("plugin[@name='"+name+"']");
             pluginsEl.remove(0, culprit);
         }
-    } else {
-        var configChanges = getConfigChanges(platformTag);
-        var base_config_path = path.basename(config_path);
-        configChanges[base_config_path].forEach(function (configNode) {
-            var selector = configNode.attrib["parent"],
-                children = configNode.findall('*');
-
-            if( action == 'install') {
-                if (!xml_helpers.graftXML(xmlDoc, children, selector)) {
-                    throw new Error('failed to add children to ' + filename);
-                }
-            } else {
-                if (!xml_helpers.pruneXML(xmlDoc, children, selector)) {
-                    throw new Error('failed to remove children from' + filename);
-                }
-            }
-        });
 
     }
+
+	// add whitelist hosts
+	root = et.Element("config-file");
+	root.attrib['parent'] = '.'
+    hosts.forEach(function (tag) {
+		root.append(tag);
+	});
+
+	if (root.len()) {
+		(configChanges[path.basename(config_path)]) ?
+        	configChanges[path.basename(config_path)].push(root) :
+        	configChanges[path.basename(config_path)] = [root];
+	}
+
+	if (configChanges[path.basename(config_path)]) {
+
+	    configChanges[base_config_path].forEach(function (configNode) {
+	        var selector = configNode.attrib["parent"],
+	            children = configNode.findall('*');
+	        if( action == 'install') {
+	            if (!xml_helpers.graftXML(xmlDoc, children, selector)) {
+	                throw new Error('failed to add children to ' + filename);
+	            }
+	        } else {
+	            if (!xml_helpers.pruneXML(xmlDoc, children, selector)) {
+	                throw new Error('failed to remove children from' + filename);
+	            }
+	        }
+		});
+	}
+
     output = xmlDoc.write({indent: 4});
     fs.writeFileSync(config_path, output);
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ae414a1b/test/ios-install.js
----------------------------------------------------------------------
diff --git a/test/ios-install.js b/test/ios-install.js
index 7292b67..97b750e 100644
--- a/test/ios-install.js
+++ b/test/ios-install.js
@@ -137,7 +137,9 @@ exports['should edit config.xml'] = function (test) {
                     '[@value="WebNotifications"]';
 
     test.ok(pluginsDoc.find(expected));
-
+	test.equal(pluginsDoc.findall("access").length, 3, "/access");
+	test.equal(pluginsDoc.findall("access")[1].attrib["origin"], "build.phonegap.com")
+    test.equal(pluginsDoc.findall("access")[2].attrib["origin"], "s3.amazonaws.com")
     test.done();
 }
 
@@ -160,6 +162,9 @@ exports['should edit config.xml even when using old <plugins-plist> approach'] =
                     '[@value="PGSQLitePlugin"]';
 
     test.ok(pluginsDoc.find(expected));
+	test.equal(pluginsDoc.findall("access").length, 3, "/access");
+	test.equal(pluginsDoc.findall("access")[1].attrib["origin"], "build.phonegap.com")
+    test.equal(pluginsDoc.findall("access")[2].attrib["origin"], "s3.amazonaws.com")
 
     test.done();
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/ae414a1b/test/ios-uninstall.js
----------------------------------------------------------------------
diff --git a/test/ios-uninstall.js b/test/ios-uninstall.js
index ee5483b..bb7837a 100644
--- a/test/ios-uninstall.js
+++ b/test/ios-uninstall.js
@@ -143,6 +143,7 @@ exports['should edit config.xml even when using old <plugins-plist> approach'] =
                     '[@value="PGSQLitePlugin"]';
 
     test.ok(!pluginsDoc.find(expected));
+	test.equal(pluginsDoc.findall("access").length, 1, "/access");
 
     test.done();
 }
@@ -168,6 +169,7 @@ exports['should edit config.xml'] = function (test) {
                     '[@value="WebNotifications"]';
 
     test.ok(!pluginsDoc.find(expected));
+	test.equal(pluginsDoc.findall("access").length, 1, "/access");
 
     test.done();
 }