cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fil...@apache.org
Subject git commit: proper uninstall + specs.
Date Thu, 25 Apr 2013 21:59:11 GMT
Updated Branches:
  refs/heads/master 83e985883 -> fe44ffc4f


proper uninstall + specs.


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

Branch: refs/heads/master
Commit: fe44ffc4f2c398fe058f1205db4531725512713f
Parents: 83e9858
Author: Fil Maj <maj.fil@gmail.com>
Authored: Thu Apr 25 14:59:07 2013 -0700
Committer: Fil Maj <maj.fil@gmail.com>
Committed: Thu Apr 25 14:59:07 2013 -0700

----------------------------------------------------------------------
 spec/install.spec.js   |    1 -
 spec/prepare.spec.js   |    9 +++++
 spec/uninstall.spec.js |   38 +++++++++++++++++---
 src/install.js         |    2 +
 src/uninstall.js       |   84 +++++++++++++++++++++++++++++++-----------
 5 files changed, 106 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/fe44ffc4/spec/install.spec.js
----------------------------------------------------------------------
diff --git a/spec/install.spec.js b/spec/install.spec.js
index b973b11..dd48d87 100644
--- a/spec/install.spec.js
+++ b/spec/install.spec.js
@@ -47,7 +47,6 @@ describe('install', function() {
             install('android', temp, 'CLEANYOURSHORTS', plugins_dir, {});
             expect(s).toHaveBeenCalled();
         });
-        // TODO: possibly test how diff platform transaction logs are created
         it('should generate an array of transactions required to run an installation and
pass into appropriate platform handler\'s install method', function() {
             install('android', temp, 'DummyPlugin', plugins_dir, {});
             var transactions = android_installer.mostRecentCall.args[0];

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/fe44ffc4/spec/prepare.spec.js
----------------------------------------------------------------------
diff --git a/spec/prepare.spec.js b/spec/prepare.spec.js
index 8d03778..e54f102 100644
--- a/spec/prepare.spec.js
+++ b/spec/prepare.spec.js
@@ -62,4 +62,13 @@ describe('prepare', function() {
         var plugins = JSON.parse(fs.readFileSync(path.join(www, 'cordova_plugins.json'),
'utf-8'));
         expect(plugins.length).toEqual(0);
     });
+
+    describe('config handling', function() {
+        it('needs to know about the stock app config.xml somehow?');
+        describe('single plugin', function() {
+        });
+
+        describe('multiple plugins', function() {
+        });
+    });
 });

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/fe44ffc4/spec/uninstall.spec.js
----------------------------------------------------------------------
diff --git a/spec/uninstall.spec.js b/spec/uninstall.spec.js
index c912321..e6b16db 100644
--- a/spec/uninstall.spec.js
+++ b/spec/uninstall.spec.js
@@ -3,8 +3,10 @@ var uninstall = require('../src/uninstall'),
     android = require('../src/platforms/android'),
     ios     = require('../src/platforms/ios'),
     blackberry = require('../src/platforms/blackberry'),
+    xml_helpers = require('../src/util/xml-helpers'),
     plugman = require('../plugman'),
     fs      = require('fs'),
+    et      = require('elementtree'),
     os      = require('osenv'),
     path    = require('path'),
     shell   = require('shelljs'),
@@ -13,9 +15,9 @@ var uninstall = require('../src/uninstall'),
     dummyplugin = path.join(__dirname, 'plugins', 'DummyPlugin'),
     variableplugin = path.join(__dirname, 'plugins', 'VariablePlugin'),
     faultyplugin = path.join(__dirname, 'plugins', 'FaultyPlugin'),
-    android_one_project = path.join(__dirname, 'projects', 'android_one', '*');
-    blackberry_project = path.join(__dirname, 'projects', 'blackberry', '*');
-    ios_project = path.join(__dirname, 'projects', 'ios-config-xml', '*');
+    android_one_project = path.join(__dirname, 'projects', 'android_one', '*'),
+    blackberry_project = path.join(__dirname, 'projects', 'blackberry', '*'),
+    ios_project = path.join(__dirname, 'projects', 'ios-config-xml', '*'),
     plugins_dir = path.join(temp, 'cordova', 'plugins');
 
 describe('uninstall', function() {
@@ -32,8 +34,17 @@ describe('uninstall', function() {
     });
 
     describe('success', function() {
-        // TODO: possibly test how diff platform transaction logs are created
+        var android_uninstaller;
+        beforeEach(function() {
+            install('android', temp, 'DummyPlugin', plugins_dir, {});
+            android_uninstaller = spyOn(android, 'uninstall');
+        });
         it('should generate and pass uninstall transaction log to appropriate platform handler\'s
uninstall', function() {
+            uninstall('android', temp, 'DummyPlugin', plugins_dir, {});
+            var transactions = android_uninstaller.mostRecentCall.args[0];
+
+            expect(transactions.length).toEqual(6);
+            expect(transactions[0].tag).toBe('source-file');
         });
     });
 
@@ -48,6 +59,23 @@ describe('uninstall', function() {
                 uninstall('android', temp, 'SomePlugin', plugins_dir, {});
             }).toThrow('Plugin "SomePlugin" not found. Already uninstalled?');
         });
-        it('should handle a failed uninstall by passing completed transactions into appropriate
handler\'s uninstall method'); 
+        it('should handle a failed uninstall by passing completed transactions into appropriate
handler\'s install method', function() {
+            shell.cp('-rf', faultyplugin, plugins_dir);
+            install('android', temp, 'DummyPlugin', plugins_dir, {});
+            var s = spyOn(android, 'install');
+            // destroy android manifest /manifest/application so pruneXML fails 
+            var manifest_path = path.join(temp, 'AndroidManifest.xml');
+            var manifest = xml_helpers.parseElementtreeSync(manifest_path);
+            var app_el = manifest.find('application');
+            manifest.getroot().remove(0, app_el);
+            var output = manifest.write({indent:4});
+            fs.writeFileSync(manifest_path, output);
+
+            uninstall('android', temp, 'DummyPlugin', plugins_dir, {});
+            var executed_txs = s.mostRecentCall.args[0];
+            expect(executed_txs.length).toEqual(1);
+            // It only ended up "uninstalling" one source file, so install reversion should
pass in that source file to re-install
+            expect(executed_txs[0].tag).toEqual('source-file');
+        }); 
     });
 });

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/fe44ffc4/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index e3a9423..c71d2ea 100644
--- a/src/install.js
+++ b/src/install.js
@@ -64,6 +64,8 @@ function runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variable
     if (!platformTag) {
         // Either this plugin doesn't support this platform, or it's a JS-only plugin.
         // Either way, return now.
+        // should call prepare probably!
+        require('./../plugman').prepare(project_dir, platform, plugins_dir);
         if (callback) callback();
         return;
     }

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/fe44ffc4/src/uninstall.js
----------------------------------------------------------------------
diff --git a/src/uninstall.js b/src/uninstall.js
index 811660f..aca3f1f 100644
--- a/src/uninstall.js
+++ b/src/uninstall.js
@@ -3,28 +3,6 @@ var path = require('path'),
     et   = require('elementtree'),
     platform_modules = require('./platforms');
 
-function runUninstall(platform, project_dir, plugin_dir, plugins_dir, cli_variables, callback)
{
-    var xml_path     = path.join(plugin_dir, 'plugin.xml')
-      , xml_text     = fs.readFileSync(xml_path, 'utf-8')
-      , plugin_et    = new et.ElementTree(et.XML(xml_text))
-
-    // run the platform-specific function
-    try {
-        platform_modules[platform].handleUninstall(project_dir, plugin_dir, plugin_et);
-        require('./../plugman').prepare(project_dir, platform, plugins_dir);
-        if (callback) callback();
-    } catch(e) {
-        var err;
-        try {
-            platform_modules[platform].forceInstall(project_dir, plugin_dir, plugin_et, {});
-            err = new Error('Error during uninstallation of plugin, reverted all changes.
Uninstall error: ' + e.message);
-        } catch(etwo) {
-            err = new Error('Error during uninstallation of plugin, reverting changes also
caused issues! Reversion probably incomplete. Uninstall error: ' + e.message + ', reversion
error: ' + etwo.message);
-        }
-        if (callback) callback(err);
-        else throw err;
-    }
-}
 
 module.exports = function uninstallPlugin(platform, project_dir, name, plugins_dir, cli_variables,
callback) {
     if (!platform_modules[platform]) {
@@ -50,3 +28,65 @@ module.exports = function uninstallPlugin(platform, project_dir, name,
plugins_d
 
     runUninstall(platform, project_dir, plugin_dir, plugins_dir, cli_variables, callback);
 };
+
+function runUninstall(platform, project_dir, plugin_dir, plugins_dir, cli_variables, callback)
{
+    var xml_path     = path.join(plugin_dir, 'plugin.xml')
+      , xml_text     = fs.readFileSync(xml_path, 'utf-8')
+      , plugin_et    = new et.ElementTree(et.XML(xml_text))
+    var name         = plugin_et.findall('name').text;
+    var plugin_id    = plugin_et._root.attrib['id'];
+
+    var platformTag = plugin_et.find('./platform[@name="'+platform+'"]');
+    var platformTag = plugin_et.find('./platform[@name="'+platform+'"]');
+    if (!platformTag) {
+        // Either this plugin doesn't support this platform, or it's a JS-only plugin.
+        // Either way, return now.
+        // should call prepare probably!
+        require('./../plugman').prepare(project_dir, platform, plugins_dir);
+        if (callback) callback();
+        return;
+    }
+    var handler = platform_modules[platform];
+
+    // parse plugin.xml into transactions
+    var txs = [];
+    var sourceFiles = platformTag.findall('./source-file'),
+        headerFiles = platformTag.findall('./header-file'),
+        resourceFiles = platformTag.findall('./resource-file'),
+        assets = platformTag.findall('./asset'),
+        frameworks = platformTag.findall('./framework'),
+        pluginsPlist = platformTag.findall('./plugins-plist'),
+        configChanges = platformTag.findall('./config-file');
+    assets = assets.concat(plugin_et.findall('./asset'));
+    
+    txs = txs.concat(sourceFiles, headerFiles, resourceFiles, frameworks, configChanges,
assets, pluginsPlist);
+
+    // pass platform-specific transactions into uninstall
+    handler.uninstall(txs, plugin_id, project_dir, plugin_dir, function(err) {
+        if (err) {
+            // FAIL
+            if (err. transactions) {
+                handler.install(err.transactions.executed, plugin_id, project_dir, plugin_dir,
cli_variables, function(superr) {
+                    var issue = '';
+                    if (superr) {
+                        // Even reversion failed. super fail.
+                        issue = 'Uninstall failed, then reversion of uninstallation failed.
Sorry :(. Uninstalation issue: ' + err.stack + ', reversion issue: ' + superr.stack;
+                    } else {
+                        issue = 'Uninstall failed, plugin reversion successful so you should
be good to go. Uninstallation issue: ' + err.stack;
+                    }
+                    var error = new Error(issue);
+                    if (callback) callback(error);
+                    else throw error;
+                });
+            } else {
+                if (callback) callback(err);
+                else throw err;
+            }
+        } else {
+            // WIN!
+            // call prepare after a successful uninstall
+            require('./../plugman').prepare(project_dir, platform, plugins_dir);
+            if (callback) callback();
+        }
+    });
+}


Mime
View raw message