cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [1/4] git commit: updating assets and spec
Date Tue, 07 May 2013 01:20:32 GMT
Updated Branches:
  refs/heads/master 747367fb3 -> ca883de68


updating assets and spec


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

Branch: refs/heads/master
Commit: 61fe6611471a9aaa54e7b9e0a10e0c5094042503
Parents: 747367f
Author: Anis Kadri <anis@apache.org>
Authored: Mon May 6 14:58:50 2013 -0700
Committer: Anis Kadri <anis@apache.org>
Committed: Mon May 6 14:58:50 2013 -0700

----------------------------------------------------------------------
 package.json         |    2 +-
 spec/install.spec.js |   62 +++++++++++++++++++++++++++++++++++++++-----
 src/install.js       |   22 ++++++++++------
 3 files changed, 70 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/61fe6611/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 6eb5ceb..2dfe157 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
   "author": "Andrew Lunny <alunny@gmail.com>",
   "name": "plugman",
   "description": "install/uninstall Cordova plugins",
-  "version": "0.6.2",
+  "version": "0.6.3",
   "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/61fe6611/spec/install.spec.js
----------------------------------------------------------------------
diff --git a/spec/install.spec.js b/spec/install.spec.js
index 7c4ef85..cf8acd4 100644
--- a/spec/install.spec.js
+++ b/spec/install.spec.js
@@ -1,7 +1,8 @@
 var install = require('../src/install'),
     android = require('../src/platforms/android'),
-    ios     = require('../src/platforms/ios'),
-    blackberry = require('../src/platforms/blackberry'),
+    common = require('../src/platforms/common'),
+    //ios     = require('../src/platforms/ios'),
+    //blackberry = require('../src/platforms/blackberry'),
     config_changes = require('../src/util/config-changes'),
     plugman = require('../plugman'),
     fs      = require('fs'),
@@ -14,8 +15,8 @@ var install = require('../src/install'),
     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', '*');
+    //blackberry_project = path.join(__dirname, 'projects', 'blackberry', '*');
+    //ios_project = path.join(__dirname, 'projects', 'ios-config-xml', '*');
     plugins_dir = path.join(temp, 'cordova', 'plugins');
 
 describe('install', function() {
@@ -37,6 +38,40 @@ describe('install', function() {
             shell.cp('-rf', dummyplugin, plugins_dir);
             android_installer = spyOn(android, 'install');
         });
+        it('should properly install assets', function() {
+            var s = spyOn(common, 'copyFile').andCallThrough();
+            install('android', temp, 'DummyPlugin', plugins_dir, {});
+            // making sure the right methods were called
+            expect(s).toHaveBeenCalled();
+            expect(s.calls.length).toEqual(2);
+
+            expect(fs.existsSync(path.join(temp, 'assets', 'www', 'dummyplugin.js'))).toBe(true);
+            expect(fs.existsSync(path.join(temp, 'assets', 'www', 'dummyplugin'))).toBe(true);
+            expect(fs.statSync(path.join(temp, 'assets', 'www', 'dummyplugin.js')).isFile()).toBe(true);
+            expect(fs.statSync(path.join(temp, 'assets', 'www', 'dummyplugin')).isDirectory()).toBe(true);
+        });
+        it('should revert all assets on asset install error', function() {
+            var sCopyFile = spyOn(common, 'copyFile').andCallThrough();
+            var sRemoveFile = spyOn(common, 'removeFile').andCallThrough();
+            var sRemoveFileF = spyOn(common, 'removeFileF').andCallThrough();
+            
+            // messing the plugin
+            shell.rm('-rf', path.join(plugins_dir, 'dummyplugin', 'www', 'dummyplugin'));

+            expect(function() {
+                install('android', temp, 'DummyPlugin', plugins_dir, {});
+            }).toThrow();
+            // making sure the right methods were called
+            expect(sCopyFile).toHaveBeenCalled();
+            expect(sCopyFile.calls.length).toEqual(2);
+
+            expect(sRemoveFile).toHaveBeenCalled();
+            expect(sRemoveFile.calls.length).toEqual(1);
+            expect(sRemoveFileF).toHaveBeenCalled();
+            expect(sRemoveFileF.calls.length).toEqual(1);
+           
+            expect(fs.existsSync(path.join(temp, 'assets', 'www', 'dummyplugin.js'))).toBe(false);
+            expect(fs.existsSync(path.join(temp, 'assets', 'www', 'dummyplugin'))).toBe(false);
+        });
         it('should call prepare after a successful install', function() {
             var s = spyOn(plugman, 'prepare');
             install('android', temp, 'DummyPlugin', plugins_dir, {});
@@ -65,9 +100,6 @@ describe('install', function() {
     });
 
     describe('failure', function() {
-        describe('should revert web assets if an install error occurs', function() {
-            
-        });
         it('should throw if platform is unrecognized', function() {
             expect(function() {
                 install('atari', temp, 'SomePlugin', plugins_dir, {});
@@ -97,5 +129,21 @@ describe('install', function() {
                 install('android', temp, 'DummyPlugin', plugins_dir, {});
             }).toThrow();
         });
+        it('should revert web assets if an install error occurs', function() {
+            var sRemoveFile = spyOn(common, 'removeFile').andCallThrough();
+            var sRemoveFileF = spyOn(common, 'removeFileF').andCallThrough();
+            shell.cp('-rf', dummyplugin, plugins_dir);
+            shell.rm(path.join(plugins_dir, 'DummyPlugin', 'src', 'android', 'DummyPlugin.java'));

+            
+            install('android', temp, 'DummyPlugin', plugins_dir, {}, function() {});
+            
+            expect(sRemoveFile).toHaveBeenCalled();
+            expect(sRemoveFile.calls.length).toEqual(2);
+            expect(sRemoveFileF).toHaveBeenCalled();
+            expect(sRemoveFileF.calls.length).toEqual(1);
+           
+            expect(fs.existsSync(path.join(temp, 'assets', 'www', 'dummyplugin.js'))).toBe(false);
+            expect(fs.existsSync(path.join(temp, 'assets', 'www', 'dummyplugin'))).toBe(false);
+        });
     });
 });

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/61fe6611/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index bc0e4c5..8626f4f 100644
--- a/src/install.js
+++ b/src/install.js
@@ -116,7 +116,7 @@ function runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variable
         try {
             // removing assets and reverting install
             for(var i = 0, j = installedAssets.length ; i < j ; i++) {
-               common.removeFile(handler.www_dir(project_dir), installedAssets[i].target);
+               common.removeFile(handler.www_dir(project_dir), installedAssets[i].attrib.target);
             }
             common.removeFileF(path.resolve(handler.www_dir(project_dir), 'plugins', plugin_id));
             issue += 'but successfully reverted\n';
@@ -127,22 +127,28 @@ function runInstall(platform, project_dir, plugin_dir, plugins_dir,
cli_variable
         if (callback) callback(error);
         else throw error;
     }
-
     txs = txs.concat(sourceFiles, headerFiles, resourceFiles, frameworks);
     // pass platform-specific transactions into install
     handler.install(txs, plugin_id, project_dir, plugin_dir, filtered_variables, function(err)
{
-        
         if (err) {
             // FAIL
-            // TODO revert assets at this point too
-            if (err. transactions) {
+            var issue = '';
+            try {
+                for(var i = 0, j = installedAssets.length ; i < j ; i++) {
+                   common.removeFile(handler.www_dir(project_dir), installedAssets[i].attrib.target);
+                }
+                common.removeFileF(path.resolve(handler.www_dir(project_dir), 'plugins',
plugin_id));
+            } catch(err2) {
+                issue += 'Could not revert assets' + err2.stack + '\n';
+            }
+            if (err.transactions) {
                 handler.uninstall(err.transactions.executed, plugin_id, project_dir, plugin_dir,
function(superr) {
-                    var issue = '';
+
                     if (superr) {
                         // Even reversion failed. super fail.
-                        issue = 'Install failed, then reversion of installation failed. Sorry
:(. Instalation issue: ' + err.stack + ', reversion issue: ' + superr.stack;
+                        issue += 'Install failed, then reversion of installation failed.
Sorry :(. Instalation issue: ' + err.stack + ', reversion issue: ' + superr.stack;
                     } else {
-                        issue = 'Install failed, plugin reversion successful so you should
be good to go. Installation issue: ' + err.stack;
+                        issue += 'Install failed, plugin reversion successful so you should
be good to go. Installation issue: ' + err.stack;
                     }
                     var error = new Error(issue);
                     if (callback) callback(error);


Mime
View raw message