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:11 UTC

[3/4] git commit: First pass at dependency support.

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);
+        }
+    });
+};
+