Skip to content

Commit

Permalink
Refactor out static getPort calls
Browse files Browse the repository at this point in the history
  • Loading branch information
janjongboom committed May 25, 2012
1 parent 87a59f5 commit 64505f1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion plugins-server/cloud9.run.node/node-runner.js
Expand Up @@ -99,7 +99,7 @@ var Runner = exports.Runner = function(options, callback) {
else {
startProcess(options.url, port);
}
});
});

function startProcess (url, port) {
self.port = port;
Expand Down
7 changes: 5 additions & 2 deletions plugins-server/cloud9.run.npm/npm.js
Expand Up @@ -14,15 +14,15 @@ var exports = module.exports = function setup(options, imports, register) {
imports.sandbox.getUnixId(function(err, unixId) {
if (err) return register(err);

pm.addRunner("npm", exports.factory(unixId));
pm.addRunner("npm", exports.factory(unixId, imports.sandbox));

register(null, {
"run-npm": {}
});
});
};

exports.factory = function(uid) {
exports.factory = function(uid, sandbox) {
return function(args, eventEmitter, eventName, callback) {
var options = {};
c9util.extend(options, args);
Expand All @@ -31,6 +31,9 @@ exports.factory = function(uid) {
options.eventName = eventName;
options.args = args.args;
options.command = "npm";

options.sandbox = sandbox;

return new Runner(options, callback);
};
};
Expand Down
25 changes: 14 additions & 11 deletions plugins-server/cloud9.run.npmnode/npmnode.js
Expand Up @@ -11,32 +11,27 @@ var exports = module.exports = function setup(options, imports, register) {
sandbox.getUserDir(function(err, userDir) {
if (err) return register(err);

sandbox.getPort(function(err, port) {
sandbox.getUnixId(function(err, unixId) {
if (err) return register(err);

sandbox.getUnixId(function(err, unixId) {
if (err) return register(err);

init(userDir, port, unixId);
});
init(userDir, unixId);
});
});

function init(userDir, port, unixId) {
pm.addRunner("run-npm", exports.factory(userDir, port, unixId));
function init(userDir, unixId) {
pm.addRunner("run-npm", exports.factory(imports.sandbox, userDir, unixId));

register(null, {
"run-run-npm": {}
});
}
};

exports.factory = function(root, port, uid) {
exports.factory = function(sandbox, root, uid) {
return function(args, eventEmitter, eventName, callback) {
var options = {};
c9util.extend(options, args);
options.root = root;
options.port = port;
options.uid = uid;
options.file = args.file;
options.args = args.args;
Expand All @@ -46,6 +41,8 @@ exports.factory = function(root, port, uid) {
options.eventEmitter = eventEmitter;
options.eventName = eventName;

options.sandbox = sandbox;

new Runner(options, callback);
};
};
Expand All @@ -61,7 +58,13 @@ var Runner = exports.Runner = function(options, callback) {
options.env = options.env || {};
options.command = process.execPath;

ShellRunner.call(this, options, callback);
options.sandbox.getPort(function (err, port) {
if (err) return callback(err);

options.port = port;

ShellRunner.call(this, options, callback);
});
};

util.inherits(Runner, ShellRunner);
Expand Down
2 changes: 1 addition & 1 deletion plugins-server/cloud9.run.shell/shell.js
Expand Up @@ -116,7 +116,7 @@ var Runner = exports.Runner = function(options, callback) {
this.args = ["-Hu", "#" + this.uid, this.command].concat(this.args);
this.command = "sudo";
}

try {
var child = spawn(this.command, this.args, this.runOptions);
} catch (e) {
Expand Down

0 comments on commit 64505f1

Please sign in to comment.