Permalink
Browse files

Implements --params option for bbwp

Fixes issue blackberry/BB10-Webworks-Packager#157

Reviewed By: Adrian Z Lee <adrilee@rim.com>
Tested By: Igor Shneur <ishneur@rim.com>
  • Loading branch information...
rwmtse committed Jul 23, 2012
1 parent ce76762 commit 30bda8453b5dd2c42713cbceaf8a10e026d4b9b6
View
@@ -38,7 +38,8 @@ module.exports = function (src, baton) {
bbwpBatFile = path.join(_c.ROOT, 'bbwp.bat'),
licenseFile = path.join(_c.ROOT, 'licenses.txt'),
defaultIcon = path.join(_c.ROOT, 'default-icon.png'),
- readMeFile = path.join(_c.ROOT, 'README.txt');
+ readMeFile = path.join(_c.ROOT, 'README.txt'),
+ paramsExampleFile = path.join(_c.ROOT, "params-example.json");
//Copy folders to target directory
copyFolder(_c.FRAMEWORK_DEPLOY, frameworkDest);
@@ -52,4 +53,5 @@ module.exports = function (src, baton) {
utils.copyFile(licenseFile, _c.DEPLOY);
utils.copyFile(readMeFile, _c.DEPLOY);
utils.copyFile(defaultIcon, _c.DEPLOY);
+ utils.copyFile(paramsExampleFile, _c.DEPLOY);
};
View
@@ -20,31 +20,41 @@ var jWorkflow = require("jWorkflow"),
fileManager = require("./file-manager"),
localize = require("./localize"),
logger = require("./logger"),
+ signingHelper = require("./signing-helper"),
targetIdx = 0;
function buildTarget(previous, baton) {
baton.take();
- var target = this.session.targets[targetIdx++];
+ var target = this.session.targets[targetIdx++],
+ session = this.session,
+ config = this.config;
//Create output folder
- wrench.mkdirSyncRecursive(this.session.outputDir + "/" + target);
+ wrench.mkdirSyncRecursive(session.outputDir + "/" + target);
//Copy target dependent files
fileManager.copyWWE(this.session, target);
fileManager.copyBarDependencies(this.session, target);
fileManager.copyExtensions(this.config.accessList, this.session, target, this.extManager);
//Generate frameworkModules.js (this needs to be done AFTER all files have been copied)
- fileManager.generateFrameworkModulesJS(this.session);
-
+ fileManager.generateFrameworkModulesJS(session);
+
//Call native-packager module for target
- nativePkgr.exec(this.session, target, this.config, function (code) {
+ nativePkgr.exec(session, target, config, function (code) {
if (code !== 0) {
logger.error(localize.translate("EXCEPTION_NATIVEPACKAGER"));
+ baton.pass(code);
+ } else {
+ if (target === "device" && session.isSigningRequired(config)) {
+ signingHelper.execSigner(session, target, function (code) {
+ baton.pass(code);
+ });
+ } else {
+ baton.pass(code);
+ }
}
-
- baton.pass(code);
});
}
View
@@ -20,13 +20,14 @@ var command = require("commander"),
command
.version('1.0.0.0')
- .usage('[drive:][path]archive [-s [dir]] [[ -g genpassword] [-buildId num]] [-o dir] [-d]')
+ .usage('[drive:][path]archive [-s [dir]] [[ -g genpassword] [-buildId num]] [-o dir] [-d] [-p paramsjsonfile]')
.option('-s, --source [dir]', 'Save source. The default behaviour is to not save the source files. If dir is specified then creates dir\\src\\ directory structure. If no dir specified then the path of archive is assumed')
.option('-g, --password <password>', 'Signing key password')
.option('-buildId <num>', '[deprecated] Use --buildId.')
.option('-b, --buildId <num>', 'Specifies the build number for signing (typically incremented from previous signing).')
.option('-o, --output <dir>', 'Redirects output file location to dir. If both -o and dir are not specified then the path of archive is assumed')
.option('-d, --debug', 'Allows use of not signed build on device by utilizing debug token and enables Web Inspector.')
+ .option('-p, --params <params JSON file>', 'Specifies additional parameters to pass to downstream tools.')
.option('-v, --verbose', 'Turn on verbose messages');
function parseArgs(args) {
View
@@ -144,6 +144,12 @@ var Localize = require("localize"),
},
"EXCEPTION_EXTENSION_NOT_FOUND": {
"en": "Extension \"$[1]\" not found in \"ext\" folder"
+ },
+ "EXCEPTION_PARAMS_FILE_ERROR": {
+ "en": "An error has occurred parsing \"$[1]\""
+ },
+ "EXCEPTION_PARAMS_FILE_NOT_FOUND": {
+ "en": "\"$[1]\" does not exist"
}
}, "", ""); // TODO maybe a bug in localize, must set default locale to "" in order get it to work
View
@@ -140,9 +140,10 @@ function generateTabletXMLFile(session, config) {
function generateOptionsFile(session, target, config) {
var srcFiles = wrench.readdirSyncRecursive(session.sourceDir),
- isSigning = session.keystore && session.storepass && config.buildId,
+ isSigning = session.isSigningRequired(config),
optionsStr = "-package" + NL,
- debugToken;
+ debugToken,
+ params = session.getParams("blackberry-nativepackager");
//if -d was provided and we are not signing [-g], set debugToken
if (session.debug && !isSigning) {
@@ -160,12 +161,6 @@ function generateOptionsFile(session, target, config) {
}
if (target === "device" && isSigning) {
- //Signing params
- optionsStr += "-sign" + NL;
- optionsStr += "-keystore" + NL;
- optionsStr += session.keystore + NL;
- optionsStr += "-storepass" + NL;
- optionsStr += session.storepass + NL;
optionsStr += "-buildId" + NL;
optionsStr += config.buildId + NL;
} else if (session.debug) {
@@ -174,6 +169,16 @@ function generateOptionsFile(session, target, config) {
optionsStr += (debugToken ? debugToken : "");
}
+ if (params) {
+ Object.getOwnPropertyNames(params).forEach(function (p) {
+ optionsStr += p + NL;
+
+ if (params[p]) {
+ optionsStr += params[p] + NL;
+ }
+ });
+ }
+
optionsStr += path.resolve(util.format(session.barPath, target)) + NL;
//to supoprt splash screens/icons for multiple resolutions/devices
@@ -198,8 +203,7 @@ function generateOptionsFile(session, target, config) {
function execNativePackager(session, callback) {
var script = "/bin/blackberry-nativepackager",
cwd = session.sourceDir,
- nativePkgr,
- msg;
+ nativePkgr;
if (pkgrUtils.isWindows()) {
script += ".bat";
@@ -210,29 +214,9 @@ function execNativePackager(session, callback) {
"env": process.env
});
- nativePkgr.stdout.on("data", function (data) {
- msg = data.toString().replace(/[\n\r]/g, '');
-
- if (msg) {
- if (msg.toLowerCase().indexOf("error:") >= 0) {
- logger.error(msg);
- } else {
- logger.info(msg);
- }
- }
- });
-
- nativePkgr.stderr.on("data", function (data) {
- msg = data.toString().replace(/[\n\r]/g, '');
+ nativePkgr.stdout.on("data", pkgrUtils.handleProcessOutput);
- if (msg) {
- if (msg.toLowerCase().indexOf("warn") >= 0) {
- logger.warn(msg);
- } else {
- logger.error(msg);
- }
- }
- });
+ nativePkgr.stderr.on("data", pkgrUtils.handleProcessOutput);
nativePkgr.on("exit", function (code) {
if (callback && typeof callback === "function") {
View
@@ -18,6 +18,7 @@ var fs = require('fs'),
path = require('path'),
wrench = require('wrench'),
localize = require("./localize"),
+ logger = require("./logger"),
os = require('os'),
_self;
@@ -157,8 +158,21 @@ _self = {
loadModule: function (path) {
return require(path);
- }
+ },
+ handleProcessOutput: function (data) {
+ var msg = data.toString().replace(/[\n\r]/g, '');
+
+ if (msg) {
+ if (msg.toLowerCase().indexOf("error:") >= 0) {
+ logger.error(msg);
+ } else if (msg.toLowerCase().indexOf("warn") >= 0) {
+ logger.warn(msg);
+ } else {
+ logger.info(msg);
+ }
+ }
+ }
};
module.exports = _self;
View
@@ -18,7 +18,34 @@ var path = require("path"),
wrench = require("wrench"),
logger = require("./logger"),
signingHelper = require("./signing-helper"),
- barConf = require("./bar-conf");
+ barConf = require("./bar-conf"),
+ localize = require("./localize"),
+ params;
+
+function getParams(cmdline, toolName) {
+ if (cmdline.params) {
+ if (!params) {
+ var paramsPath = path.resolve(cmdline.params);
+
+ if (path.existsSync(paramsPath)) {
+ try {
+ params = require(paramsPath);
+ } catch (e) {
+ throw localize.translate("EXCEPTION_PARAMS_FILE_ERROR", paramsPath);
+ }
+ } else {
+ throw localize.translate("EXCEPTION_PARAMS_FILE_NOT_FOUND", paramsPath);
+ }
+ }
+
+ if (params) {
+ return params[toolName];
+ }
+ }
+
+ return null;
+}
+
module.exports = {
initialize: function (cmdline) {
@@ -72,6 +99,12 @@ module.exports = {
"keystoreDb": signingHelper.getDbPath(),
"storepass": signingPassword,
"buildId": buildId,
+ getParams: function (toolName) {
+ return getParams(cmdline, toolName);
+ },
+ isSigningRequired: function (config) {
+ return signingHelper.getKeyStorePath() && signingPassword && config.buildId;
+ },
"targets": ["simulator", "device"]
};
}
View
@@ -15,6 +15,11 @@
*/
var path = require('path'),
os = require('os'),
+ childProcess = require("child_process"),
+ util = require("util"),
+ conf = require("./conf"),
+ pkgrUtils = require("./packager-utils"),
+ logger = require("./logger"),
AUTHOR_P12 = "author.p12",
CSK = "barsigner.csk",
DB = "barsigner.db",
@@ -48,6 +53,50 @@ function getDefaultPath(file) {
}
}
+function execSigner(session, target, callback) {
+ var script = "/bin/blackberry-signer",
+ cwd = session.sourceDir,
+ signer,
+ params = session.getParams("blackberry-signer"),
+ args = [];
+
+ if (pkgrUtils.isWindows()) {
+ script += ".bat";
+ }
+
+ args.push("-keystore");
+ args.push(session.keystore);
+ args.push("-storepass");
+ args.push(session.storepass);
+
+ if (params) {
+ Object.getOwnPropertyNames(params).forEach(function (p) {
+ args.push(p);
+
+ if (params[p]) {
+ args.push(params[p]);
+ }
+ });
+ }
+
+ args.push(path.resolve(util.format(session.barPath, target)));
+
+ signer = childProcess.spawn(path.normalize(conf.DEPENDENCIES_TOOLS + script), args, {
+ "cwd": cwd,
+ "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);
+ }
+ });
+}
+
_self = {
getKeyStorePath : function () {
// Todo: decide where to put sigtool.p12 which is genereated and used in WebWorks SDK for Tablet OS
@@ -60,7 +109,9 @@ _self = {
getDbPath : function () {
return getDefaultPath(DB);
- }
+ },
+
+ execSigner: execSigner
};
module.exports = _self;
View
@@ -0,0 +1,12 @@
+{
+ "_comment": "You can specify additional parameters to be passed to downstream tools by using the bbwp --params option",
+ "blackberry-signer": {
+ "-proxyhost": "host",
+ "-proxyport": "port",
+ "-proxyusername": "user name",
+ "-proxypassword": "password"
+ },
+ "blackberry-nativepackager": {
+
+ }
+}
View
@@ -0,0 +1,10 @@
+{
+EVIL!
+ "blackberry-signer": {
+ "-proxyhost": "abc.com",
+ "-proxyport": "80"
+ },
+ "blackberry-nativepackager": {
+
+ }
+}
View
@@ -0,0 +1,9 @@
+{
+ "blackberry-signer": {
+ "-proxyhost": "abc.com",
+ "-proxyport": "80"
+ },
+ "blackberry-nativepackager": {
+
+ }
+}
Oops, something went wrong.

0 comments on commit 30bda84

Please sign in to comment.