You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/09/04 19:59:18 UTC
[3/3] git commit: [CB-4714] Add -f option to 'plugin rm' to
forcefully remove a plugin.
[CB-4714] Add -f option to 'plugin rm' to forcefully remove a plugin.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/c2461bc9
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/c2461bc9
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/c2461bc9
Branch: refs/heads/master
Commit: c2461bc946555a3f43928d35ba1768c3cdcff03a
Parents: d9ee339
Author: jbondc <jb...@openmv.com>
Authored: Mon Sep 2 09:53:40 2013 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Sep 4 13:58:51 2013 -0400
----------------------------------------------------------------------
src/uninstall.js | 28 ++++++++++++++++++++--------
src/util/dependencies.js | 10 ++++++++--
2 files changed, 28 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c2461bc9/src/uninstall.js
----------------------------------------------------------------------
diff --git a/src/uninstall.js b/src/uninstall.js
index c0cddf5..f87ec20 100644
--- a/src/uninstall.js
+++ b/src/uninstall.js
@@ -44,8 +44,10 @@ module.exports.uninstallPlatform = function(platform, project_dir, id, plugins_d
module.exports.uninstallPlugin = function(id, plugins_dir, callback) {
var plugin_dir = path.join(plugins_dir, id);
- // If already removed, skip.
+
+ // If already removed, skip.
if (!fs.existsSync(plugin_dir)) {
+ // console.log("Skipped " + plugin_dir + " (not found)");
if (callback) callback();
return;
}
@@ -75,24 +77,34 @@ module.exports.uninstallPlugin = function(id, plugins_dir, callback) {
// possible options: cli_variables, www_dir, is_top_level
function runUninstall(actions, platform, project_dir, plugin_dir, plugins_dir, options, callback) {
- var xml_path = path.join(plugin_dir, 'plugin.xml')
- , plugin_et = xml_helpers.parseElementtreeSync(xml_path);
+ var xml_path = path.join(plugin_dir, 'plugin.xml');
+ if (!fs.existsSync(xml_path)) {
+ // log warning?
+ return;
+ }
+
+ var plugin_et = xml_helpers.parseElementtreeSync(xml_path);
var plugin_id = plugin_et._root.attrib['id'];
options = options || {};
- var dependency_info = dependencies.generate_dependency_info(plugins_dir, platform);
+ var dependency_info = dependencies.generate_dependency_info(plugins_dir, platform, 'remove');
var graph = dependency_info.graph;
var dependents = graph.getChain(plugin_id);
+ var forced = options.cmd && (options.cmd.indexOf('-f') + options.cmd.indexOf('-force') > -2);
var tlps = dependency_info.top_level_plugins;
var diff_arr = [];
tlps.forEach(function(tlp) {
if (tlp != plugin_id) {
var ds = graph.getChain(tlp);
if (options.is_top_level && ds.indexOf(plugin_id) > -1) {
- var err = new Error('Another top-level plugin (' + tlp + ') relies on plugin ' + plugin_id + ', therefore aborting uninstallation.');
- if (callback) return callback(err);
- else throw err;
+ if(forced) {
+ require('../plugman').emit('log', tlp + ' depends on '+ plugin_id + ', but forcing removal...');
+ } else {
+ var err = new Error('Another top-level plugin (' + tlp + ') relies on plugin ' + plugin_id + ', therefore aborting uninstallation.');
+ if (callback) return callback(err);
+ else throw err;
+ }
}
diff_arr.push(ds);
}
@@ -171,7 +183,7 @@ function handleUninstall(actions, platform, plugin_id, plugin_et, project_dir, w
// queue up the plugin so prepare can remove the config changes
config_changes.add_uninstalled_plugin_to_prepare_queue(plugins_dir, path.basename(plugin_dir), platform, is_top_level);
// call prepare after a successful uninstall
- require('./../plugman').prepare(project_dir, platform, plugins_dir);
+ require('../plugman').prepare(project_dir, platform, plugins_dir);
if (callback) callback();
}
});
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c2461bc9/src/util/dependencies.js
----------------------------------------------------------------------
diff --git a/src/util/dependencies.js b/src/util/dependencies.js
index 32e07eb..bf40eb1 100644
--- a/src/util/dependencies.js
+++ b/src/util/dependencies.js
@@ -1,10 +1,11 @@
var dep_graph = require('dep-graph'),
path = require('path'),
+ fs = require('fs'),
config_changes = require('./config-changes'),
xml_helpers = require('./xml-helpers');
module.exports = {
- generate_dependency_info:function(plugins_dir, platform) {
+ generate_dependency_info:function(plugins_dir, platform, context) {
var json = config_changes.get_platform_json(plugins_dir, platform);
var tlps = [];
var graph = new dep_graph();
@@ -18,7 +19,12 @@ module.exports = {
});
});
Object.keys(json.dependent_plugins).forEach(function(plug) {
- var xml = xml_helpers.parseElementtreeSync(path.join(plugins_dir, plug, 'plugin.xml'));
+ var xmlPath = path.join(plugins_dir, plug, 'plugin.xml');
+ if (context == 'remove' && !fs.existsSync(xmlPath)) {
+ return; // dependency may have been forcefully removed
+ }
+
+ var xml = xml_helpers.parseElementtreeSync(xmlPath);
var deps = xml.findall('dependency');
deps && deps.forEach(function(dep) {
var id = dep.attrib.id;