Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8954210DD9 for ; Thu, 12 Sep 2013 18:15:45 +0000 (UTC) Received: (qmail 75301 invoked by uid 500); 12 Sep 2013 18:14:53 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 74710 invoked by uid 500); 12 Sep 2013 18:14:43 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 73707 invoked by uid 99); 12 Sep 2013 18:14:32 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Sep 2013 18:14:32 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 99032161F1; Thu, 12 Sep 2013 18:14:32 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: steven@apache.org To: commits@cordova.apache.org Date: Thu, 12 Sep 2013 18:14:54 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [26/40] 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/ffos Commit: c2461bc946555a3f43928d35ba1768c3cdcff03a Parents: d9ee339 Author: jbondc Authored: Mon Sep 2 09:53:40 2013 -0400 Committer: Andrew Grieve 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;