cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bra...@apache.org
Subject [1/4] git commit: Make plugin cache directories be named after the plugin ID
Date Fri, 10 May 2013 18:39:09 GMT
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 <braden.shepherdson@gmail.com>
Authored: Thu May 9 12:18:58 2013 -0400
Committer: Braden Shepherdson <braden.shepherdson@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);
             }
         });


Mime
View raw message