You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by an...@apache.org on 2013/05/01 04:12:43 UTC
[1/2] git commit: CB-3284 moving assets to install/uninstall
Updated Branches:
refs/heads/master 069a4bbfe -> 6ae75d2f2
CB-3284 moving assets to install/uninstall
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/59787105
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/59787105
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/59787105
Branch: refs/heads/master
Commit: 597871051bf8352d05a64553dbecaf8d8927dd69
Parents: 069a4bb
Author: Anis Kadri <an...@apache.org>
Authored: Tue Apr 30 19:12:00 2013 -0700
Committer: Anis Kadri <an...@apache.org>
Committed: Tue Apr 30 19:12:00 2013 -0700
----------------------------------------------------------------------
spec/install.spec.js | 2 +-
spec/platforms/ios.spec.js | 78 +++++++++++++++++++-------------------
spec/uninstall.spec.js | 2 +-
src/install.js | 30 ++++++++++++++-
src/uninstall.js | 31 ++++++++++++++-
5 files changed, 99 insertions(+), 44 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/59787105/spec/install.spec.js
----------------------------------------------------------------------
diff --git a/spec/install.spec.js b/spec/install.spec.js
index e993388..15d5871 100644
--- a/spec/install.spec.js
+++ b/spec/install.spec.js
@@ -52,7 +52,7 @@ describe('install', function() {
install('android', temp, 'DummyPlugin', plugins_dir, {});
var transactions = android_installer.mostRecentCall.args[0];
- expect(transactions.length).toEqual(3);
+ expect(transactions.length).toEqual(1);
expect(transactions[0].tag).toBe('source-file');
});
it('should call the config-changes module\'s add_installed_plugin_to_prepare_queue method', function() {
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/59787105/spec/platforms/ios.spec.js
----------------------------------------------------------------------
diff --git a/spec/platforms/ios.spec.js b/spec/platforms/ios.spec.js
index 591e217..0c58cc2 100644
--- a/spec/platforms/ios.spec.js
+++ b/spec/platforms/ios.spec.js
@@ -273,45 +273,45 @@ describe('ios project handler', function() {
expect(spy).toHaveBeenCalledWith('-R', path.join(dummyplugin, 'src', 'ios', 'DummyPlugin.bundle'), path.join(temp, 'SampleApp', 'Resources'));
});
});
-
- describe('of <asset> elements', function() {
- beforeEach(function() {
- shell.cp('-rf', ios_config_xml_project, temp);
- });
- it('should throw if asset src cannot be found', function() {
- var assets = copyArray(invalid_assets);
- expect(function() {
- ios.install(assets, faulty_id, temp, faultyplugin, {});
- }).toThrow('"' + path.resolve(faultyplugin, 'www/main.js') + '" not found!');
- });
- it('should throw if asset target already exists', function() {
- var assets = copyArray(valid_assets);
- var target = path.join(temp, 'www', 'dummyplugin.js');
- fs.writeFileSync(target, 'some bs', 'utf-8');
- expect(function() {
- ios.install(assets, dummy_id, temp, dummyplugin, {});
- }).toThrow('"'+ target + '" already exists!');
- });
- it('should cp the file and directory to the right target location', function() {
- var assets = copyArray(valid_assets);
- var spy_cp = spyOn(shell, 'cp').andCallThrough();
- var spy_mkdir = spyOn(shell, 'mkdir').andCallThrough();
- ios.install(assets, dummy_id, temp, dummyplugin, {});
- expect(spy_mkdir).toHaveBeenCalledWith('-p', path.join(temp, 'www'));
- expect(spy_cp).toHaveBeenCalledWith(path.join(dummyplugin, 'www', 'dummyplugin.js'), path.join(temp, 'www', 'dummyplugin.js'));
- expect(spy_cp).toHaveBeenCalledWith('-R', path.join(dummyplugin, 'www', 'dummyplugin/*'), path.join(temp, 'www', 'dummyplugin'));
-
- // make sure the file and directory are properly copies
- expect(fs.existsSync(path.join(temp, 'www', 'dummyplugin.js'))).toBe(true);
- expect(fs.statSync(path.join(temp, 'www', 'dummyplugin.js')).isFile()).toBe(true);
-
- expect(fs.existsSync(path.join(temp, 'www', 'dummyplugin'))).toBe(true);
- expect(fs.statSync(path.join(temp, 'www', 'dummyplugin')).isDirectory()).toBe(true);
-
- expect(fs.existsSync(path.join(temp, 'www', 'dummyplugin', 'image.jpg'))).toBe(true);
- expect(fs.statSync(path.join(temp, 'www', 'dummyplugin', 'image.jpg')).isFile()).toBe(true);
- });
- });
+ // TODO move this shit to install/uninstall
+ // describe('of <asset> elements', function() {
+ // beforeEach(function() {
+ // shell.cp('-rf', ios_config_xml_project, temp);
+ // });
+ // it('should throw if asset src cannot be found', function() {
+ // var assets = copyArray(invalid_assets);
+ // expect(function() {
+ // ios.install(assets, faulty_id, temp, faultyplugin, {});
+ // }).toThrow('"' + path.resolve(faultyplugin, 'www/main.js') + '" not found!');
+ // });
+ // it('should throw if asset target already exists', function() {
+ // var assets = copyArray(valid_assets);
+ // var target = path.join(temp, 'www', 'dummyplugin.js');
+ // fs.writeFileSync(target, 'some bs', 'utf-8');
+ // expect(function() {
+ // ios.install(assets, dummy_id, temp, dummyplugin, {});
+ // }).toThrow('"'+ target + '" already exists!');
+ // });
+ // it('should cp the file and directory to the right target location', function() {
+ // var assets = copyArray(valid_assets);
+ // var spy_cp = spyOn(shell, 'cp').andCallThrough();
+ // var spy_mkdir = spyOn(shell, 'mkdir').andCallThrough();
+ // ios.install(assets, dummy_id, temp, dummyplugin, {});
+ // expect(spy_mkdir).toHaveBeenCalledWith('-p', path.join(temp, 'www'));
+ // expect(spy_cp).toHaveBeenCalledWith(path.join(dummyplugin, 'www', 'dummyplugin.js'), path.join(temp, 'www', 'dummyplugin.js'));
+ // expect(spy_cp).toHaveBeenCalledWith('-R', path.join(dummyplugin, 'www', 'dummyplugin/*'), path.join(temp, 'www', 'dummyplugin'));
+ //
+ // // make sure the file and directory are properly copies
+ // expect(fs.existsSync(path.join(temp, 'www', 'dummyplugin.js'))).toBe(true);
+ // expect(fs.statSync(path.join(temp, 'www', 'dummyplugin.js')).isFile()).toBe(true);
+ //
+ // expect(fs.existsSync(path.join(temp, 'www', 'dummyplugin'))).toBe(true);
+ // expect(fs.statSync(path.join(temp, 'www', 'dummyplugin')).isDirectory()).toBe(true);
+ //
+ // expect(fs.existsSync(path.join(temp, 'www', 'dummyplugin', 'image.jpg'))).toBe(true);
+ // expect(fs.statSync(path.join(temp, 'www', 'dummyplugin', 'image.jpg')).isFile()).toBe(true);
+ // });
+ // });
describe('of <framework> elements', function() {
beforeEach(function() {
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/59787105/spec/uninstall.spec.js
----------------------------------------------------------------------
diff --git a/spec/uninstall.spec.js b/spec/uninstall.spec.js
index a2ce26d..f1c6b9c 100644
--- a/spec/uninstall.spec.js
+++ b/spec/uninstall.spec.js
@@ -44,7 +44,7 @@ describe('uninstall', function() {
uninstall('android', temp, 'DummyPlugin', plugins_dir, {});
var transactions = android_uninstaller.mostRecentCall.args[0];
- expect(transactions.length).toEqual(3);
+ expect(transactions.length).toEqual(1);
expect(transactions[0].tag).toBe('source-file');
});
it('should call the config-changes module\'s add_uninstalled_plugin_to_prepare_queue method', function() {
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/59787105/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index b07540c..ba9d0bb 100644
--- a/src/install.js
+++ b/src/install.js
@@ -101,10 +101,37 @@ function runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variable
assets = assets.concat(plugin_et.findall('./asset'));
- txs = txs.concat(sourceFiles, headerFiles, resourceFiles, frameworks, assets);
+ // asset installation
+ var installedAssets = [];
+ var common = require('./platforms/common');
+ try {
+ for(var i = 0, j = assets.length ; i < j ; i++) {
+ var src = assets[i].attrib['src'],
+ target = assets[i].attrib['target'];
+ common.copyFile(plugin_dir, src, handler.www_dir(project_dir), target);
+ installedAssets.push(assets[i]);
+ }
+ } catch(err) {
+ var issue = 'asset installation failed\n'+err.stack+'\n';
+ 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.removeFileF(path.resolve(handler.www_dir(project_dir), 'plugins', plugin_id));
+ issue += 'but successfully reverted\n';
+ } catch(err2) {
+ issue += 'and reversion failed :(\n' + err2.stack;
+ }
+ var error = new Error(issue);
+ 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
if (err. transactions) {
@@ -125,6 +152,7 @@ function runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variable
else throw err;
}
} else {
+
// WIN!
// Log out plugin INFO element contents in case additional install steps are necessary
var info = platformTag.findall('./info');
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/59787105/src/uninstall.js
----------------------------------------------------------------------
diff --git a/src/uninstall.js b/src/uninstall.js
index 0868b7e..6648e35 100644
--- a/src/uninstall.js
+++ b/src/uninstall.js
@@ -52,8 +52,35 @@ function runUninstall(platform, project_dir, plugin_dir, plugins_dir, cli_variab
frameworks = platformTag.findall('./framework');
assets = assets.concat(plugin_et.findall('./asset'));
- txs = txs.concat(sourceFiles, headerFiles, resourceFiles, frameworks, assets);
-
+ // asset uninstallation
+ var uninstalledAssets = [];
+ var common = require('./platforms/common');
+ try {
+ for(var i = 0, j = assets.length ; i < j ; i++) {
+ common.removeFile(handler.www_dir(project_dir), assets[i].attrib['target']);
+ uninstalledAssets.push(assets[i]);
+ }
+ common.removeFileF(path.resolve(handler.www_dir(project_dir), 'plugins', plugin_id));
+ } catch(err) {
+ var issue = 'asset uninstallation failed\n'+err.stack+'\n';
+ try {
+ // adding assets back
+ for(var i = 0, j = uninstalledAssets.length ; i < j ; i++) {
+ var src = uninstalledAssets[i].attrib['src'],
+ target = uninstalledAssets[i].attrib['target'];
+ common.copyFile(plugin_dir, src, handler.www_dir(project_dir), target);
+ }
+ issue += 'but successfully reverted\n';
+ } catch(err2) {
+ issue += 'and reversion failed :(\n' + err2.stack;
+ }
+ var error = new Error(issue);
+ if (callback) callback(error);
+ else throw error;
+ }
+
+ txs = txs.concat(sourceFiles, headerFiles, resourceFiles, frameworks);
+
// pass platform-specific transactions into uninstall
handler.uninstall(txs, plugin_id, project_dir, plugin_dir, function(err) {
if (err) {
[2/2] git commit: CB-3215 added ability to use zip archives from
local/remote sources
Posted by an...@apache.org.
CB-3215 added ability to use zip archives from local/remote sources
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/6ae75d2f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/6ae75d2f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/6ae75d2f
Branch: refs/heads/master
Commit: 6ae75d2f2e4fabd6bca6ec25b51401e9f32f266d
Parents: 5978710
Author: Anis Kadri <an...@apache.org>
Authored: Tue Apr 30 19:12:37 2013 -0700
Committer: Anis Kadri <an...@apache.org>
Committed: Tue Apr 30 19:12:37 2013 -0700
----------------------------------------------------------------------
src/util/plugins.js | 69 ++++++++++++++++++++++++++++++---------------
1 files changed, 46 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/6ae75d2f/src/util/plugins.js
----------------------------------------------------------------------
diff --git a/src/util/plugins.js b/src/util/plugins.js
index 52739be..d79b672 100644
--- a/src/util/plugins.js
+++ b/src/util/plugins.js
@@ -19,7 +19,7 @@
*/
var http = require('http'),
- osenv = require('osenv'),
+ os = require('os'),
path = require('path'),
fs = require('fs'),
util = require('util'),
@@ -80,15 +80,8 @@ module.exports = {
if (callback) callback(err);
else throw err;
}
- // use osenv to get a temp directory in a portable way
- var lastSlash = plugin_git_url.lastIndexOf('/');
- var basename = plugin_git_url.substring(lastSlash+1);
- var dotGitIndex = basename.lastIndexOf('.git');
- if (dotGitIndex >= 0) {
- basename = basename.substring(0, dotGitIndex);
- }
- var plugin_dir = path.join(plugins_dir, basename);
+ var plugin_dir = path.join(plugins_dir, path.basename(plugin_git_url).replace(path.extname(plugin_git_url), ''));
// trash it if it already exists (something went wrong before probably)
// TODO: is this the correct behaviour?
@@ -105,20 +98,50 @@ module.exports = {
if (callback) callback(null, plugin_dir);
}
});
- }
- // TODO add method for archives and other formats
- // extractArchive:function(plugin_dir) {
- // }
-
- // TODO add method to publish plugin from cli
- // publishPlugin:function(plugin_dir) {
- // }
+ },
+ // FIXME: this won't work on Windows OBVIOUSLY! Use node-zip to support?
+ handleZipArchive:function(source, plugins_dir, callback) {
+
+ if(!shell.which('unzip')) {
+ var err = new Error('unzip command line is not installed');
+ if (callback) callback(err);
+ else throw err;
+ }
+ var basename = path.basename(source);
+
+ var unzip = function(src, dst, callback) {
+ var plugin_dir = path.join(plugins_dir, basename.replace(path.extname(source), ''));
+ var util = require('util');
+ shell.exec(util.format('unzip %s -d %s', src, dst), {silent: true, async:true}, function(code, output) {
+ if (code != 0) {
+ var err = new Error('failed to extract the plugin zip archive '+ src+' Reason: '+output);
+ if (callback) callback(err);
+ else throw err;
+ } else {
+ if (callback) callback(null, plugin_dir);
+ }
+ });
+ };
+
+ if(source.indexOf('http://') == 0) {
+ var target = os.tmpdir() + basename;
+ var file = fs.createWriteStream(target);
+ var request = http.get(source, function(res) {
+ if(res.statusCode != 200) {
+ var err = new Error('failed to fetch the plugin zip archive from '+ source);
+ if (callback) callback(err);
+ else throw err;
+ } else {
+ res.pipe(file);
+ res.on('end', function() {
+ unzip(target, plugins_dir);
+ });
+ }
+ });
- // TODO add method to unpublish plugin from cli
- // unpublishPlugin:function(plugin_dir) {
- // }
+ } else {
+ unzip(source, plugins_dir);
+ }
+ }
};
-
-
-