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 2014/01/07 23:59:12 UTC
[1/2] git commit: CB-5006: Add --searchpath option for local plugin
search path
Updated Branches:
refs/heads/master 6d8c1c777 -> c8e1cb998
CB-5006: Add --searchpath option for local plugin search path
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/c8e1cb99
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/c8e1cb99
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/c8e1cb99
Branch: refs/heads/master
Commit: c8e1cb9982c243e6c0674e8c7bb799062c109d05
Parents: 9abd3d8
Author: Mark Koudritsky <ka...@chromium.org>
Authored: Tue Jan 7 16:06:58 2014 -0500
Committer: Braden Shepherdson <br...@chromium.org>
Committed: Tue Jan 7 17:58:30 2014 -0500
----------------------------------------------------------------------
doc/help.txt | 1 +
main.js | 1 +
plugman.js | 3 +-
src/fetch.js | 153 +++++++++++++++++++++++++++++++---------------------
src/install.js | 2 +-
5 files changed, 98 insertions(+), 62 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c8e1cb99/doc/help.txt
----------------------------------------------------------------------
diff --git a/doc/help.txt b/doc/help.txt
index 0c6ad7a..1ab3467 100644
--- a/doc/help.txt
+++ b/doc/help.txt
@@ -28,6 +28,7 @@ Optional parameters
- www <directory>: www assets for the plugin will be installed into this directory. Default is to install into the standard www directory for the platform specified
- plugins_dir <directory>: a copy of the plugin will be stored in this directory. Default is to install into the <project directory>/plugins folder
+ - searchpath <directory>: a colon separated list of directories to scan for a plugin with the provided ID before looking on http://plugins.cordova.io
Optional flags
--------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c8e1cb99/main.js
----------------------------------------------------------------------
diff --git a/main.js b/main.js
index 5fa6422..877c563 100755
--- a/main.js
+++ b/main.js
@@ -38,6 +38,7 @@ var known_opts = { 'platform' : [ 'ios', 'android', 'amazon-fireos', 'blackberry
, 'link': Boolean
, 'variable' : Array
, 'www': path
+ , 'searchpath' : String
}, shortHands = { 'var' : ['--variable'], 'v': ['--version'], 'h': ['--help'] };
var cli_opts = nopt(known_opts, shortHands);
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c8e1cb99/plugman.js
----------------------------------------------------------------------
diff --git a/plugman.js b/plugman.js
index 7f7ac5c..4c0f61b 100755
--- a/plugman.js
+++ b/plugman.js
@@ -97,7 +97,8 @@ plugman.commands = {
var opts = {
subdir: '.',
cli_variables: cli_variables,
- www_dir: cli_opts.www
+ www_dir: cli_opts.www,
+ searchpath: cli_opts.searchpath ? cli_opts.searchpath.split(':') : []
};
return plugman.install(cli_opts.platform, cli_opts.project, cli_opts.plugin, cli_opts.plugins_dir, opts);
},
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c8e1cb99/src/fetch.js
----------------------------------------------------------------------
diff --git a/src/fetch.js b/src/fetch.js
index 0d50187..2f45f5f 100644
--- a/src/fetch.js
+++ b/src/fetch.js
@@ -10,16 +10,17 @@ var shell = require('shelljs'),
// XXX: leave the require('../plugman') because jasmine shits itself if you declare it up top
// possible options: link, subdir, git_ref, client, expected_id
// Returns a promise.
-module.exports = function fetchPlugin(plugin_dir, plugins_dir, options) {
- require('../plugman').emit('log', 'Fetching plugin from "' + plugin_dir + '"...');
+module.exports = function fetchPlugin(plugin_src, plugins_dir, options) {
+ require('../plugman').emit('log', 'Fetching plugin from "' + plugin_src + '"...');
// Ensure the containing directory exists.
shell.mkdir('-p', plugins_dir);
options = options || {};
options.subdir = options.subdir || '.';
+ options.searchpath = options.searchpath || [];
// clone from git repository
- var uri = url.parse(plugin_dir);
+ var uri = url.parse(plugin_src);
// If the hash exists, it has the form from npm: http://foo.com/bar#git-ref[:subdir]
// NB: No leading or trailing slash on the subdir.
@@ -32,27 +33,28 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, options) {
options.subdir = result[2];
// Recurse and exit with the new options and truncated URL.
- var new_dir = plugin_dir.substring(0, plugin_dir.indexOf('#'));
+ var new_dir = plugin_src.substring(0, plugin_src.indexOf('#'));
return fetchPlugin(new_dir, plugins_dir, options);
}
}
- if ( uri.protocol && uri.protocol != 'file:' && !plugin_dir.match(/^\w+:\\/)) {
+ // If it looks like a network URL, git clone it.
+ if ( uri.protocol && uri.protocol != 'file:' && !plugin_src.match(/^\w+:\\/)) {
if (options.link) {
return Q.reject(new Error('--link is not supported for git URLs'));
} else {
var data = {
source: {
type: 'git',
- url: plugin_dir,
+ url: plugin_src,
subdir: options.subdir,
ref: options.git_ref
}
};
- return plugins.clonePluginGitRepo(plugin_dir, plugins_dir, options.subdir, options.git_ref)
+ return plugins.clonePluginGitRepo(plugin_src, plugins_dir, options.subdir, options.git_ref)
.then(function(dir) {
- return checkID(options, dir);
+ return checkID(options.expected_id, dir);
})
.then(function(dir) {
metadata.save_fetch_metadata(dir, data);
@@ -60,70 +62,101 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, options) {
});
}
} else {
+ // If it's not a network URL, it's either a local path or a plugin ID.
- // Copy from the local filesystem.
- // First, read the plugin.xml and grab the ID.
// NOTE: Can't use uri.href here as it will convert spaces to %20 and make path invalid.
- // Use original plugin_dir value instead.
- plugin_dir = path.join(plugin_dir, options.subdir);
-
- var linkable = true;
- var movePlugin = function(plugin_dir) {
- var plugin_xml_path = path.join(plugin_dir, 'plugin.xml');
- require('../plugman').emit('verbose', 'Fetch is reading plugin.xml from location "' + plugin_xml_path + '"...');
- var xml = xml_helpers.parseElementtreeSync(plugin_xml_path);
- var plugin_id = xml.getroot().attrib.id;
-
- var dest = path.join(plugins_dir, plugin_id);
-
- shell.rm('-rf', dest);
- if (options.link && linkable) {
- require('../plugman').emit('verbose', 'Symlinking from location "' + plugin_dir + '" to location "' + dest + '"');
- fs.symlinkSync(plugin_dir, dest, 'dir');
- } else {
- shell.mkdir('-p', dest);
- require('../plugman').emit('verbose', 'Copying from location "' + plugin_dir + '" to location "' + dest + '"');
- shell.cp('-R', path.join(plugin_dir, '*') , dest);
- }
+ // Use original plugin_src value instead.
- var data = {
- source: {
- type: 'local',
- path: plugin_dir
- }
- };
- metadata.save_fetch_metadata(dest, data);
- return dest;
- };
+ var p, // The Q promise to be returned.
+ linkable = true,
+ plugin_dir = path.join(plugin_src, options.subdir);
- if(!fs.existsSync(plugin_dir)) {
- return registry.fetch([plugin_dir], options.client)
- .then(function(dir) {
+ if (fs.existsSync(plugin_dir)) {
+ p = Q(plugin_dir);
+ } else {
+ // If there is no such local path, it's a plugin id.
+ // First look for it in the local search path (if provided).
+ var local_dir = findLocalPlugin(plugin_src, options.searchpath);
+ if(local_dir) {
+ p = Q(local_dir);
+ } else {
+ // If not found in local search path, fetch from the registry.
linkable = false;
- return movePlugin(dir);
+ p = registry.fetch([plugin_src], options.client);
+ }
+ }
+
+ return p
+ .then(function(dir) {
+ return copyPlugin(dir, plugins_dir, options.link && linkable);
})
- .then(function(dir) {
- return checkID(options, dir);
+ .then(function(dir) {
+ return checkID(options.expected_id, dir);
});
- } else {
- return Q(movePlugin(plugin_dir))
- .then(function(dir) {
- return checkID(options, dir);
- });
- }
}
};
+
+function readId(dir) {
+ var xml_path = path.join(dir, 'plugin.xml');
+ require('../plugman').emit('verbose', 'Fetch is reading plugin.xml from location "' + xml_path + '"...');
+ var et = xml_helpers.parseElementtreeSync(path.join(dir, 'plugin.xml'));
+ var plugin_id = et.getroot().attrib.id;
+ return plugin_id;
+}
+
// Helper function for checking expected plugin IDs against reality.
-function checkID(options, dir) {
- // Read the plugin.xml file and check the ID matches options.expected_id if set.
- if (options.expected_id) {
- var et = xml_helpers.parseElementtreeSync(path.join(dir, 'plugin.xml'));
- if (et.getroot().attrib.id == options.expected_id) {
- return dir;
- } else {
- return Q.reject(new Error('Expected Fetched plugin to have ID "' + options.expected_id + '" but got "' + et.getroot().attrib.id + '".'));
+function checkID(expected_id, dir) {
+ if ( expected_id ) {
+ var id = readId(dir);
+ if (expected_id != id) {
+ throw new Error('Expected fetched plugin to have ID "' + expected_id + '" but got "' + id + '".');
}
}
return dir;
}
+
+// Look for plugin in local search path.
+function findLocalPlugin(plugin_id, searchpath) {
+ for(var i = 0; i < searchpath.length; i++){
+ var files = fs.readdirSync(searchpath[i]);
+ for (var j = 0; j < files.length; j++){
+ var plugin_path = path.join(searchpath[i], files[j]);
+ try {
+ var id = readId(plugin_path);
+ if (plugin_id === id) {
+ return plugin_path;
+ }
+ }
+ catch(err) {
+ require('../plugman').emit('verbose', 'Error while trying to read plugin.xml from ' + plugin_path);
+ }
+ }
+ }
+ return null;
+}
+
+
+// Copy or link a plugin from plugin_dir to plugins_dir/plugin_id.
+function copyPlugin(plugin_dir, plugins_dir, link) {
+ var plugin_id = readId(plugin_dir);
+ var dest = path.join(plugins_dir, plugin_id);
+ shell.rm('-rf', dest);
+ if (link) {
+ require('../plugman').emit('verbose', 'Symlinking from location "' + plugin_dir + '" to location "' + dest + '"');
+ fs.symlinkSync(plugin_dir, dest, 'dir');
+ } else {
+ shell.mkdir('-p', dest);
+ require('../plugman').emit('verbose', 'Copying from location "' + plugin_dir + '" to location "' + dest + '"');
+ shell.cp('-R', path.join(plugin_dir, '*') , dest);
+ }
+
+ var data = {
+ source: {
+ type: 'local',
+ path: plugin_dir
+ }
+ };
+ metadata.save_fetch_metadata(dest, data);
+ return dest;
+}
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/c8e1cb99/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index 37b78e1..28c030f 100644
--- a/src/install.js
+++ b/src/install.js
@@ -50,7 +50,7 @@ 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.
- return require('../plugman').raw.fetch(id, plugins_dir, { link: false, subdir: options.subdir, git_ref: options.git_ref, client: 'plugman', expected_id: options.expected_id })
+ return require('../plugman').raw.fetch(id, plugins_dir, { link: false, subdir: options.subdir, git_ref: options.git_ref, client: 'plugman', expected_id: options.expected_id, searchpath: options.searchpath })
.then(function(plugin_dir) {
return runInstall(actions, platform, project_dir, plugin_dir, plugins_dir, options);
});
[2/2] git commit: White space & style fixes.
Posted by br...@apache.org.
White space & style fixes.
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/9abd3d87
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/9abd3d87
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/9abd3d87
Branch: refs/heads/master
Commit: 9abd3d87d801fa30573fd42b24b97a032b691099
Parents: 6d8c1c7
Author: Mark Koudritsky <ka...@chromium.org>
Authored: Mon Jan 6 22:57:43 2014 -0500
Committer: Braden Shepherdson <br...@chromium.org>
Committed: Tue Jan 7 17:58:30 2014 -0500
----------------------------------------------------------------------
plugman.js | 6 +++---
src/install.js | 37 +++++++++++++++++--------------------
2 files changed, 20 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/9abd3d87/plugman.js
----------------------------------------------------------------------
diff --git a/plugman.js b/plugman.js
index a7ff484..7f7ac5c 100755
--- a/plugman.js
+++ b/plugman.js
@@ -119,7 +119,7 @@ plugman.commands = {
if (err) throw err;
else {
for(var plugin in plugins) {
- console.log(plugins[plugin].name, '-', plugins[plugin].description || 'no description provided');
+ console.log(plugins[plugin].name, '-', plugins[plugin].description || 'no description provided');
}
}
});
@@ -140,7 +140,7 @@ plugman.commands = {
},
'publish' : function(cli_opts) {
- var plugin_path = cli_opts.argv.remain;
+ var plugin_path = cli_opts.argv.remain;
if(!plugin_path) {
return console.log(plugman.help());
}
@@ -151,7 +151,7 @@ plugman.commands = {
},
'unpublish': function(cli_opts) {
- var plugin = cli_opts.argv.remain;
+ var plugin = cli_opts.argv.remain;
if(!plugin) {
return console.log(plugman.help());
}
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/9abd3d87/src/install.js
----------------------------------------------------------------------
diff --git a/src/install.js b/src/install.js
index 6b09434..37b78e1 100644
--- a/src/install.js
+++ b/src/install.js
@@ -1,9 +1,6 @@
var path = require('path'),
fs = require('fs'),
- fetch = require('./fetch'),
- et = require('elementtree'),
action_stack = require('./util/action-stack'),
- shell = require('shelljs'),
child_process = require('child_process'),
semver = require('semver'),
config_changes = require('./util/config-changes'),
@@ -65,7 +62,7 @@ function possiblyFetch(actions, platform, project_dir, id, plugins_dir, options)
function checkEngines(engines) {
for(var i = 0; i < engines.length; i++) {
var engine = engines[i];
- if(semver.satisfies(engine.currentVersion, engine.minVersion) || engine.currentVersion == null){
+ if(semver.satisfies(engine.currentVersion, engine.minVersion) || engine.currentVersion === null){
// engine ok!
}else{
return Q.reject(new Error('Plugin doesn\'t support this project\'s '+engine.name+' version. '+engine.name+': ' + engine.currentVersion + ', failed version requirement: ' + engine.minVersion));
@@ -81,7 +78,7 @@ function cleanVersionOutput(version, name){
var dev_index = out.indexOf('dev');
if (rc_index > -1) {
out = out.substr(0, rc_index) + '-' + out.substr(rc_index);
- }
+ }
// strip out the -dev and put a warning about using the dev branch
if (dev_index > -1) {
@@ -92,22 +89,22 @@ function cleanVersionOutput(version, name){
out = out.substr(0, dev_index-1);
}
require('../plugman').emit('verbose', name+' has been detected as using a development branch. Attemping to install anyways.');
- }
-
+ }
+
// add extra period/digits to conform to semver - some version scripts will output
// just a major or major minor version number
var majorReg = /\d+/,
minorReg = /\d+\.\d+/,
patchReg = /\d+\.\d+\.\d+/;
-
+
if(patchReg.test(out)){
-
+
}else if(minorReg.test(out)){
out = out.match(minorReg)[0]+'.0';
}else if(majorReg.test(out)){
out = out.match(majorReg)[0]+'.0.0';
- }
-
+ }
+
return out;
}
@@ -120,7 +117,7 @@ function callEngineScripts(engines) {
engines.map(function(engine){
// CB-5192; on Windows scriptSrc doesn't have file extension so we shouldn't check whether the script exists
if(isWindows || fs.existsSync(engine.scriptSrc)){
-
+
if(!isWindows) { // not required on Windows
fs.chmodSync(engine.scriptSrc, '755');
}
@@ -154,9 +151,9 @@ function getEngines(pluginElement, platform, project_dir, plugin_dir){
var uncheckedEngines = [];
var cordovaEngineIndex, cordovaPlatformEngineIndex, theName, platformIndex, defaultPlatformIndex;
// load in known defaults and update when necessary
- engines.forEach(function(engine){
+ engines.forEach(function(engine){
theName = engine.attrib["name"];
-
+
// check to see if the engine is listed as a default engine
if(defaultEngines[theName]){
// make sure engine is for platform we are installing on
@@ -166,11 +163,11 @@ function getEngines(pluginElement, platform, project_dir, plugin_dir){
defaultEngines[theName].currentVersion = defaultEngines[theName].currentVersion ? defaultEngines[theName].currentVersion : null;
defaultEngines[theName].scriptSrc = defaultEngines[theName].scriptSrc ? defaultEngines[theName].scriptSrc : null;
defaultEngines[theName].name = theName;
-
+
// set the indices so we can pop the cordova engine when needed
if(theName==='cordova') cordovaEngineIndex = uncheckedEngines.length;
if(theName==='cordova-'+platform) cordovaPlatformEngineIndex = uncheckedEngines.length;
-
+
uncheckedEngines.push(defaultEngines[theName]);
}
// check for other engines
@@ -181,7 +178,7 @@ function getEngines(pluginElement, platform, project_dir, plugin_dir){
}
}
});
-
+
// make sure we check for platform req's and not just cordova reqs
if(cordovaEngineIndex && cordovaPlatformEngineIndex) uncheckedEngines.pop(cordovaEngineIndex);
return uncheckedEngines;
@@ -222,13 +219,13 @@ var runInstall = module.exports.runInstall = function runInstall(actions, platfo
.then(checkEngines)
.then(function() {
// checking preferences, if certain variables are not provided, we should throw.
- prefs = plugin_et.findall('./preference') || [];
+ var prefs = plugin_et.findall('./preference') || [];
prefs = prefs.concat(plugin_et.findall('./platform[@name="'+platform+'"]/preference'));
var missing_vars = [];
prefs.forEach(function (pref) {
var key = pref.attrib["name"].toUpperCase();
options.cli_variables = options.cli_variables || {};
- if (options.cli_variables[key] == undefined)
+ if (options.cli_variables[key] === undefined)
missing_vars.push(key)
else
filtered_variables[key] = options.cli_variables[key]
@@ -360,7 +357,7 @@ function handleInstall(actions, plugin_id, plugin_et, platform, project_dir, plu
resourceFiles && resourceFiles.forEach(function(resource) {
actions.push(actions.createAction(handler["resource-file"].install, [resource, plugin_dir, project_dir], handler["resource-file"].uninstall, [resource, project_dir]));
});
- // CB-5238 custom frameworks only
+ // CB-5238 custom frameworks only
frameworkFiles && frameworkFiles.forEach(function(framework) {
actions.push(actions.createAction(handler["framework"].install, [framework, plugin_dir, project_dir, plugin_id], handler["framework"].uninstall, [framework, project_dir]));
});