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/24 01:01:14 UTC
[46/50] [abbrv] git commit: finished android handler specs. fixed a
bug with asset removal (yay tests!). removed retrieving plugins during an
uninstall.
finished android handler specs. fixed a bug with asset removal (yay tests!). removed retrieving plugins during an uninstall.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/c0de3de1
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/c0de3de1
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/c0de3de1
Branch: refs/heads/master
Commit: c0de3de12de15f3045f8e2723f704add26430885
Parents: 7d9574b
Author: Fil Maj <ma...@gmail.com>
Authored: Tue Apr 23 14:39:31 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Tue Apr 23 14:39:31 2013 -0700
----------------------------------------------------------------------
spec/platforms/android.spec.js | 82 ++++++++++++++++++++++++++++++++---
src/platforms/android.js | 4 +-
src/uninstall.js | 27 +-----------
3 files changed, 78 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c0de3de1/spec/platforms/android.spec.js
----------------------------------------------------------------------
diff --git a/spec/platforms/android.spec.js b/spec/platforms/android.spec.js
index 0dd06b9..a009908 100644
--- a/spec/platforms/android.spec.js
+++ b/spec/platforms/android.spec.js
@@ -1,11 +1,13 @@
var android = require('../../src/platforms/android'),
common = require('../../src/platforms/common'),
+ install = require('../../src/install'),
path = require('path'),
fs = require('fs'),
shell = require('shelljs'),
et = require('elementtree'),
os = require('osenv'),
temp = path.join(os.tmpdir(), 'plugman'),
+ plugins_dir = path.join(temp, 'cordova', 'plugins'),
xml_helpers = require('../../src/util/xml-helpers'),
plugins_module = require('../../src/util/plugins'),
dummyplugin = path.join(__dirname, '..', 'plugins', 'DummyPlugin'),
@@ -132,18 +134,84 @@ describe('android project handler', function() {
});
describe('uninstallation', function() {
+ beforeEach(function() {
+ shell.mkdir('-p', temp);
+ shell.mkdir('-p', plugins_dir);
+ shell.cp('-rf', android_two_project, temp);
+ shell.cp('-rf', dummyplugin, plugins_dir);
+ });
+ afterEach(function() {
+ shell.rm('-rf', temp);
+ });
describe('of <source-file> elements', function() {
- it('should remove stuff by calling common.deleteJava');
- it('should remove empty dirs from java src dir heirarchy');
+ it('should remove stuff by calling common.deleteJava', function(done) {
+ var s = spyOn(common, 'deleteJava');
+ install('android', temp, 'DummyPlugin', plugins_dir, {}, function() {
+ var source = copyArray(valid_source);
+ android.uninstall(source, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
+ expect(s).toHaveBeenCalledWith(temp, 'src/com/phonegap/plugins/dummyplugin/DummyPlugin.java');
+ done();
+ });
+ });
});
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 pruneXML');
+ it('should only target config.xml if that is applicable', function(done) {
+ var config = copyArray(configChanges);
+ var s = spyOn(xml_helpers, 'parseElementtreeSync').andCallThrough();
+ install('android', temp, 'DummyPlugin', plugins_dir, {}, function() {
+ var config = copyArray(configChanges);
+ android.uninstall(config, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
+ expect(s).toHaveBeenCalledWith(path.join(temp, 'res', 'xml', 'config.xml'));
+ expect(s).not.toHaveBeenCalledWith(path.join(temp, 'res', 'xml', 'plugins.xml'));
+ done();
+ });
+ });
+ it('should only target plugins.xml if that is applicable', function(done) {
+ shell.rm('-rf', temp);
+ shell.mkdir('-p', temp);
+ shell.mkdir('-p', plugins_dir);
+ shell.cp('-rf', android_one_project, temp);
+ shell.cp('-rf', dummyplugin, plugins_dir);
+ var config = copyArray(configChanges);
+ var s = spyOn(xml_helpers, 'parseElementtreeSync').andCallThrough();
+ install('android', temp, 'DummyPlugin', plugins_dir, {}, function() {
+ var config = copyArray(configChanges);
+ android.uninstall(config, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
+ expect(s).not.toHaveBeenCalledWith(path.join(temp, 'res', 'xml', 'config.xml'));
+ expect(s).toHaveBeenCalledWith(path.join(temp, 'res', 'xml', 'plugins.xml'));
+ done();
+ });
+ });
+ it('should call into xml helper\'s pruneXML', function(done) {
+ var config = copyArray(configChanges);
+ install('android', temp, 'DummyPlugin', plugins_dir, {}, function() {
+ var s = spyOn(xml_helpers, 'pruneXML').andReturn(true);
+ android.uninstall(config, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
+ expect(s).toHaveBeenCalled();
+ done();
+ });
+ });
});
describe('of <asset> elements', function() {
- it('should remove www\'s plugins <plugin-id> directory');
- it('should remove stuff specified by the element');
+ it('should remove www\'s plugins/<plugin-id> directory', function(done) {
+ var as = copyArray(assets);
+ install('android', temp, 'DummyPlugin', plugins_dir, {}, function() {
+ var s = spyOn(shell, 'rm');
+ android.uninstall(as, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
+ expect(s).toHaveBeenCalledWith('-rf', path.join(temp, 'assets', 'www', 'plugins', dummy_id));
+ done();
+ });
+ });
+ it('should remove stuff specified by the element', function(done) {
+ var as = copyArray(assets);
+ install('android', temp, 'DummyPlugin', plugins_dir, {}, function() {
+ var s = spyOn(shell, 'rm');
+ android.uninstall(as, dummy_id, temp, path.join(plugins_dir, 'DummyPlugin'));
+ expect(s).toHaveBeenCalledWith('-rf', path.join(temp, 'assets', 'www', 'dummyplugin.js'));
+ expect(s).toHaveBeenCalledWith('-rf', path.join(temp, 'assets', 'www', 'dummyplugin'));
+ done();
+ });
+ });
});
});
});
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c0de3de1/src/platforms/android.js
----------------------------------------------------------------------
diff --git a/src/platforms/android.js b/src/platforms/android.js
index e476021..8b696a6 100644
--- a/src/platforms/android.js
+++ b/src/platforms/android.js
@@ -89,8 +89,8 @@ function handlePlugin(action, plugin_id, txs, project_dir, plugin_dir, variables
case 'asset':
if (action == 'uninstall') {
var target = mod.attrib.target;
- shell.rm('-rf', path.resolve(module.exports.www_dir(), target));
- shell.rm('-rf', path.resolve(module.exports.www_dir(), 'plugins', plugin_id));
+ shell.rm('-rf', path.resolve(module.exports.www_dir(project_dir), target));
+ shell.rm('-rf', path.resolve(module.exports.www_dir(project_dir), 'plugins', plugin_id));
}
break;
default:
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c0de3de1/src/uninstall.js
----------------------------------------------------------------------
diff --git a/src/uninstall.js b/src/uninstall.js
index 2625c44..811660f 100644
--- a/src/uninstall.js
+++ b/src/uninstall.js
@@ -38,7 +38,6 @@ module.exports = function uninstallPlugin(platform, project_dir, name, plugins_d
// Check that the plugin has already been fetched.
var plugin_dir = path.join(plugins_dir, name);
- var plugin_xml_path = path.join(plugin_dir, 'plugin.xml');
if (!fs.existsSync(plugin_dir)) {
var err = new Error('Plugin "' + name + '" not found. Already uninstalled?');
@@ -49,29 +48,5 @@ module.exports = function uninstallPlugin(platform, project_dir, name, plugins_d
else throw err;
}
- // TODO: uninstall if plugin does not exist? this should not be here.
- if (!fs.existsSync(plugin_xml_path)) {
- // try querying the plugin database
- plugins.getPluginInfo(plugin_dir,
- function(err, plugin_info) {
- if (err) {
- var err_obj = new Error('uninstall failed. plugin.xml at "' + plugin_xml_path + '" not found and couldnt query remote server for information about the plugin because ' + err.message);
- if (callback) callback(err_obj);
- else throw err_obj;
- } else {
- plugins.clonePluginGitRepo(plugin_info.url, plugins_dir, function(err, plugin_dir) {
- if (err) {
- var err_obj = new Error('uninstall failed. plugin.xml at "' + plugin_xml_path + '" not found and couldnt clone plugin repo because ' + err.message);
- if (callback) callback(err_obj);
- else throw err_obj;
- } else {
- runUninstall(platform, project_dir, plugin_dir, plugins_dir, cli_variables, callback);
- }
- });
- }
- }
- );
- } else {
- runUninstall(platform, project_dir, plugin_dir, plugins_dir, cli_variables, callback);
- }
+ runUninstall(platform, project_dir, plugin_dir, plugins_dir, cli_variables, callback);
};