Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C37ACDB7A for ; Fri, 24 May 2013 21:17:53 +0000 (UTC) Received: (qmail 56540 invoked by uid 500); 24 May 2013 21:17:53 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 56500 invoked by uid 500); 24 May 2013 21:17:53 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 56493 invoked by uid 99); 24 May 2013 21:17:53 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 May 2013 21:17:53 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 6FFFDED0C; Fri, 24 May 2013 21:17:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bhiggins@apache.org To: commits@cordova.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: webworks commit: [CB-2927] [CB-2939] Update build and run scripts to more closely match cordova spec Date: Fri, 24 May 2013 21:17:53 +0000 (UTC) Updated Branches: refs/heads/2.8.x b42482ac4 -> 1e2f28cba [CB-2927] [CB-2939] Update build and run scripts to more closely match cordova spec - run now invokes build rather than the reverse - changes to argument syntax - moved the debug token feature from "build" script to "run" script - added a validation feature for debug token so it won't be created all the time - added --no-build and --keystorepass for "run" script - added a default build.id in config.xml - cleaned up output messages - removed "keystorepass" from the default project.json Reviewed by Bryan Higgins Tested by Tracy Li Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/1e2f28cb Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/1e2f28cb Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/1e2f28cb Branch: refs/heads/2.8.x Commit: 1e2f28cba401642cf75091bebce7212cd74ba016 Parents: b42482a Author: Eric Li Authored: Fri May 24 14:25:00 2013 -0400 Committer: Bryan Higgins Committed: Fri May 24 17:17:09 2013 -0400 ---------------------------------------------------------------------- .../bin/templates/project/cordova/lib/build | 132 ++++------- .../project/cordova/lib/debugtoken-helper.js | 70 ++++++ .../bin/templates/project/cordova/lib/localize.js | 7 +- .../project/cordova/lib/packager-validator.js | 3 - blackberry10/bin/templates/project/cordova/lib/run | 194 +++++++++++---- blackberry10/bin/templates/project/project.json | 1 - blackberry10/bin/templates/project/www/config.xml | 2 +- 7 files changed, 257 insertions(+), 152 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/1e2f28cb/blackberry10/bin/templates/project/cordova/lib/build ---------------------------------------------------------------------- diff --git a/blackberry10/bin/templates/project/cordova/lib/build b/blackberry10/bin/templates/project/cordova/lib/build old mode 100644 new mode 100755 index 3fb3432..d2a8ea6 --- a/blackberry10/bin/templates/project/cordova/lib/build +++ b/blackberry10/bin/templates/project/cordova/lib/build @@ -18,11 +18,7 @@ var path = require("path"), command = require("commander"), - jWorkflow = require("jWorkflow"), - localize = require("./localize"), - logger = require("./logger"), projectProperties = require("../../project.json"), - debugTokenHelper = require("./debugtoken-helper"), bbwpArgv = [ process.argv[0], path.resolve(path.join(__dirname, process.argv[1])), @@ -30,12 +26,10 @@ var path = require("path"), "-o", path.resolve(path.join(__dirname, "..", "..", "build")) ], - built = false, - debugtoken = false; - -function getTarget() { - return typeof command.args[0] === "string" ? command.args[0] : undefined; -} + jWorkflow = require("jWorkflow"), + childProcess = require("child_process"), + pkgrUtils = require("./packager-utils"), + commandStr; function copyArgIfExists(arg) { if (command[arg]) { @@ -44,49 +38,14 @@ function copyArgIfExists(arg) { } } -function createDebugtoken(previous, baton) { - var keystorepass = command["keystorepass"] ? command["keystorepass"] : projectProperties.keystorepass; - baton.take(); - logger.info(localize.translate("PROGRESS_WILL_CREATE_DEBUG_TOKEN")); - debugTokenHelper.createToken(projectProperties, getTarget(), keystorepass, function (code) { - if (code === 0) { - debugtoken = true; - } - - baton.pass(); - }); -} - -function deployDebugToken(previous, baton) { - baton.take(); - - // If in debug build and debug token was created, deploy the debug token and wait until the deployment is finished - if (debugtoken) { - logger.info(localize.translate("PROGRESS_WILL_DEPLOY_DEBUG_TOKEN")); - debugTokenHelper.deployToken(projectProperties, getTarget(), function () { - baton.pass(); - }); - } else { - baton.pass(); - } -} - function doDebugBuild() { - built = true; - //build in debug mode by default bbwpArgv.push("-d"); - // In debug build, it needs to create debug token first - jWorkflow.order(createDebugtoken) - .andThen(deployDebugToken) - .andThen(build) - .start(); + build(); } function doReleaseBuild() { - built = true; - //Note: Packager refers to signing password as "password" not "keystorepass" if (command["keystorepass"]) { bbwpArgv.push("--password"); @@ -95,7 +54,8 @@ function doReleaseBuild() { bbwpArgv.push("--password"); bbwpArgv.push( projectProperties.keystorepass); } else { - throw "No signing password provided. Please use --keystorepass via command-line or enter a value for keystorepass in project.json"; + console.log("No signing password provided. Please use --keystorepass via command-line or enter a value for keystorepass in project.json"); + process.exit(2); } copyArgIfExists("buildId"); @@ -107,68 +67,64 @@ function build() { copyArgIfExists("params"); copyArgIfExists("loglevel"); - //Overrite process.argv, before calling packager + //Overwrite process.argv, before calling packager process.argv = bbwpArgv; //Delete cached commander object. It will conflict with the packagers commander delete require.cache[require.resolve("commander")]; delete require.cache[require.resolve("commander/lib/commander")]; - //Package app. If successfull call run - require("./packager").start(run); + require("./packager").start(function() {}); } -function run() { - var target = getTarget(); +function postClean() { + if (command.release) { + doReleaseBuild(); + } else { + doDebugBuild(); + } +} - //Overrite process.argv, before calling run - process.argv = [ - process.argv[0], - process.argv[1], - ]; +function clean(previous, baton) { + var cleanScript; - if (target) { - process.argv.push(target); - } + baton.take(); - //deploy app - require("./run"); -} + cleanScript = childProcess.exec("./clean", { + "cwd": path.normalize(__dirname + "/.."), + "env": process.env + }); -command - .usage('command [] [-k | --keystorepass] [-b | --buildId ] [-p | --params ] [-ll | --loglevel ]') - .option('-k, --keystorepass ', 'Signing key password') - .option('-b, --buildId ', 'Specifies the build number for signing (typically incremented from previous signing).') - .option('-p, --params ', 'Specifies additional parameters to pass to downstream tools.') - .option('-ll, --loglevel ', 'set the logging level (error, warn, verbose)'); + cleanScript.stdout.on("data", pkgrUtils.handleProcessOutput); + cleanScript.stderr.on("data", pkgrUtils.handleProcessOutput); -command - .command('release') - .usage('[] [-k | --keystorepass] [-b | --buildId ] [-p | --params ] [-ll | --loglevel ]') - .description(' Build in release mode. This will sign the resulting bar.') - .option('-k, --keystorepass ', 'Signing key password') - .option('-b, --buildId ', 'Specifies the build number for signing (typically incremented from previous signing).') - .option('-p, --params ', 'Specifies additional parameters to pass to downstream tools.') - .option('-ll, --loglevel ', 'set the logging level (error, warn, verbose)') - .action(doReleaseBuild); + cleanScript.on("exit", function (code) { + baton.pass(); + }); +} command - .command('debug') - .usage('[] [-p | --params ] [-ll | --loglevel ]') - .description(' Build in debug mode.') - .option('-p, --params ', 'Specifies additional parameters to pass to downstream tools.') - .option('-ll, --loglevel ', 'set the logging level (error, warn, verbose)') - .action(doDebugBuild); + .usage('[--debug] [--release] [-k | --keystorepass] [-b | --buildId ] [-p | --params ] [-ll | --loglevel ]') + .option('--debug', 'build in debug mode.') + .option('--release', 'build in release mode. This will sign the resulting bar.') + .option('-k, --keystorepass ', 'signing key password') + .option('-b, --buildId ', 'specifies the build number for signing (typically incremented from previous signing).') + .option('-p, --params ', 'specifies additional parameters to pass to downstream tools.') + .option('-ll, --loglevel ', 'set the logging level (error, warn, verbose)'); try { command.parse(process.argv); - //if we get here and haven't built yet then no mode was provided [debug, release], default to debug mode - if (!built) { - doDebugBuild(); + if (command.debug && command.release) { + throw "Invalid build command: cannot specify both debug and release parameters." } + + // Implicitly call clean first + jWorkflow.order(clean) + .andThen(postClean) + .start(); } catch (e) { console.log(e); - process.exit(); + process.exit(2); } http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/1e2f28cb/blackberry10/bin/templates/project/cordova/lib/debugtoken-helper.js ---------------------------------------------------------------------- diff --git a/blackberry10/bin/templates/project/cordova/lib/debugtoken-helper.js b/blackberry10/bin/templates/project/cordova/lib/debugtoken-helper.js index 791973c..f1a4220 100755 --- a/blackberry10/bin/templates/project/cordova/lib/debugtoken-helper.js +++ b/blackberry10/bin/templates/project/cordova/lib/debugtoken-helper.js @@ -28,6 +28,44 @@ var childProcess = require("child_process"), deployCallback, self = {}; +function isDebugTokenValid(pin, data) { + var manifests, + i, + l, + expiry = null, + pin, + devices = [], + line, + now = new Date(); + + if (!data) { + return false; + } + + manifests = data.toString().replace(/[\r]/g, '').split('\n'); + + for (i=0, l=manifests.length; i= 0) { + // Parse the expiry date + line = manifests[i].substring("Debug-Token-Expiry-Date: ".length); + expiry = new Date(line.substring(0, line.indexOf("T")) + " " + line.substring(line.indexOf("T") + 1, line.length -1) + " UTC"); + } else if (manifests[i].indexOf("Debug-Token-Device-Id: ") >= 0) { + line = manifests[i].substring("Debug-Token-Device-Id: ".length); + devices = line.split(","); + } + } + + if (expiry && expiry > now) { + for (i=0, l=devices.length; i [-t | --type ] [-p ] [--pin ]\n"); + console.log("No target exists, to add that target please run target add [-t | --type ] [-p ] [--pin ]"); return false; } if (!properties.targets[target]) { - console.log("The target \""+target+"\" does not exist, to add that target please run target add "+target+" [-t | --type ] [-p ] [--pin ]\n"); + console.log("The target \""+target+"\" does not exist, to add that target please run target add "+target+" [-t | --type ] [-p ] [--pin ]"); return false; } if (properties.targets[target].ip) { ip = properties.targets[target].ip; } else { - console.log("IP is not defined in target \""+target+"\"\n"); + console.log("IP is not defined in target \""+target+"\""); return false; } if (properties.targets[target].password) { password = properties.targets[target].password; } return true; - -} - -function deployAll(keys) { - target = keys[0]; - - if (target) { - if (checkTarget()) { - var options = generateOptions(); - if (program.uninstall) { - uninstall( - function() { - keys.shift(); - deployAll(keys); - }); - } else { - execNativeDeploy(options, - function() { - deployAll(keys); - }); - } - } - } } -function uninstall(callback) { +function uninstall() { var script = "/bin/blackberry-deploy", nativeDeploy; @@ -158,12 +142,10 @@ function uninstall(callback) { var options = generateOptions(true); execNativeDeploy(options, function(){ - options = generateOptions(false); - execNativeDeploy(options, callback); + deploy(); }); } else { - options = generateOptions(false); - execNativeDeploy(options, callback); + deploy(); } }); }); @@ -171,34 +153,138 @@ function uninstall(callback) { } } -function exec(callback) { - program - .usage('command [] [--no-launch] [--no-uninstall]') - .option('--no-uninstall', 'does not uninstall app from device') - .option('--no-launch', 'do not launch the app on device') +function deploy() { + options = generateOptions(false); + execNativeDeploy(options, function (code) { + if (code) { + process.exit(2); + } else { + process.exit(0); + } + }); +} - program - .command('all') - .usage('all [--no-launch] [--no-uninstall]') - .description(' Deploy the app on all targets') - .option('--no-uninstall', 'does not uninstall app from device') - .option('--no-launch', 'do not launch the app on device') - - program.parse(process.argv); - target = program.args[0] ? program.args[0] : properties.defaultTarget +function checkDebugtoken(previous, baton) { + baton.take(); - if (target === "all") { - deployAll(Object.keys(properties.targets)); - } else { - if (checkTarget()) { - if (program.uninstall) { - uninstall(callback); + // if target has no pin, skip the debug token feature + if (properties.targets[target].pin) { + debugTokenHelper.checkDebugToken(properties.targets[target].pin, function (valid) { + // If the debug token is not valid, we need create new debug token + if (valid) { + // No need to create the debug token + logger.info(localize.translate("PROGRESS_DEBUG_TOKEN_IS_VALID")); + needDeployDebugToken = true; } else { - options = generateOptions(false); - execNativeDeploy(options, callback) + needCreateDebugToken = true; + } + baton.pass(); + }); + } else { + baton.pass(); + } +} + +function createDebugToken(previous, baton) { + var keystorepass = program["keystorepass"] ? program["keystorepass"] : properties.keystorepass; + + baton.take(); + + if (needCreateDebugToken) { + debugTokenHelper.createToken(properties, "all", keystorepass, function (code) { + if (code === 0) { + // Deploy the debug token if created + needDeployDebugToken = true; } + + baton.pass(); + }); + } else { + baton.pass(); + } +} + +function deployDebugToken(previous, baton) { + baton.take(); + + // If in debug build and debug token was created, deploy the debug token and wait until the deployment is finished + if (needDeployDebugToken) { + debugTokenHelper.deployToken(properties, target, function () { + baton.pass(); + }); + } else { + baton.pass(); + } +} + +function handleBuildOutput(data) { + var msg = data.toString().replace(/[\n\r]/g, ''); + console.log(msg); +} + +function build(previous, baton) { + var nativeDeploy; + + baton.take(); + + nativeDeploy = childProcess.exec("./build", { + "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(); + }); +} + +function postBuild() { + if (program.uninstall) { + uninstall(); + } else { + deploy(); + } +} + +function exec() { + program + .usage('[--target=] [-k | --keystorepass] [--no-launch] [--no-uninstall] [--no-build]') + .option('-k, --keystorepass ', 'the password of signing key; needed for creating debug token') + .option('--target', 'specifies the target to run the application') + .option('--no-uninstall', 'does not uninstall application from device') + .option('--no-launch', 'do not launch the application on device') + .option('--no-build', 'deploy the pre-built bar file and skip building'); + + commandStr = typeof process.argv[2] === "string" ? process.argv[2] : undefined; + if (commandStr && commandStr.indexOf("--target=") === 0) { + // Convert "--target=" into "--target id" + process.argv[2] = "--target"; + process.argv.splice(3, 0, commandStr.substring("--target=".length)); + } + + program.parse(process.argv); + target = program.args[0] ? program.args[0] : properties.defaultTarget; + + if (checkTarget()) { + if (program.build) { + jWorkflow.order(checkDebugtoken) + .andThen(createDebugToken) + .andThen(deployDebugToken) + .andThen(build) + .andThen(postBuild) + .start(); + } else { + postBuild(); } } } -exec(null); \ No newline at end of file +exec(); http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/1e2f28cb/blackberry10/bin/templates/project/project.json ---------------------------------------------------------------------- diff --git a/blackberry10/bin/templates/project/project.json b/blackberry10/bin/templates/project/project.json index 97bbb24..97390ae 100644 --- a/blackberry10/bin/templates/project/project.json +++ b/blackberry10/bin/templates/project/project.json @@ -1,6 +1,5 @@ { "barName": "cordova-BB10-app", - "keystorepass": "password", "defaultTarget": "", "targets": {} } http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/1e2f28cb/blackberry10/bin/templates/project/www/config.xml ---------------------------------------------------------------------- diff --git a/blackberry10/bin/templates/project/www/config.xml b/blackberry10/bin/templates/project/www/config.xml index 3edc941..a645139 100644 --- a/blackberry10/bin/templates/project/www/config.xml +++ b/blackberry10/bin/templates/project/www/config.xml @@ -24,7 +24,7 @@ + version="1.0.0.1" id="default.app.id"> Webworks Application