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/04/23 22:56:05 UTC
git commit: removing unused element code. android
handler install specs done.
Updated Branches:
refs/heads/future 1f8b525b7 -> 7d9574b25
removing unused <library-file> element code. android handler install specs done.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/7d9574b2
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/7d9574b2
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/7d9574b2
Branch: refs/heads/future
Commit: 7d9574b256dd920265b5396f8bacdac70eaf2a93
Parents: 1f8b525
Author: Fil Maj <ma...@gmail.com>
Authored: Tue Apr 23 13:56:01 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Tue Apr 23 13:56:01 2013 -0700
----------------------------------------------------------------------
spec/platforms/android.spec.js | 65 +++++++++++++++++++++++++++-------
src/install.js | 3 +-
src/platforms/android.js | 22 +++--------
src/util/plugins.js | 1 +
src/util/search-and-replace.js | 24 ++++++------
5 files changed, 71 insertions(+), 44 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/7d9574b2/spec/platforms/android.spec.js
----------------------------------------------------------------------
diff --git a/spec/platforms/android.spec.js b/spec/platforms/android.spec.js
index 4cc1724..0dd06b9 100644
--- a/spec/platforms/android.spec.js
+++ b/spec/platforms/android.spec.js
@@ -6,9 +6,13 @@ var android = require('../../src/platforms/android'),
et = require('elementtree'),
os = require('osenv'),
temp = path.join(os.tmpdir(), 'plugman'),
+ xml_helpers = require('../../src/util/xml-helpers'),
+ plugins_module = require('../../src/util/plugins'),
dummyplugin = path.join(__dirname, '..', 'plugins', 'DummyPlugin'),
faultyplugin = path.join(__dirname, '..', 'plugins', 'FaultyPlugin'),
- android_one_project = path.join(__dirname, '..', 'projects', 'android_one', '*');
+ variableplugin = path.join(__dirname, '..', 'plugins', 'VariablePlugin'),
+ android_one_project = path.join(__dirname, '..', 'projects', 'android_one', '*'),
+ android_two_project = path.join(__dirname, '..', 'projects', 'android_two', '*');
var xml_path = path.join(dummyplugin, 'plugin.xml')
, xml_text = fs.readFileSync(xml_path, 'utf-8')
@@ -29,6 +33,14 @@ platformTag = plugin_et.find('./platform[@name="android"]');
var invalid_source = platformTag.findall('./source-file');
var faulty_id = plugin_et._root.attrib['id'];
+xml_path = path.join(variableplugin, 'plugin.xml')
+xml_text = fs.readFileSync(xml_path, 'utf-8')
+plugin_et = new et.ElementTree(et.XML(xml_text));
+platformTag = plugin_et.find('./platform[@name="android"]');
+
+var variable_id = plugin_et._root.attrib['id'];
+var variable_configs = platformTag.findall('./config-file');
+
function copyArray(arr) {
return Array.prototype.slice.call(arr, 0);
}
@@ -47,12 +59,15 @@ describe('android project handler', function() {
describe('installation', function() {
beforeEach(function() {
shell.mkdir('-p', temp);
- shell.cp('-rf', android_one_project, temp);
});
afterEach(function() {
shell.rm('-rf', temp);
});
describe('of <source-file> elements', function() {
+ beforeEach(function() {
+ shell.cp('-rf', android_one_project, temp);
+ });
+
it('should copy stuff from one location to another by calling common.straightCopy', function() {
var source = copyArray(valid_source);
var s = spyOn(common, 'straightCopy');
@@ -78,17 +93,42 @@ describe('android project handler', function() {
}).toThrow('"' + target + '" already exists!');
});
});
- describe('of <library-file> elements', function() {
- it('should copy stuff from one location to another by calling common.straightCopy');
- it('should throw if source file cannot be found');
- it('should throw if target file already exists');
- });
describe('of <config-file> elements', function() {
- it('should only target config.xml if that is applicable');
- it('should only target plugins.xml if that is applicable');
- it('should call into xml helper\'s graftXML');
+ it('should only target config.xml if that is applicable', function() {
+ var config = copyArray(configChanges);
+ shell.cp('-rf', android_two_project, temp);
+ var s = spyOn(xml_helpers, 'parseElementtreeSync').andCallThrough();
+ android.install(config, dummy_id, temp, dummyplugin, {});
+ expect(s).toHaveBeenCalledWith(path.join(temp, 'res', 'xml', 'config.xml'));
+ expect(s).not.toHaveBeenCalledWith(path.join(temp, 'res', 'xml', 'plugins.xml'));
+ });
+ it('should only target plugins.xml if that is applicable', function() {
+ shell.cp('-rf', android_one_project, temp);
+ var config = copyArray(configChanges);
+ var s = spyOn(xml_helpers, 'parseElementtreeSync').andCallThrough();
+ android.install(config, dummy_id, temp, dummyplugin, {});
+ expect(s).not.toHaveBeenCalledWith(path.join(temp, 'res', 'xml', 'config.xml'));
+ expect(s).toHaveBeenCalledWith(path.join(temp, 'res', 'xml', 'plugins.xml'));
+ });
+ it('should call into xml helper\'s graftXML', function() {
+ shell.cp('-rf', android_one_project, temp);
+ var config = copyArray(configChanges);
+ var s = spyOn(xml_helpers, 'graftXML').andReturn(true);
+ android.install(config, dummy_id, temp, dummyplugin, {});
+ expect(s).toHaveBeenCalled();
+ });
+ });
+ it('should call into plugins\'s searchAndReplace to interpolate variables properly', function() {
+ shell.cp('-rf', android_one_project, temp);
+ var config = copyArray(variable_configs);
+ var s = spyOn(plugins_module, 'searchAndReplace');
+ var vars = {
+ 'API_KEY':'batcountry'
+ };
+ android.install(config, variable_id, temp, variableplugin, vars);
+ expect(s).toHaveBeenCalledWith(path.resolve(temp, 'AndroidManifest.xml'), vars);
+ expect(s).toHaveBeenCalledWith(path.resolve(temp, 'res', 'xml', 'plugins.xml'), vars);
});
- it('should interpolate variables properly');
});
describe('uninstallation', function() {
@@ -96,9 +136,6 @@ describe('android project handler', function() {
it('should remove stuff by calling common.deleteJava');
it('should remove empty dirs from java src dir heirarchy');
});
- describe('of <library-file> elements', function() {
- it('should remove stuff using fs.unlinkSync');
- });
describe('of <config-file> elements', function() {
it('should only target config.xml if that is applicable');
it('should only target plugins.xml if that is applicable');
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/7d9574b2/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index 3fcd2e4..def44b8 100644
--- a/src/install.js
+++ b/src/install.js
@@ -73,7 +73,6 @@ function runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variable
// parse plugin.xml into transactions
var txs = [];
var sourceFiles = platformTag.findall('./source-file'),
- libFiles = platformTag.findall('./library-file'),
headerFiles = platformTag.findall('./header-file'),
resourceFiles = platformTag.findall('./resource-file'),
assets = platformTag.findall('./asset'),
@@ -83,7 +82,7 @@ function runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variable
assets = assets.concat(plugin_et.findall('./asset'));
- txs = txs.concat(sourceFiles, libFiles, headerFiles, resourceFiles, frameworks, configChanges, assets, pluginsPlist);
+ txs = txs.concat(sourceFiles, headerFiles, resourceFiles, frameworks, configChanges, assets, pluginsPlist);
// pass platform-specific transactions into install
handler.install(txs, plugin_id, project_dir, plugin_dir, filtered_variables, function(err) {
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/7d9574b2/src/platforms/android.js
----------------------------------------------------------------------
diff --git a/src/platforms/android.js b/src/platforms/android.js
index 6b0ef46..e476021 100644
--- a/src/platforms/android.js
+++ b/src/platforms/android.js
@@ -22,7 +22,7 @@ var fs = require('fs') // use existsSync in 0.6.x
, shell = require('shelljs')
, common = require('./common')
, getConfigChanges = require(path.join(__dirname, '..', 'util', 'config-changes'))
- , searchAndReplace = require(path.join(__dirname, '..', 'util', 'search-and-replace'))
+ , plugins_module = require(path.join(__dirname, '..', 'util', 'plugins'))
, xml_helpers = require(path.join(__dirname, '..', 'util', 'xml-helpers'));
module.exports = {
@@ -64,15 +64,6 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir, variables
common.deleteJava(project_dir, destFile);
}
break;
- case 'library-file':
- var destFile = path.join(mod.attrib['target-dir'], path.basename(mod.attrib['src']));
-
- if (action == 'install') {
- common.straightCopy(plugin_dir, mod.attrib['src'], project_dir, destFile);
- } else {
- fs.unlinkSync(path.resolve(project_dir, destFile));
- }
- break;
case 'config-file':
// Only modify config files that exist.
var config_file = path.resolve(project_dir, mod.attrib['target']);
@@ -83,11 +74,11 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir, variables
if (action == 'install') {
if (!xml_helpers.graftXML(xmlDoc, children, selector)) {
- throw new Error('failed to add config-file children to "' + selector + '" to "'+ filename + '"');
+ 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 "' + filename + '"');
+ throw new Error('failed to remove config-file children from "' + selector + '" from "' + config_file + '"');
}
}
@@ -123,8 +114,8 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir, variables
variables['PACKAGE_NAME'] = androidPackageName(project_dir);
var config_filename = path.resolve(project_dir, 'res', 'xml', 'config.xml');
if (!fs.existsSync(config_filename)) config_filename = path.resolve(project_dir, 'res', 'xml', 'plugins.xml');
- searchAndReplace(config_filename, variables);
- searchAndReplace(path.resolve(project_dir, 'AndroidManifest.xml'), variables);
+ plugins_module.searchAndReplace(config_filename, variables);
+ plugins_module.searchAndReplace(path.resolve(project_dir, 'AndroidManifest.xml'), variables);
}
if (callback) callback();
@@ -134,8 +125,7 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir, variables
// @param string project_dir the absolute path to the directory containing the project
// @return string the name of the package
function androidPackageName(project_dir) {
- var mDoc = xml_helpers.parseElementtreeSync(
- path.resolve(project_dir, 'AndroidManifest.xml'));
+ var mDoc = xml_helpers.parseElementtreeSync(path.resolve(project_dir, 'AndroidManifest.xml'));
return mDoc._root.attrib['package'];
}
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/7d9574b2/src/util/plugins.js
----------------------------------------------------------------------
diff --git a/src/util/plugins.js b/src/util/plugins.js
index 242cb1c..045f48c 100644
--- a/src/util/plugins.js
+++ b/src/util/plugins.js
@@ -27,6 +27,7 @@ var http = require('http'),
remote = require(path.join(__dirname, '..', '..', 'config', 'remote'));
module.exports = {
+ searchAndReplace:require('./search-and-replace'),
// Fetches plugin information from remote server
getPluginInfo:function(plugin_name, callback) {
var responded = false;
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/7d9574b2/src/util/search-and-replace.js
----------------------------------------------------------------------
diff --git a/src/util/search-and-replace.js b/src/util/search-and-replace.js
index dc1f931..39bd9c3 100644
--- a/src/util/search-and-replace.js
+++ b/src/util/search-and-replace.js
@@ -22,16 +22,16 @@ var glob = require('glob'),
fs = require('fs');
module.exports = function searchAndReplace(srcGlob, variables) {
- var files = glob.sync(srcGlob);
- for (var i in files) {
- var file = files[i];
- if (fs.lstatSync(file).isFile()) {
- var contents = fs.readFileSync(file, "utf-8");
- for (var key in variables) {
- var regExp = new RegExp("\\$" + key, "g");
- contents = contents.replace(regExp, variables[key]);
- }
- fs.writeFileSync(file, contents);
+ var files = glob.sync(srcGlob);
+ for (var i in files) {
+ var file = files[i];
+ if (fs.lstatSync(file).isFile()) {
+ var contents = fs.readFileSync(file, "utf-8");
+ for (var key in variables) {
+ var regExp = new RegExp("\\$" + key, "g");
+ contents = contents.replace(regExp, variables[key]);
+ }
+ fs.writeFileSync(file, contents);
+ }
}
- }
-}
\ No newline at end of file
+}