Skip to content
This repository has been archived by the owner on Apr 18, 2019. It is now read-only.

Commit

Permalink
[CB-3798] Refactored all exec calls to use newly created utility exec…
Browse files Browse the repository at this point in the history
… function to avoid path with spaces errors
  • Loading branch information
jkeshavarzi authored and Bryan Higgins committed Aug 16, 2013
1 parent ed53b6c commit b6dfddf
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 340 deletions.
54 changes: 53 additions & 1 deletion blackberry10/bin/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

var fs = require('fs'),
path = require('path'),
childProcess = require('child_process'),
wrench = require('wrench'),
localize = require("./localize"),
os = require('os'),
Expand Down Expand Up @@ -201,7 +202,58 @@ _self = {
},

inQuotes : function (property) {
return "\"" + property + "\"";
//wrap in quotes if it's not already wrapped
if (property.indexOf("\"") === -1) {
return "\"" + property + "\"";
} else {
return property;
}
},

exec : function (command, args, options, callback) {
//Optional params handling [args, options]
if (typeof args === "Object" && !Array.isArray(args)) {
callback = options;
options = args;
args = [];
} else if (typeof args === "function"){
callback = args;
options = {};
args = [];
} else if (typeof options === "function"){
callback = options;
options = {};
}

//insert executable portion at begining of arg array
args.splice(0, 0, command);

var pkgrUtils = require("./packager-utils"),
customOptions = options._customOptions,
proc,
i;

for (i = 0; i < args.length; i++) {
if (args[i].indexOf(" ") !== -1) {
if (!_self.isWindows()) {
//remove any escaped spaces on non-Windows platforms and simply use quotes
args[i] = args[i].replace(/\\ /g, " ");
}

//put any args with spaces in quotes
args[i] = _self.inQuotes(args[i]);
}
};

//delete _customOptions from options object before sending to exec
delete options._customOptions;

proc = childProcess.exec(args.join(" "), options, callback);

if (!customOptions || !customOptions.silent) {
proc.stdout.on("data", pkgrUtils.handleProcessOutput);
proc.stderr.on("data", pkgrUtils.handleProcessOutput);
}
},

loadModule: function (path) {
Expand Down
8 changes: 6 additions & 2 deletions blackberry10/bin/templates/project/cordova/lib/bar-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ function buildTarget(previous, baton) {
baton.pass(code);
} else {
if (target === "device" && session.isSigningRequired(config)) {
signingHelper.execSigner(session, target, function (code) {
baton.pass(code);
signingHelper.execSigner(session, target, function (error, stdout, stderr) {
if (error && error.code) {
baton.pass(error.code);
} else {
baton.pass();
}
});
} else {
baton.pass(code);
Expand Down
39 changes: 11 additions & 28 deletions blackberry10/bin/templates/project/cordova/lib/debugtoken-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,12 @@ function generateDeployTokenOptions(targetIp, targetPassword) {
}

function execNativeScript(script, options, callback) {
var cp,
script = path.join(process.env.CORDOVA_BBTOOLS, script);
var script = path.join(process.env.CORDOVA_BBTOOLS, script);

if (pkgrUtils.isWindows()) {
script += ".bat";
}

cp = childProcess.spawn(script, options, {
utils.exec(script, options, {
"cwd" : workingDir,
"env" : process.env
});

cp.stdout.on("data", pkgrUtils.handleProcessOutput);

cp.stderr.on("data", pkgrUtils.handleProcessOutput);

cp.on("exit", function (code) {
if (callback && typeof callback === "function") {
callback(code);
}
});
}, callback);
}

self.createToken = function (projectProperties, target, keystorepass, callback) {
Expand Down Expand Up @@ -176,8 +161,11 @@ self.deployToken = function (target, targetIp, targetPassword, callback) {
};

self.checkDebugToken = function (pin, callback) {
var script = utils.inQuotes(path.join(process.env.CORDOVA_BBTOOLS, "blackberry-nativepackager")),
nativePackager;
var script = path.normalize(path.join(process.env.CORDOVA_BBTOOLS, "blackberry-nativepackager")),
args = [
"-listManifest",
path.normalize(debugTokenDir)
];

if (!callback || typeof callback !== "function") {
return;
Expand All @@ -188,18 +176,13 @@ self.checkDebugToken = function (pin, callback) {
return;
}

if (pkgrUtils.isWindows()) {
script += ".bat";
}

nativePackager = childProcess.exec(path.normalize(script + " -listManifest " + debugTokenDir), {
utils.exec(script, args, {
"cwd": workingDir,
"env": process.env
"env": process.env,
_customOptions: { silent: true}
}, function (error, stdout, stderr) {
callback(isDebugTokenValid(pin, stdout));
});

return;
};

module.exports = self;
81 changes: 29 additions & 52 deletions blackberry10/bin/templates/project/cordova/lib/run
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,13 @@ function generateOptions(uninstall) {
}
}

function execNativeDeploy(optionsArray, callback) {
var script = utils.inQuotes(path.join(process.env.CORDOVA_BBTOOLS, "blackberry-deploy")),
nativeDeploy,
options = optionsArray.join(" ");
function execNativeDeploy(options, callback) {
var script = path.normalize(path.join(process.env.CORDOVA_BBTOOLS, "blackberry-deploy"));

if (pkgrUtils.isWindows()) {
script += ".bat";
}

nativeDeploy = childProcess.exec(path.normalize(script + " " + options), {
utils.exec(script, options, {
"cwd": workingdir,
"env": process.env
});

nativeDeploy.stdout.on("data", pkgrUtils.handleProcessOutput);

nativeDeploy.stderr.on("data", pkgrUtils.handleProcessOutput);

nativeDeploy.on("exit", function (code) {
if (callback && typeof callback === "function") {
callback(code);
}
});
}, callback);
}

function checkDeviceInfo(ip, deviceType, callback) {
Expand Down Expand Up @@ -190,16 +174,19 @@ function deploy() {
}

function uninstall() {
var script = utils.inQuotes(path.join(process.env.CORDOVA_BBTOOLS, "blackberry-deploy")),
nativeDeploy;

if (pkgrUtils.isWindows()) {
script += ".bat";
}

nativeDeploy = childProcess.exec(script + " -listInstalledApps -device " + ip + " -password " + password, {
var script = path.join(process.env.CORDOVA_BBTOOLS, "blackberry-deploy"),
args = [
"-listInstalledApps",
"-device",
ip,
"-password",
password
];

utils.exec(script, args, {
"cwd": workingdir,
"env": process.env
"env": process.env,
_customOptions: { silent: true}
}, function (error, stdout, stderr) {
var parser = new xml2js.Parser();
fs.readFile(path.join(__dirname + "/../../www/", "config.xml"), function (err, data) {
Expand Down Expand Up @@ -244,8 +231,8 @@ function createDebugToken(previous, baton) {
baton.take();

if (needCreateDebugToken) {
debugTokenHelper.createToken(targets, "all", keystorepass, function (code) {
if (code === 0) {
debugTokenHelper.createToken(targets, "all", keystorepass, function (error, stdout, stderr) {
if (!error) {
// Deploy the debug token if created
needDeployDebugToken = true;
}
Expand Down Expand Up @@ -276,32 +263,22 @@ function handleBuildOutput(data) {
}

function build(previous, baton) {
var nativeDeploy,
execName = "./build";
var execName = utils.isWindows() ? "build" : "./build",
callback = function (code) {
// If error happened during building the bar, exit
if (code === 2) {
process.exit(2);
}

baton.take();
baton.pass();
};

if (pkgrUtils.isWindows()) {
execName = "build";
}
baton.take();

nativeDeploy = childProcess.exec(execName, {
utils.exec(execName, [], {
"cwd": path.normalize(__dirname + "/.."),
"env": process.env
});

nativeDeploy.stdout.on("data", handleBuildOutput);

nativeDeploy.stderr.on("data", handleBuildOutput);

nativeDeploy.on("exit", function (code) {
// If error happened during building the bar, exit
if (code === 2) {
process.exit(2);
}

baton.pass();
});
}, callback);
}

function postBuild() {
Expand Down
18 changes: 2 additions & 16 deletions blackberry10/bin/templates/project/cordova/lib/signing-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ function execSigner(session, target, callback) {
params = session.getParams("blackberry-signer"),
args = [];

if (pkgrUtils.isWindows()) {
script += ".bat";
}

args.push("-keystore");
args.push(session.keystore);
args.push("-storepass");
Expand All @@ -88,19 +84,9 @@ function execSigner(session, target, callback) {

args.push(path.resolve(util.format(session.barPath, target)));

signer = childProcess.spawn(script, args, {
utils.exec(script, args, {
"env": process.env
});

signer.stdout.on("data", pkgrUtils.handleProcessOutput);

signer.stderr.on("data", pkgrUtils.handleProcessOutput);

signer.on("exit", function (code) {
if (callback && typeof callback === "function") {
callback(code);
}
});
}, callback);
}

_self = {
Expand Down
29 changes: 23 additions & 6 deletions blackberry10/bin/templates/project/cordova/lib/target-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
var _self,
os = require("os"),
fs = require('fs'),
exec = require('child_process').exec,
path = require('path'),
bb10_utils = require('./utils'),
blackberryProperties = bb10_utils.getProperties();
Expand Down Expand Up @@ -66,11 +65,21 @@ _self = {
},

getDeviceInfo: function (ip, password, callback) {
var cmd = path.join(process.env.CORDOVA_BBTOOLS, 'blackberry-deploy') + ' -listDeviceInfo ' + ip;
var cmd = path.join(process.env.CORDOVA_BBTOOLS, 'blackberry-deploy'),
args = [
'-listDeviceInfo',
ip
],
options = {
_customOptions: { silent: true }
};

if (password) {
cmd += ' -password ' + password;
args.push('-password');
args.push(password);
}
exec(cmd, function (error, stdout, stderr) {

bb10_utils.exec(cmd, args, options, function (error, stdout, stderr) {
var result = {},
name = /modelname::(.*?)(\r?)\n/.exec(stdout),
pin = /devicepin::0x(.*?)(\r?)\n/.exec(stdout);
Expand Down Expand Up @@ -205,8 +214,16 @@ _self = {
},

checkConnection: function (ip, type, callback) {
var script = path.join(process.env.CORDOVA_BBTOOLS, 'blackberry-deploy');
exec(script + ' -test ' + ip, function (error, stdout, stderr) {
var script = path.join(process.env.CORDOVA_BBTOOLS, 'blackberry-deploy'),
args = [
'-test',
ip
],
options = {
_customOptions: { silent: true }
};

bb10_utils.exec(script, args, options, function (error, stdout, stderr) {
// error code 3 corresponds to a connected device, null or "Error: null" in stderr corresponds to connected simulator
callback((type === 'simulator' && (error === null || stderr.length === 0 || stderr.indexOf('Error: null') >= 0 || stderr.indexOf('Error: Authentication failed') >= 0)) || (type === 'device' && error.code === 3));
});
Expand Down
Loading

0 comments on commit b6dfddf

Please sign in to comment.