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 <[email protected]>
Authored: Mon Jun 3 16:51:11 2013 -0400
Committer: Braden Shepherdson <[email protected]>
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
                 };
 

Reply via email to