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

[88/91] [abbrv] git commit: [android] add support

[android] 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/780c8d0c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/780c8d0c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/780c8d0c

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

----------------------------------------------------------------------
 platforms/android.js          |   45 +++++++++++++++++++++++------------
 test/android-one-install.js   |   13 ++++++++++
 test/android-one-uninstall.js |   12 +++++++++
 test/android-two-install.js   |   13 ++++++++++
 test/android-two-uninstall.js |   12 +++++++++
 5 files changed, 79 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/780c8d0c/platforms/android.js
----------------------------------------------------------------------
diff --git a/platforms/android.js b/platforms/android.js
index f7ce866..e71a5e3 100644
--- a/platforms/android.js
+++ b/platforms/android.js
@@ -23,19 +23,37 @@ exports.handlePlugin = function (action, project_dir, plugin_dir, plugin_et) {
       , PACKAGE_NAME = androidPackageName(project_dir)
       , configChanges = getConfigChanges(platformTag);
 
-    // find which config-files we're interested in
+	// get config.xml filename
+	var config_xml_filename = 'res/xml/config.xml';
+    if(fs.existsSync(path.resolve(project_dir, 'res/xml/plugins.xml'))) {
+        config_xml_filename = 'res/xml/plugins.xml';
+    }
+
+    // collision detection 
+    if(action == "install" && pluginInstalled(plugin_et, project_dir, config_xml_filename)) {
+        throw "Plugin "+plugin_id+" already installed"
+    } else if(action == "uninstall" && !pluginInstalled(plugin_et, project_dir, config_xml_filename)) {
+        throw "Plugin "+plugin_id+" not installed"
+    }
+
+	root = et.Element("config-file");
+	root.attrib['parent'] = '.'
+    plugin_et.findall('./access').forEach(function (tag) { 
+		root.append(tag);
+	});
+
+	if (root.len()) {
+		(configChanges[config_xml_filename]) ?
+        	configChanges[config_xml_filename].push(root) :
+        	configChanges[config_xml_filename] = [root];
+	}
+
+	// find which config-files we're interested in
     Object.keys(configChanges).forEach(function (configFile) {
         if (!fs.existsSync(path.resolve(project_dir, configFile))) {
             delete configChanges[configFile];
         }
     });
-    
-    // collision detection 
-    if(action == "install" && pluginInstalled(plugin_et, project_dir)) {
-        throw "Plugin "+plugin_id+" already installed"
-    } else if(action == "uninstall" && !pluginInstalled(plugin_et, project_dir)) {
-        throw "Plugin "+plugin_id+" not installed"
-    }
 
     // move asset files
     assets.forEach(function (asset) {
@@ -114,7 +132,6 @@ exports.handlePlugin = function (action, project_dir, plugin_dir, plugin_et) {
         }
     })
 
-
     // edit configuration files
     Object.keys(configChanges).forEach(function (filename) {
         var filepath = path.resolve(project_dir, filename),
@@ -163,13 +180,9 @@ function androidPackageName(project_dir) {
     return mDoc._root.attrib['package'];
 }
 
-function pluginInstalled(plugin_et, project_dir) {
-    var filename = 'res/xml/config.xml';
-    if(fs.existsSync(path.resolve(project_dir, 'res/xml/plugins.xml'))) {
-        filename = 'res/xml/plugins.xml';
-    }
-    var tag_xpath = util.format('./platform[@name="android"]/config-file[@target="%s"]/plugin', filename);
+function pluginInstalled(plugin_et, project_dir, config_xml_filename) {
+    var tag_xpath = util.format('./platform[@name="android"]/config-file[@target="%s"]/plugin', config_xml_filename);
     var plugin_name = plugin_et.find(tag_xpath).attrib.name;
-    return (fs.readFileSync(path.resolve(project_dir, filename), 'utf8')
+    return (fs.readFileSync(path.resolve(project_dir, config_xml_filename), 'utf8')
            .match(new RegExp(plugin_name, "g")) != null);
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/780c8d0c/test/android-one-install.js
----------------------------------------------------------------------
diff --git a/test/android-one-install.js b/test/android-one-install.js
index ed417c0..4dd9d55 100644
--- a/test/android-one-install.js
+++ b/test/android-one-install.js
@@ -111,3 +111,16 @@ exports['should add ChildBrowser to AndroidManifest.xml'] = function (test) {
     test.ok(found);
     test.done();
 }
+
+exports['should add whitelist hosts'] = function (test) {
+	android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et);
+
+    var pluginsXmlPath = path.join(test_dir, 'projects', 'android_one', 'res', 'xml', 'plugins.xml');
+    var pluginsTxt = fs.readFileSync(pluginsXmlPath, 'utf-8'),
+        pluginsDoc = new et.ElementTree(et.XML(pluginsTxt));
+
+    test.equal(pluginsDoc.findall("access").length, 2, "/access");
+	test.equal(pluginsDoc.findall("access")[0].attrib["origin"], "build.phonegap.com")
+    test.equal(pluginsDoc.findall("access")[1].attrib["origin"], "s3.amazonaws.com")
+    test.done();
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/780c8d0c/test/android-one-uninstall.js
----------------------------------------------------------------------
diff --git a/test/android-one-uninstall.js b/test/android-one-uninstall.js
index dec6c09..4262ab8 100644
--- a/test/android-one-uninstall.js
+++ b/test/android-one-uninstall.js
@@ -130,3 +130,15 @@ exports['should remove ChildBrowser from AndroidManifest.xml'] = function (test)
     test.ok(!found);
     test.done();
 }
+
+exports['should remove whitelist hosts'] = function (test) {
+	android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et);
+	android.handlePlugin('uninstall', test_project_dir, test_plugin_dir, plugin_et);
+    
+	var pluginsXmlPath = path.join(test_dir, 'projects', 'android_one', 'res', 'xml', 'plugins.xml');
+    var pluginsTxt = fs.readFileSync(pluginsXmlPath, 'utf-8'),
+        pluginsDoc = new et.ElementTree(et.XML(pluginsTxt));
+
+    test.equal(pluginsDoc.findall("access").length, 0, "/access");
+    test.done();
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/780c8d0c/test/android-two-install.js
----------------------------------------------------------------------
diff --git a/test/android-two-install.js b/test/android-two-install.js
index ba6c1ac..c4999ee 100644
--- a/test/android-two-install.js
+++ b/test/android-two-install.js
@@ -123,3 +123,16 @@ exports['should not install a plugin that is already installed'] = function (tes
 
     test.done();
 }
+
+exports['should add whitelist hosts'] = function (test) {
+	android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et);
+
+    var pluginsXmlPath = path.join(test_dir, 'projects', 'android_two', 'res', 'xml', 'config.xml');
+    var pluginsTxt = fs.readFileSync(pluginsXmlPath, 'utf-8'),
+        pluginsDoc = new et.ElementTree(et.XML(pluginsTxt));
+
+    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/780c8d0c/test/android-two-uninstall.js
----------------------------------------------------------------------
diff --git a/test/android-two-uninstall.js b/test/android-two-uninstall.js
index 86ce80f..9220a94 100644
--- a/test/android-two-uninstall.js
+++ b/test/android-two-uninstall.js
@@ -131,6 +131,18 @@ exports['should remove ChildBrowser from AndroidManifest.xml'] = function (test)
     test.done();
 }
 
+exports['should remove whitelist hosts'] = function (test) {
+    android.handlePlugin('install', test_project_dir, test_plugin_dir, plugin_et);
+	android.handlePlugin('uninstall', test_project_dir, test_plugin_dir, plugin_et);
+	
+	var pluginsXmlPath = path.join(test_dir, 'projects', 'android_two', 'res', 'xml', 'config.xml');
+    var pluginsTxt = fs.readFileSync(pluginsXmlPath, 'utf-8'),
+        pluginsDoc = new et.ElementTree(et.XML(pluginsTxt));
+
+    test.equal(pluginsDoc.findall("access").length, 1, "/access");
+    test.done();
+}
+
 exports['should not uninstall a plugin that is not installed'] = function (test) {
     var jsPath = path.join(test_dir, 'projects', 'android_two', 'assets', 'www', 'childbrowser.js');