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/06/04 00:03:33 UTC

[1/2] git commit: Add support for relative dependencies with a url of "."

Updated Branches:
  refs/heads/master fbb776847 -> dc4fcb5d3


Add support for relative dependencies with a url of "."


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

Branch: refs/heads/master
Commit: dc4fcb5d38cb83f72fe45d852c320fd44e33b77b
Parents: f7a7a45
Author: Braden Shepherdson <br...@gmail.com>
Authored: Mon Jun 3 16:51:11 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Mon Jun 3 18:03:21 2013 -0400

----------------------------------------------------------------------
 plugin_spec.md |   10 ++++++++--
 src/install.js |   44 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 51 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/dc4fcb5d/plugin_spec.md
----------------------------------------------------------------------
diff --git a/plugin_spec.md b/plugin_spec.md
index ebc344f..2fbabbf 100644
--- a/plugin_spec.md
+++ b/plugin_spec.md
@@ -146,15 +146,21 @@ If `src` does not resolve to a file that can be found, plugman will stop/reverse
 
 Dependency tags let you specify plugins on which this plugin depends. In the future there will be plugin repositories to fetch plugins from. In the short term, plugins are directly pointed to by URLs in `<dependency>` tags. These tags have the following format:
 
-    <dependency id="com.plugin.id" src="https://github.com/myuser/someplugin" commit="428931ada3891801" subdir="some/path/here" />
+    <dependency id="com.plugin.id" url="https://github.com/myuser/someplugin" commit="428931ada3891801" subdir="some/path/here" />
 
 * `id`: gives the ID of the plugin. This should be globally unique, and in reverse-domain style. Neither of these restrictions is currently enforced, but they may be in the future and plugins should still follow them.
-* `src`: A URL for the plugin. This should point to a git repository, since plugman will try to `git clone` it.
+* `url`: A URL for the plugin. This should point to a git repository, since plugman will try to `git clone` it.
 * `commit`: This is any git ref. It can be a branch or tag name (eg. `master`, `0.3.1`), a commit hash (eg. `975ddb228af811dd8bb37ed1dfd092a3d05295f9`), anything understood by `git checkout`.
 * `subdir`: Specifies that the plugin we're interested in exists as a subdirectory of the git repository. This is helpful because it allows one to keep several related plugins in a sigle git repository, and specify the plugins in it individually.
 
 In the future, version constraints will be introduced, and a plugin repository will exist to support fetching by name instead of explicit URLs.
 
+### Relative Dependency Paths
+
+You can set the `url` of a `<dependency>` tag to `"."`, and give it a `subdir`. Then the dependent plugin will be installed from the same local or remote git repository as the parent plugin where the `<dependency>` tag is.
+
+Note that the `subdir` is, as always, relative to the _root of the git repository_, not the parent plugin. This is true even if you installed the plugin with a local path directly to it. Plugman will find the root of the git repository and then find the other plugin from there.
+
 ## &lt;platform&gt;
 
 Platform tags identify platforms that have associated native code and/or require configuration file modifications. Tools using

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/dc4fcb5d/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index f744468..ba9746f 100644
--- a/src/install.js
+++ b/src/install.js
@@ -31,7 +31,6 @@ function possiblyFetch(actions, platform, project_dir, id, plugins_dir, options,
     // Check that the plugin has already been fetched.
     if (!fs.existsSync(plugin_dir)) {
         // if plugin doesnt exist, use fetch to get it.
-        // TODO: Actual value for git_ref.
         require('../plugman').fetch(id, plugins_dir, { link: false, subdir: '.', git_ref: options.git_ref }, function(err, plugin_dir) {
             if (err) {
                 callback(err);
@@ -140,6 +139,48 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt
             if (dep_subdir) {
                 dep_subdir = path.join.apply(null, dep_subdir.split('/'));
             }
+
+            // Handle relative dependency paths by expanding and resolving them.
+            // The easy case of relative paths is to have a URL of '.' and a different subdir.
+            // TODO: Implement the hard case of different repo URLs, rather than the special case of
+            // same-repo-different-subdir.
+            if (dep_url == '.') {
+                // Look up the parent plugin's fetch metadata and determine the correct URL.
+                var fetchdata = require('./util/metadata').get_fetch_metadata(plugin_dir);
+                
+                if (!fetchdata || !(fetchdata.source && fetchdata.source.type)) {
+                    var err = new Error('No fetch metadata found for ' + plugin_id + '. Cannot install relative dependencies.');
+                    if (callback) callback(err);
+                    throw err;
+                    return;
+                }
+
+                // Now there are two cases here: local directory, and git URL.
+                if (fetchdata.source.type === 'local') {
+                    dep_url = fetchdata.source.path;
+
+                    var old_pwd = shell.pwd();
+                    shell.cd(dep_url);
+                    var result = shell.exec('git rev-parse --show-toplevel', { silent:true, async:false});
+                    if (result.code === 128) {
+                        var err = new Error('Error: Plugin ' + plugin_id + ' is not in git repository. All plugins must be in a git repository.');
+                        if (callback) callback(err);
+                        else throw err;
+                        return;
+                    } else if(result.code > 0) {
+                        var err = new Error('Error trying to locate git repository for plugin.');
+                        if (callback) callback(err);
+                        else throw err;
+                        return;
+                    }
+
+                    var dep_url = path.join(result.output.trim(), dep_subdir);
+                    shell.cd(old_pwd);
+                } else if (fetchdata.source.type === 'git') {
+                    dep_url = fetchdata.source.url;
+                }
+            }
+
             var dep_plugin_dir = path.join(plugins_dir, dep_plugin_id);
             if (fs.existsSync(dep_plugin_dir)) {
                 console.log('Dependent plugin ' + dep_plugin_id + ' already fetched, using that version.');
@@ -155,6 +196,7 @@ function runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, opt
                     cli_variables: filtered_variables,
                     www_dir: options.www_dir,
                     is_top_level: false,
+                    subdir: dep_subdir,
                     git_ref: dep_git_ref
                 };
 


[2/2] git commit: Add .fetch.json metadata file to plugin dirs after fetch

Posted by br...@apache.org.
Add .fetch.json metadata file to plugin dirs after fetch

This file holds data about where this plugin was fetched from. This
facilitates updating plugins and installing relative 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/f7a7a45e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/f7a7a45e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/f7a7a45e

Branch: refs/heads/master
Commit: f7a7a45e8793b7e2781d3da670a81e29154789da
Parents: fbb7768
Author: Braden Shepherdson <br...@gmail.com>
Authored: Mon Jun 3 15:47:15 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Mon Jun 3 18:03:21 2013 -0400

----------------------------------------------------------------------
 src/fetch.js         |   24 +++++++++++++++++++++++-
 src/util/metadata.js |   19 +++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/f7a7a45e/src/fetch.js
----------------------------------------------------------------------
diff --git a/src/fetch.js b/src/fetch.js
index 201f495..68f5113 100644
--- a/src/fetch.js
+++ b/src/fetch.js
@@ -2,6 +2,7 @@ var shell   = require('shelljs'),
     fs      = require('fs'),
     plugins = require('./util/plugins'),
     xml_helpers = require('./util/xml-helpers'),
+    metadata = require('./util/metadata'),
     path    = require('path');
 
 // possible options: link, subdir, git_ref
@@ -19,7 +20,20 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, options, callback
             if (callback) callback(err);
             else throw err;
         } else {
-            plugins.clonePluginGitRepo(plugin_dir, plugins_dir, options.subdir, options.git_ref, callback);
+            var data = {
+                source: {
+                    type: 'git',
+                    url:  plugin_dir,
+                    subdir: options.subdir,
+                    ref: options.git_ref
+                }
+            };
+
+            plugins.clonePluginGitRepo(plugin_dir, plugins_dir, options.subdir, options.git_ref, function(err, dir) {
+                if (!err) {
+                    metadata.save_fetch_metadata(dir, data);
+                }
+            });
         }
     } else {
         if (plugin_dir.lastIndexOf('file://', 0) === 0) {
@@ -42,6 +56,14 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, options, callback
             shell.cp('-R', path.join(plugin_dir, '*') , dest);
         }
 
+        var data = {
+            source: {
+                type: 'local',
+                path: plugin_dir
+            }
+        };
+        metadata.save_fetch_metadata(dest, data);
+
         if (callback) callback(null, dest);
     }
 };

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/f7a7a45e/src/util/metadata.js
----------------------------------------------------------------------
diff --git a/src/util/metadata.js b/src/util/metadata.js
new file mode 100644
index 0000000..cfbb643
--- /dev/null
+++ b/src/util/metadata.js
@@ -0,0 +1,19 @@
+var fs = require('fs'),
+    path = require('path');
+
+var filename = '.fetch.json';
+
+exports.get_fetch_metadata = function(plugin_dir) {
+    var filepath = path.join(plugin_dir, filename);
+    if (fs.existsSync(filepath)) {
+        return JSON.parse(fs.readFileSync(filepath, 'utf-8'));
+    } else {
+        return {};
+    }
+};
+
+exports.save_fetch_metadata = function(plugin_dir, data) {
+    var filepath = path.join(plugin_dir, '.fetch.json');
+    fs.writeFileSync(filepath, JSON.stringify(data), 'utf-8');
+};
+