You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by br...@apache.org on 2013/05/10 20:39:09 UTC
[1/4] git commit: Make plugin cache directories be named after the
plugin ID
Updated Branches:
refs/heads/dependencies [created] 39d6f7937
Make plugin cache directories be named after the plugin ID
Previously they were named accidentally, after the git repo's or local
directory's basename.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/5e9eebb1
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/5e9eebb1
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/5e9eebb1
Branch: refs/heads/dependencies
Commit: 5e9eebb167a03d04f6cba03ae19f2d5f6e49e5eb
Parents: 8b99d7c
Author: Braden Shepherdson <br...@gmail.com>
Authored: Thu May 9 12:18:58 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Thu May 9 12:18:58 2013 -0400
----------------------------------------------------------------------
spec/fetch.spec.js | 2 +-
spec/remove.spec.js | 6 +++---
src/fetch.js | 9 +++++++--
src/util/plugins.js | 23 ++++++++++++++---------
4 files changed, 25 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/5e9eebb1/spec/fetch.spec.js
----------------------------------------------------------------------
diff --git a/spec/fetch.spec.js b/spec/fetch.spec.js
index 8c07d44..b36ceab 100644
--- a/spec/fetch.spec.js
+++ b/spec/fetch.spec.js
@@ -8,7 +8,7 @@ var fetch = require('../src/fetch'),
plugins = require('../src/util/plugins');
describe('fetch', function() {
- var copied_plugin_path = path.join(temp,'ChildBrowser');
+ var copied_plugin_path = path.join(temp, 'com.phonegap.plugins.childbrowser');
beforeEach(function() {
shell.mkdir('-p', temp);
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/5e9eebb1/spec/remove.spec.js
----------------------------------------------------------------------
diff --git a/spec/remove.spec.js b/spec/remove.spec.js
index 444f420..4553b85 100644
--- a/spec/remove.spec.js
+++ b/spec/remove.spec.js
@@ -8,7 +8,7 @@ var remove = require('../src/remove'),
test_plugin = path.join(__dirname, 'plugins', 'ChildBrowser');
describe('remove', function() {
- var copied_plugin_path = path.join(temp,'ChildBrowser');
+ var copied_plugin_path = path.join(temp,'com.phonegap.plugins.childbrowser');
beforeEach(function() {
shell.mkdir('-p', temp);
@@ -19,12 +19,12 @@ describe('remove', function() {
it('should remove symbolically-linked plugins', function() {
fetch(test_plugin, temp, true);
- remove('ChildBrowser', temp);
+ remove('com.phonegap.plugins.childbrowser', temp);
expect(fs.readdirSync(temp).length).toEqual(0);
});
it('should remove non-linked plugins', function() {
fetch(test_plugin, temp, false);
- remove('ChildBrowser', temp);
+ remove('com.phonegap.plugins.childbrowser', temp);
expect(fs.readdirSync(temp).length).toEqual(0);
});
});
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/5e9eebb1/src/fetch.js
----------------------------------------------------------------------
diff --git a/src/fetch.js b/src/fetch.js
index d5b4684..822f28d 100644
--- a/src/fetch.js
+++ b/src/fetch.js
@@ -1,6 +1,7 @@
var shell = require('shelljs'),
fs = require('fs'),
plugins = require('./util/plugins'),
+ xml_helpers = require('./util/xml-helpers'),
path = require('path');
module.exports = function fetchPlugin(plugin_dir, plugins_dir, link, callback) {
@@ -18,13 +19,17 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, link, callback) {
}
} else {
// Copy from the local filesystem.
- var dest = path.join(plugins_dir, path.basename(plugin_dir));
+ // First, read the plugin.xml and grab the ID.
+ var xml = xml_helpers.parseElementtreeSync(path.join(plugin_dir, 'plugin.xml'));
+ var plugin_id = xml.getroot().attrib.id;
+
+ var dest = path.join(plugins_dir, plugin_id);
shell.rm('-rf', dest);
if (link) {
fs.symlinkSync(path.resolve(plugin_dir), dest, 'dir');
} else {
- shell.cp('-R', plugin_dir, plugins_dir); // Yes, not dest.
+ shell.cp('-R', path.join(plugin_dir, '*'), dest);
}
if (callback) callback(null, dest);
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/5e9eebb1/src/util/plugins.js
----------------------------------------------------------------------
diff --git a/src/util/plugins.js b/src/util/plugins.js
index 3c55290..0a627cb 100644
--- a/src/util/plugins.js
+++ b/src/util/plugins.js
@@ -23,7 +23,9 @@ var http = require('http'),
path = require('path'),
fs = require('fs'),
util = require('util'),
- shell = require('shelljs');
+ shell = require('shelljs'),
+ xml_helpers = require('./xml-helpers'),
+ tmp_dir = path.join(path.sep, 'tmp', 'plugman-tmp');
module.exports = {
searchAndReplace:require('./search-and-replace'),
@@ -35,20 +37,23 @@ module.exports = {
else throw err;
}
- var plugin_dir = path.join(plugins_dir, path.basename(plugin_git_url).replace(path.extname(plugin_git_url), ''));
+ shell.rm('-rf', tmp_dir);
- // trash it if it already exists (something went wrong before probably)
- // TODO: is this the correct behaviour?
- if(fs.existsSync(plugin_dir)) {
- shell.rm('-rf', plugin_dir);
- }
-
- shell.exec('git clone ' + plugin_git_url + ' ' + plugin_dir, {silent: true, async:true}, function(code, output) {
+ var cmd = util.format('git clone "%s" "%s"', plugin_git_url, tmp_dir);
+ shell.exec(cmd, {silent: true, async:true}, function(code, output) {
if (code > 0) {
var err = new Error('failed to get the plugin via git from URL '+ plugin_git_url);
if (callback) callback(err)
else throw err;
} else {
+ // Read the plugin.xml file and extract the plugin's ID.
+ var xml_file = path.join(tmp_dir, 'plugin.xml');
+ var xml = xml_helpers.parseElementtreeSync(xml_file);
+ var plugin_id = xml.getroot().attrib.id;
+
+ var plugin_dir = path.join(plugins_dir, plugin_id);
+ shell.cp('-R', path.join(tmp_dir, '*'), plugin_dir);
+
if (callback) callback(null, plugin_dir);
}
});
[4/4] git commit: Fix tests after adding dependencies.
Posted by br...@apache.org.
Fix tests after adding 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/39d6f793
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/39d6f793
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/39d6f793
Branch: refs/heads/dependencies
Commit: 39d6f79379558024317f906c5bae0132b835703a
Parents: 6b9932f
Author: Braden Shepherdson <br...@gmail.com>
Authored: Thu May 9 14:41:44 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Thu May 9 14:41:44 2013 -0400
----------------------------------------------------------------------
src/install.js | 3 ++-
src/uninstall.js | 3 ++-
src/util/dependencies.js | 1 +
3 files changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/39d6f793/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index d7f8c46..37d789c 100644
--- a/src/install.js
+++ b/src/install.js
@@ -1,7 +1,8 @@
var path = require('path'),
fs = require('fs'),
et = require('elementtree'),
- config_changes = require('./util/config-changes');
+ config_changes = require('./util/config-changes'),
+ dependencies = require('./util/dependencies'),
platform_modules = require('./platforms');
// TODO: is name necessary as a param ehre?
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/39d6f793/src/uninstall.js
----------------------------------------------------------------------
diff --git a/src/uninstall.js b/src/uninstall.js
index c2db2e2..35838ca 100644
--- a/src/uninstall.js
+++ b/src/uninstall.js
@@ -1,7 +1,8 @@
var path = require('path'),
fs = require('fs'),
et = require('elementtree'),
- config_changes = require('./util/config-changes');
+ config_changes = require('./util/config-changes'),
+ platform_modules = require('./platforms');
module.exports = function uninstallPlugin(platform, project_dir, name, plugins_dir, cli_variables, www_dir, callback) {
if (!platform_modules[platform]) {
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/39d6f793/src/util/dependencies.js
----------------------------------------------------------------------
diff --git a/src/util/dependencies.js b/src/util/dependencies.js
index 381fdf0..9f7a594 100644
--- a/src/util/dependencies.js
+++ b/src/util/dependencies.js
@@ -1,5 +1,6 @@
var install = require('../install'),
fetch = require('../fetch'),
+ path = require('path'),
fs = require('fs'),
xml_helpers = require('./xml-helpers');
[2/4] git commit: Adding subdirectory support to fetch.
Posted by br...@apache.org.
Adding subdirectory support to fetch.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/7d2cd7d5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/7d2cd7d5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/7d2cd7d5
Branch: refs/heads/dependencies
Commit: 7d2cd7d5798db71886b6f3a47653a585edb187f1
Parents: 5e9eebb
Author: Braden Shepherdson <br...@gmail.com>
Authored: Thu May 9 12:54:57 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Thu May 9 12:54:57 2013 -0400
----------------------------------------------------------------------
spec/util/plugins.spec.js | 4 ++--
src/fetch.js | 11 +++++++----
src/install.js | 2 +-
src/util/plugins.js | 5 +++--
4 files changed, 13 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/7d2cd7d5/spec/util/plugins.spec.js
----------------------------------------------------------------------
diff --git a/spec/util/plugins.spec.js b/spec/util/plugins.spec.js
index 55c3f0e..f0cb3e0 100644
--- a/spec/util/plugins.spec.js
+++ b/spec/util/plugins.spec.js
@@ -32,10 +32,10 @@ describe('plugins', function(){
var plugin_git_url = 'https://github.com/imhotep/ChildBrowser'
var myFunction = function(){};
- plugins.clonePluginGitRepo(plugin_git_url, temp, myFunction);
+ plugins.clonePluginGitRepo(plugin_git_url, temp, '.', myFunction);
expect(mySpy).toHaveBeenCalled();
- expect(mySpy).toHaveBeenCalledWith(plugin_git_url, temp, myFunction);
+ expect(mySpy).toHaveBeenCalledWith(plugin_git_url, temp, '.', myFunction);
});
});
});
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/7d2cd7d5/src/fetch.js
----------------------------------------------------------------------
diff --git a/src/fetch.js b/src/fetch.js
index 822f28d..8d6c7b8 100644
--- a/src/fetch.js
+++ b/src/fetch.js
@@ -4,10 +4,12 @@ var shell = require('shelljs'),
xml_helpers = require('./util/xml-helpers'),
path = require('path');
-module.exports = function fetchPlugin(plugin_dir, plugins_dir, link, callback) {
+module.exports = function fetchPlugin(plugin_dir, plugins_dir, link, subdir, callback) {
// Ensure the containing directory exists.
shell.mkdir('-p', plugins_dir);
+ subdir = subdir || '.';
+
// clone from git repository
if(plugin_dir.indexOf('https://') == 0 || plugin_dir.indexOf('git://') == 0) {
if (link) {
@@ -15,11 +17,12 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, link, callback) {
if (callback) callback(err);
else throw err;
} else {
- plugins.clonePluginGitRepo(plugin_dir, plugins_dir, callback);
+ plugins.clonePluginGitRepo(plugin_dir, plugins_dir, subdir, callback);
}
} else {
// Copy from the local filesystem.
// First, read the plugin.xml and grab the ID.
+ plugin_dir = path.join(plugin_dir, subdir);
var xml = xml_helpers.parseElementtreeSync(path.join(plugin_dir, 'plugin.xml'));
var plugin_id = xml.getroot().attrib.id;
@@ -27,9 +30,9 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, link, callback) {
shell.rm('-rf', dest);
if (link) {
- fs.symlinkSync(path.resolve(plugin_dir), dest, 'dir');
+ fs.symlinkSync(plugin_dir, dest, 'dir');
} else {
- shell.cp('-R', path.join(plugin_dir, '*'), dest);
+ shell.cp('-R', plugin_dir, dest);
}
if (callback) callback(null, dest);
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/7d2cd7d5/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index 617b065..257d8de 100644
--- a/src/install.js
+++ b/src/install.js
@@ -20,7 +20,7 @@ module.exports = function installPlugin(platform, project_dir, name, plugins_dir
// Check that the plugin has already been fetched.
if (!fs.existsSync(plugin_dir)) {
// if plugin doesnt exist, use fetch to get it.
- require('../plugman').fetch(name, plugins_dir, false, function(err, plugin_dir) {
+ require('../plugman').fetch(name, plugins_dir, false, '.', function(err, plugin_dir) {
if (err) {
callback(err);
} else {
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/7d2cd7d5/src/util/plugins.js
----------------------------------------------------------------------
diff --git a/src/util/plugins.js b/src/util/plugins.js
index 0a627cb..fddecfa 100644
--- a/src/util/plugins.js
+++ b/src/util/plugins.js
@@ -25,12 +25,12 @@ var http = require('http'),
util = require('util'),
shell = require('shelljs'),
xml_helpers = require('./xml-helpers'),
- tmp_dir = path.join(path.sep, 'tmp', 'plugman-tmp');
+ tmp_dir = path.join(os.tmpdir(), 'plugman-tmp');
module.exports = {
searchAndReplace:require('./search-and-replace'),
// Fetches plugin information from remote server
- clonePluginGitRepo:function(plugin_git_url, plugins_dir, callback) {
+ clonePluginGitRepo:function(plugin_git_url, plugins_dir, subdir, callback) {
if(!shell.which('git')) {
var err = new Error('git command line is not installed');
if (callback) callback(err);
@@ -47,6 +47,7 @@ module.exports = {
else throw err;
} else {
// Read the plugin.xml file and extract the plugin's ID.
+ tmp_dir = path.join(tmp_dir, subdir);
var xml_file = path.join(tmp_dir, 'plugin.xml');
var xml = xml_helpers.parseElementtreeSync(xml_file);
var plugin_id = xml.getroot().attrib.id;
[3/4] git commit: First pass at dependency support.
Posted by br...@apache.org.
First pass at dependency support.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/6b9932ff
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/6b9932ff
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/6b9932ff
Branch: refs/heads/dependencies
Commit: 6b9932ff2930bbb8731ea3f944ed052a0f76ca30
Parents: 7d2cd7d
Author: Braden Shepherdson <br...@gmail.com>
Authored: Thu May 9 14:38:46 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Thu May 9 14:38:46 2013 -0400
----------------------------------------------------------------------
src/install.js | 4 +++
src/util/dependencies.js | 55 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/6b9932ff/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index 257d8de..d7f8c46 100644
--- a/src/install.js
+++ b/src/install.js
@@ -80,6 +80,10 @@ function runInstall(platform, project_dir, plugin_dir, plugins_dir, cli_variable
else throw err;
return;
}
+
+ // We need to install this plugin, so install its dependencies first.
+ dependencies.installAll(platform, project_dir, path.basename(plugin_dir), plugins_dir, cli_variables, www_dir, callback);
+
// TODO: if plugin does not have platform tag but has platform-agnostic config changes, should we queue it up?
var platformTag = plugin_et.find('./platform[@name="'+platform+'"]');
if (!platformTag) {
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/6b9932ff/src/util/dependencies.js
----------------------------------------------------------------------
diff --git a/src/util/dependencies.js b/src/util/dependencies.js
new file mode 100644
index 0000000..381fdf0
--- /dev/null
+++ b/src/util/dependencies.js
@@ -0,0 +1,55 @@
+var install = require('../install'),
+ fetch = require('../fetch'),
+ fs = require('fs'),
+ xml_helpers = require('./xml-helpers');
+
+exports.installAll = function(platform, project_dir, name, plugins_dir, cli_variables, www_dir, callback) {
+ // It should have been fetched already, so read the plugin.xml from plugin_dir
+ var plugin_dir = path.join(plugins_dir, name);
+ var xml = xml_helpers.parseElementtreeSync(path.join(plugin_dir, 'plugin.xml'));
+
+ var dependencies = xml.findall('dependency');
+
+ if (!dependencies || dependencies.length == 0) {
+ return;
+ }
+
+ function waitForAll(n) {
+ var count = n;
+ var errs = [];
+ return function(err) {
+ count--;
+ if (err) {
+ throw err;
+ }
+ if (count == 0) {
+ callback();
+ }
+ };
+ }
+
+ var dependencyCallback = waitForAll(dependencies.length);
+
+ dependencies && dependencies.forEach(function(dep) {
+ function doInstall(plugin_dir) {
+ // Call installation for this plugin after it gets fetched.
+ install(platform, project_dir, path.basename(plugin_dir), plugins_dir, cli_variables, www_dir, dependencyCallback);
+ }
+
+ // Check if this dependency is already there.
+ if (fs.existsSync(path.join(plugins_dir, dep.attrib.id))) {
+ console.log('Plugin ' + dep.attrib.id + ' already fetched, using that version.');
+ doInstall(path.join(plugins_dir, dep.attrib.id));
+ } else {
+ // Fetch it.
+ var subdir = dep.attrib.subdir;
+ if (subdir) {
+ subdir = path.join.apply(null, dep.attrib.subdir.split('/'));
+ }
+
+ console.log('Fetching dependency ' + dep.attrib.id);
+ fetch(dep.attrib.url, plugins_dir, false /* no link */, subdir, doInstall);
+ }
+ });
+};
+