cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject [3/6] git commit: android projects now adhere to whitelist specified by config.xml
Date Tue, 06 Nov 2012 21:03:02 GMT
android projects now adhere to whitelist specified by config.xml


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/commit/9e7b7779
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/tree/9e7b7779
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/diff/9e7b7779

Branch: refs/heads/cordova-client
Commit: 9e7b7779e60a6a4b2c73a8721c44b34fe46996f5
Parents: f58c26e
Author: Fil Maj <maj.fil@gmail.com>
Authored: Tue Nov 6 12:44:15 2012 -0800
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Tue Nov 6 12:44:15 2012 -0800

----------------------------------------------------------------------
 spec/metadata/android_parser.spec.js |   15 +++++++++++++++
 src/metadata/android_parser.js       |   15 +++++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/9e7b7779/spec/metadata/android_parser.spec.js
----------------------------------------------------------------------
diff --git a/spec/metadata/android_parser.spec.js b/spec/metadata/android_parser.spec.js
index 18adccc..6371e6b 100644
--- a/spec/metadata/android_parser.spec.js
+++ b/spec/metadata/android_parser.spec.js
@@ -8,6 +8,7 @@ var android_parser = require('../../src/metadata/android_parser'),
     android_path = path.join(__dirname, '..', 'fixtures', 'projects', 'native', 'android'),
     android_strings = path.join(android_path, 'res', 'values', 'strings.xml'),
     android_manifest = path.join(android_path, 'AndroidManifest.xml'),
+    android_config = path.join(android_path, 'res', 'xml', 'config.xml'),
     tempDir = path.join(__dirname, '..', '..', 'temp'),
     cordova = require('../../cordova');
 
@@ -16,6 +17,7 @@ var cwd = process.cwd();
 var original_strings = fs.readFileSync(android_strings, 'utf-8');
 var original_manifest = fs.readFileSync(android_manifest, 'utf-8');
 var original_config = fs.readFileSync(cfg_path, 'utf-8');
+var original_android_config = fs.readFileSync(android_config, 'utf-8');
 
 describe('android project parser', function() {
     it('should throw an exception with a path that is not a native android project', function()
{
@@ -42,6 +44,7 @@ describe('android project parser', function() {
             fs.writeFileSync(android_strings, original_strings, 'utf-8');
             fs.writeFileSync(android_manifest, original_manifest, 'utf-8');
             fs.writeFileSync(cfg_path, original_config, 'utf-8');
+            fs.writeFileSync(android_config, original_android_config, 'utf-8');
         });
         it('should throw an exception if a non config_parser object is passed into it', function()
{
             expect(function() {
@@ -74,6 +77,18 @@ describe('android project parser', function() {
             expect(fs.existsSync(javs)).toBe(true);
             expect(fs.readFileSync(javs, 'utf-8')).toMatch(/package ca.filmaj.dewd/i);
         });
+        it('should update the whitelist properly', function() {
+            config.access.remove('*');
+            config.access.add('http://apache.org');
+            config.access.add('http://github.com');
+            project.update_from_config(config);
+
+            var native_config = new et.ElementTree(et.XML(fs.readFileSync(android_config,
'utf-8')));
+            var as = native_config.findall('access');
+            expect(as.length).toEqual(2);
+            expect(as[0].attrib.origin).toEqual('http://apache.org');
+            expect(as[1].attrib.origin).toEqual('http://github.com');
+        });
     });
 
     describe('update_www method', function() {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-labs/blob/9e7b7779/src/metadata/android_parser.js
----------------------------------------------------------------------
diff --git a/src/metadata/android_parser.js b/src/metadata/android_parser.js
index ffa06ea..f49cc8d 100644
--- a/src/metadata/android_parser.js
+++ b/src/metadata/android_parser.js
@@ -12,6 +12,7 @@ module.exports = function android_parser(project) {
     this.path = project;
     this.strings = path.join(this.path, 'res', 'values', 'strings.xml');
     this.manifest = path.join(this.path, 'AndroidManifest.xml');
+    this.android_config = path.join(this.path, 'res', 'xml', 'config.xml');
 };
 
 module.exports.prototype = {
@@ -19,11 +20,13 @@ module.exports.prototype = {
         if (config instanceof config_parser) {
         } else throw 'update_from_config requires a config_parser object';
 
+        // Update app name by editing res/values/strings.xml
         var name = config.name();
         var strings = new et.ElementTree(et.XML(fs.readFileSync(this.strings, 'utf-8')));
         strings.find('string[@name="app_name"]').text = name;
         fs.writeFileSync(this.strings, strings.write({indent: 4}), 'utf-8');
 
+        // Update package name by changing the AndroidManifest id and moving the entry class
around to the proper package directory
         var manifest = new et.ElementTree(et.XML(fs.readFileSync(this.manifest, 'utf-8')));
         var pkg = config.packageName();
         var orig_pkg = manifest.getroot().attrib.package;
@@ -38,7 +41,19 @@ module.exports.prototype = {
         var javs_contents = fs.readFileSync(orig_javs, 'utf-8');
         javs_contents = javs_contents.replace(/package [\w\.]*;/, 'package ' + pkg + ';');
         fs.writeFileSync(new_javs, javs_contents, 'utf-8');
+
+        // Update whitelist by changing res/xml/config.xml
+        var android_cfg_xml = new config_parser(this.android_config);
+        // clean out all existing access elements first
+        android_cfg_xml.access.get().forEach(function(uri) {
+            android_cfg_xml.access.remove(uri);
+        });
+        // add only the ones specified in the www/config.xml file
+        config.access.get().forEach(function(uri) {
+            android_cfg_xml.access.add(uri);
+        });
     },
+
     update_www:function() {
         var projectRoot = util.isCordova(process.cwd());
         var www = path.join(projectRoot, 'www');


Mime
View raw message