0.9.2. uninstallPlatform should never invoke uninstallPlugin. uninstallPlugin 
needs to recurse for dependencies.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/b421b7b1
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/b421b7b1
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/b421b7b1

Branch: refs/heads/plugman-registry
Commit: b421b7b19d7b28a73a6c985393ae34cbce338082
Parents: e6d488e
Author: Fil Maj <[email protected]>
Authored: Thu Jul 11 12:16:02 2013 -0700
Committer: Fil Maj <[email protected]>
Committed: Thu Jul 11 12:16:02 2013 -0700

----------------------------------------------------------------------
 package.json           |  2 +-
 spec/uninstall.spec.js | 38 +++++++++++++++++++++++++++++++-------
 src/uninstall.js       | 33 +++++++++++++++++++++------------
 3 files changed, 53 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/b421b7b1/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 2453a4f..1c0f0d6 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
   "author": "Andrew Lunny <[email protected]>",
   "name": "plugman",
   "description": "install/uninstall Cordova plugins",
-  "version": "0.9.1",
+  "version": "0.9.2",
   "repository": {
     "type": "git",
     "url": "git://git-wip-us.apache.org/repos/asf/cordova-plugman.git"

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/b421b7b1/spec/uninstall.spec.js
----------------------------------------------------------------------
diff --git a/spec/uninstall.spec.js b/spec/uninstall.spec.js
index 3c6a73e..0b6dd0c 100644
--- a/spec/uninstall.spec.js
+++ b/spec/uninstall.spec.js
@@ -60,11 +60,9 @@ describe('uninstallPlatform', function() {
         });
 
         describe('with dependencies', function() {
-            var uninstall_spy, parseET;
+            var parseET, emit;
             beforeEach(function() {
-                uninstall_spy = spyOn(uninstall, 
'uninstallPlugin').andCallFake(function(id, dir, cb) {
-                    cb();
-                });
+                emit = spyOn(plugman, 'emit');
                 parseET = spyOn(xml_helpers, 
'parseElementtreeSync').andReturn({
                     _root:{
                         attrib:{}
@@ -98,8 +96,7 @@ describe('uninstallPlatform', function() {
                     return obj;
                 });
                 uninstall.uninstallPlatform('android', temp, dummyplugin, 
plugins_dir, {});
-                expect(uninstall_spy).toHaveBeenCalledWith('one', plugins_dir, 
jasmine.any(Function));
-                expect(uninstall_spy).toHaveBeenCalledWith('two', plugins_dir, 
jasmine.any(Function));
+                expect(emit).toHaveBeenCalledWith('log', 'Uninstalling 2 
dangling dependent plugins...');
             });
             it('should not uninstall any dependencies that are relied on by 
other plugins');
         });
@@ -121,8 +118,9 @@ describe('uninstallPlatform', function() {
 });
 
 describe('uninstallPlugin', function() {
-    var exists, get_json, chmod, exec, proc, add_to_queue, prepare, 
actions_push, c_a, rm;
+    var exists, get_json, chmod, exec, proc, add_to_queue, prepare, 
actions_push, c_a, rm, uninstall_plugin;
     beforeEach(function() {
+        uninstall_plugin = spyOn(uninstall, 
'uninstallPlugin').andCallThrough();
         proc = spyOn(actions.prototype, 
'process').andCallFake(function(platform, proj, cb) {
             cb();
         });
@@ -144,6 +142,32 @@ describe('uninstallPlugin', function() {
             uninstall.uninstallPlugin(dummyplugin, plugins_dir);
             expect(rm).toHaveBeenCalled();
         });
+        describe('with dependencies', function() {
+            var parseET, emit;
+            beforeEach(function() {
+                emit = spyOn(plugman, 'emit');
+                var counter = 0;
+                parseET = spyOn(xml_helpers, 
'parseElementtreeSync').andCallFake(function(p) {
+                    return {
+                        _root:{
+                            attrib:{}
+                        },
+                        find:function() { return null },
+                        findall:function() { 
+                            if (counter === 0) {
+                                counter++;
+                                return [{attrib:{id:'somedependent'}}] 
+                            }
+                            else return [];
+                        }
+                    }
+                });
+            });
+            it('should recurse if dependent plugins are detected', function() {
+                uninstall.uninstallPlugin(dummyplugin, plugins_dir);
+                expect(uninstall_plugin).toHaveBeenCalledWith('somedependent', 
plugins_dir, jasmine.any(Function));
+            });
+        });
     });
 
     describe('failure', function() {

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/b421b7b1/src/uninstall.js
----------------------------------------------------------------------
diff --git a/src/uninstall.js b/src/uninstall.js
index 0f07774..3b56b3c 100644
--- a/src/uninstall.js
+++ b/src/uninstall.js
@@ -46,11 +46,26 @@ module.exports.uninstallPlugin = function(id, plugins_dir, 
callback) {
     var plugin_dir = path.join(plugins_dir, id);
     var xml_path     = path.join(plugin_dir, 'plugin.xml')
       , plugin_et    = xml_helpers.parseElementtreeSync(xml_path);
-    var plugin_id    = plugin_et._root.attrib['id'];
-    // axe the directory
-    shell.rm('-rf', plugin_dir);
-    require('../plugman').emit('log', plugin_id + ' uninstalled.');
-    if (callback) callback();
+
+    require('../plugman').emit('log', 'Removing plugin ' + id + '...');
+    // Check for dependents
+    var dependencies = plugin_et.findall('dependency');
+    if (dependencies && dependencies.length) {
+        require('../plugman').emit('log', 'Dependencies detected, iterating 
through them and removing them first...');
+        var end = n(dependencies.length, function() {
+            shell.rm('-rf', plugin_dir);
+            require('../plugman').emit('log', id + ' removed.');
+            if (callback) callback();
+        });
+        dependencies.forEach(function(dep) {
+            module.exports.uninstallPlugin(dep.attrib.id, plugins_dir, end);
+        });
+    } else {
+        // axe the directory
+        shell.rm('-rf', plugin_dir);
+        require('../plugman').emit('log', id + ' removed.');
+        if (callback) callback();
+    }
 };
 
 // possible options: cli_variables, www_dir, is_top_level
@@ -93,13 +108,7 @@ function runUninstall(actions, platform, project_dir, 
plugin_dir, plugins_dir, o
                 cli_variables: options.cli_variables,
                 is_top_level: false /* TODO: should this "is_top_level" param 
be false for dependents? */
             };
-            runUninstall(actions, platform, project_dir, dependent_path, 
plugins_dir, opts, function(err) {
-                if (err) {
-                    if (callback) return callback(err);
-                    else throw err;
-                }
-                module.exports.uninstallPlugin(dangler, plugins_dir, end);
-            });
+            runUninstall(actions, platform, project_dir, dependent_path, 
plugins_dir, opts, end);
         });
     } else {
         // this plugin can get axed by itself, gogo!

Reply via email to