You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bh...@apache.org on 2013/10/02 15:33:47 UTC

[1/2] webworks commit: [CB-2988] Added the install-device script

Updated Branches:
  refs/heads/master 0924d911a -> 6f63be2cc


[CB-2988] Added the install-device script

Reviewed by Jeffrey Heifetz <jh...@blackberry.com>
Tested by Tracy Li <tl...@blackberry.com>


Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/a009d879
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/a009d879
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/a009d879

Branch: refs/heads/master
Commit: a009d879d0d2c92d46bb065d6a101bbfd74f942a
Parents: 0924d91
Author: DanielAudino <da...@blackberry.com>
Authored: Mon Sep 9 13:11:43 2013 -0400
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Wed Oct 2 09:36:42 2013 -0400

----------------------------------------------------------------------
 .../bin/templates/project/cordova/build         |  18 ++
 .../bin/templates/project/cordova/clean         |  18 ++
 .../templates/project/cordova/install-device    |  23 ++
 .../project/cordova/install-device.bat          |  21 ++
 .../project/cordova/lib/install-device          |  85 ++++--
 .../project/cordova/lib/install-device.bat      |  21 --
 .../bin/templates/project/cordova/lib/run       | 283 +----------------
 .../templates/project/cordova/lib/run-utils.js  | 303 +++++++++++++++++++
 blackberry10/bin/templates/project/cordova/run  |  18 ++
 .../bin/templates/project/cordova/version       |  18 ++
 10 files changed, 493 insertions(+), 315 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/a009d879/blackberry10/bin/templates/project/cordova/build
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/build b/blackberry10/bin/templates/project/cordova/build
index 80769f7..4e47b92 100755
--- a/blackberry10/bin/templates/project/cordova/build
+++ b/blackberry10/bin/templates/project/cordova/build
@@ -1,4 +1,22 @@
 #!/bin/sh
+<<COMMENT
+    Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+COMMENT
 CORDOVA_DIR=$(dirname "$0")
 source "$CORDOVA_DIR/init"
 

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/a009d879/blackberry10/bin/templates/project/cordova/clean
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/clean b/blackberry10/bin/templates/project/cordova/clean
index d1fa322..41b33bd 100755
--- a/blackberry10/bin/templates/project/cordova/clean
+++ b/blackberry10/bin/templates/project/cordova/clean
@@ -1,4 +1,22 @@
 #!/bin/sh
+<<COMMENT
+    Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+COMMENT
 CORDOVA_DIR=$(dirname "$0")
 source "$CORDOVA_DIR/init"
 

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/a009d879/blackberry10/bin/templates/project/cordova/install-device
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/install-device b/blackberry10/bin/templates/project/cordova/install-device
new file mode 100755
index 0000000..40e43c5
--- /dev/null
+++ b/blackberry10/bin/templates/project/cordova/install-device
@@ -0,0 +1,23 @@
+#!/bin/sh
+<<COMMENT
+    Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+COMMENT
+CORDOVA_DIR=$(dirname "$0")
+source "$CORDOVA_DIR/init"
+
+"$CORDOVA_NODE/node" "$CORDOVA_DIR/lib/install-device" "$@"

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/a009d879/blackberry10/bin/templates/project/cordova/install-device.bat
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/install-device.bat b/blackberry10/bin/templates/project/cordova/install-device.bat
new file mode 100755
index 0000000..92e39ec
--- /dev/null
+++ b/blackberry10/bin/templates/project/cordova/install-device.bat
@@ -0,0 +1,21 @@
+@ECHO OFF
+goto comment
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+:comment
+call "%~dps0init"
+"%CORDOVA_NODE%\node.exe" "%~dps0\lib\install-device" %*

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/a009d879/blackberry10/bin/templates/project/cordova/lib/install-device
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/install-device b/blackberry10/bin/templates/project/cordova/lib/install-device
old mode 100755
new mode 100644
index b9f38d3..c63cbee
--- a/blackberry10/bin/templates/project/cordova/lib/install-device
+++ b/blackberry10/bin/templates/project/cordova/lib/install-device
@@ -1,24 +1,65 @@
-#!/usr/bin/env bash
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-#  KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
+#!/usr/bin/env node
 
-set -e
+/*
+ *  Copyright 2012 Research In Motion Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
-echo 'BlackBerry10: Not able to install to connected devices through command-line at this time.'
-exit 1
+var path = require("path"),
+    utils = require("./utils"),
+    options = require('commander'),
+    runUtils = require("./run-utils"),
+    logger = require("./logger"),
+    async = require("async");
+
+options
+    .usage('[--target=id]')
+    .option('--target <id>', 'specifies the target to run the application')
+    .option('--query', 'query on the commandline when a password is needed')
+    .option('--no-uninstall', 'does not uninstall application from device')
+    .on('--help', function() {
+        console.log('  Examples:');
+        console.log('');
+        console.log("  Deploying to a predefined target");
+        console.log('    $ run --target=Z10');
+        console.log('');
+    });
+process.argv.forEach(function (argument, index, args) {
+    if (argument.match(/^--target=/)) {
+        args.splice(index, 1, "--target", argument.substr("--target=".length));
+    }
+});
+
+options.parse(process.argv);
+
+async.waterfall(
+    [
+        runUtils.getValidatedTarget.bind(this, options),
+        runUtils.checkBuild,
+        runUtils.uninstall.bind(this, options),
+        runUtils.deployToTarget.bind(this, options)
+    ],
+    function (err) {
+        if (err) {
+            if (typeof err === "string") {
+                logger.error(err);
+                process.exit(1);
+            } else if (typeof err === "number") {
+                process.exit(err);
+            }
+        } else {
+            process.exit(0);
+        }
+    }
+);

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/a009d879/blackberry10/bin/templates/project/cordova/lib/install-device.bat
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/install-device.bat b/blackberry10/bin/templates/project/cordova/lib/install-device.bat
deleted file mode 100644
index 965417e..0000000
--- a/blackberry10/bin/templates/project/cordova/lib/install-device.bat
+++ /dev/null
@@ -1,21 +0,0 @@
-:: Licensed to the Apache Software Foundation (ASF) under one
-:: or more contributor license agreements.  See the NOTICE file
-:: distributed with this work for additional information
-:: regarding copyright ownership.  The ASF licenses this file
-:: to you under the Apache License, Version 2.0 (the
-:: "License"); you may not use this file except in compliance
-:: with the License.  You may obtain a copy of the License at
-::
-:: http://www.apache.org/licenses/LICENSE-2.0
-::
-:: Unless required by applicable law or agreed to in writing,
-:: software distributed under the License is distributed on an
-:: "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-:: KIND, either express or implied.  See the License for the
-:: specific language governing permissions and limitations
-:: under the License.
-
-@ECHO OFF
-
-ECHO echo 'BlackBerry10: Not able to install to connected devices through command-line at this time.'
-EXIT /B 1

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/a009d879/blackberry10/bin/templates/project/cordova/lib/run
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/run b/blackberry10/bin/templates/project/cordova/lib/run
index e07965c..8d2daca 100755
--- a/blackberry10/bin/templates/project/cordova/lib/run
+++ b/blackberry10/bin/templates/project/cordova/lib/run
@@ -16,289 +16,30 @@
  * limitations under the License.
  */
 
-var childProcess = require("child_process"),
-    fs = require("fs"),
-    path = require("path"),
-    util = require("util"),
-    wrench = require("wrench"),
-    conf = require("./conf"),
+var path = require("path"),
     utils = require("./utils"),
-    targetUtils = require("./target-utils.js"),
-    localize = require("./localize"),
-    pkgrUtils = require("./packager-utils"),
-    debugTokenHelper = require("./debugtoken-helper"),
-    program = require('commander'),
-    xml2js = require('xml2js'),
+    options = require('commander'),
+    runUtils = require("./run-utils"),
     logger = require("./logger"),
-    async = require("async"),
-    properties = utils.getProperties(),
-    workingdir = path.normalize(__dirname + "/..");
-
-function generateOptions(deployTarget, uninstall) {
-    var options = [],
-        barPath = pkgrUtils.escapeStringForShell(
-            path.normalize(__dirname + "/../../build/" +
-                           (deployTarget.type === "device" ? "device" : "simulator") +
-                           "/" + utils.genBarName() + ".bar"));
-
-    options.push("-device");
-    options.push(deployTarget.ip);
-
-    if (deployTarget.password) {
-        options.push("-password");
-        options.push(deployTarget.password);
-    }
-
-    options.push("-package");
-    options.push(barPath);
-
-    if (uninstall) {
-        options.push("-uninstallApp");
-        return options;
-    } else {
-
-        options.push("-installApp");
-
-        if (program.launch) {
-            options.push("-launchApp");
-        }
-
-        return options;
-    }
-}
-
-function execNativeDeploy(options, callback) {
-    var script = path.normalize(path.join(process.env.CORDOVA_BBTOOLS, "blackberry-deploy"));
-
-    utils.exec(script, options, {
-        "cwd": workingdir,
-        "env": process.env
-    }, callback);
-}
-
-function checkDeviceInfo(ip, deviceType, devicePass, done) {
-    var props = utils.getProperties(),
-        targetName;
-
-    targetUtils.getDeviceInfo(ip, devicePass, function (err, device) {
-        if (!err) {
-            targetName = device.name + "-" + device.pin;
-            props.targets[targetName] = {
-                ip: ip,
-                pin: device.pin,
-                type: deviceType
-            };
-            utils.writeToPropertiesFile(props);
-        }
-        done(err, targetName);
-    });
-}
-
-function getTargetName (done) {
-    var ipFinder = program.device ? targetUtils.findConnectedDevice : targetUtils.findConnectedSimulator,
-        targetType = program.device ? "device" : "emulator";
-
-    if (program.target) {
-        done(null, program.target);
-    } else if (program.device || program.emulator) {
-        if (program.device && program.emulator) {
-            localize.translate("WARN_RUN_DEVICE_OVERIDES_EMULATOR");
-        }
-
-        async.series(
-            {
-                ip: function (done) {
-                    ipFinder(function (ip) {
-                        done(ip ? null : "No connected BlackBerry 10 " + targetType + " found", ip);
-                    });
-                },
-                devicePass: function (done) {
-                    if (!program.devicepass && program.devicepass !== "") {
-                        if (program.query) {
-                            utils.prompt({description: "Please enter your " + targetType +  " password: ", hidden: true}, done);
-                        } else {
-                            done("Please provide device password using --devicepass");
-                        }
-                    } else {
-                        done(null, program.devicepass);
-                    }
-                }
-            },
-            function (err, results) {
-                if (err) {
-                    done(err);
-                } else {
-                    program.devicepass = results.devicePass;
-                    checkDeviceInfo(results.ip, targetType, results.devicePass, done);
-                }
-            }
-        );
-    } else {
-        done(null, properties.defaultTarget);
-    }
-}
-
-
-function validateTarget(targetName, allDone) {
-    var deployTarget,
-        err,
-        runTasks = [];
-
-    if (!targetName) {
-        err = "No target exists, to add that target please run target add <name> <ip> [-t | --type <device | simulator>] [-p <password>] [--pin <devicepin>]";
-    } else if (!properties.targets[targetName]) {
-        err = "The target \"" + targetName + "\" does not exist, to add that target please run target add " + targetName + " <ip> [-t | --type <device | simulator>] [-p <password>] [--pin <devicepin>]";
-    } else {
-        deployTarget = utils.clone(properties.targets[targetName]);
-        deployTarget.name = targetName;
-
-        if (!deployTarget.ip) {
-            if (program.query) {
-                runTasks.push(function (done) {
-                    utils.prompt({description: "Please enter the IP address for target " + deployTarget.name + ": "}, function (e, ip) {
-                        deployTarget.ip = ip;
-                        done(e);
-                    });
-                });
-            } else {
-                err = "IP is not defined in target \"" + target + "\"";
-            }
-        }
-
-        if (!deployTarget.password && deployTarget.password !== "") {
-            if (program.devicepass || program.devicepass === "") {
-                deployTarget.password = program.devicepass;
-            } else {
-                if (program.query) {
-                    runTasks.push(function (done) {
-                        utils.prompt({description: "Please enter your " + deployTarget.type +  " password: ", hidden: true}, function (e, devicePass) {
-                            deployTarget.password = devicePass;
-                            done(e);
-                        });
-                    });
-                } else {
-                    err = "Please provide device password using --devicepass or add one to the target " + deployTarget.name + " defined at " + utils.getPropertiesFilePath();
-                }
-            }
-        }
-    }
-
-    async.series(runTasks, function (e) {
-        var finalErr = err || e;
-        if (!finalErr && deployTarget) {
-            logger.info("Target " + deployTarget.name + " selected");
-        }
-        allDone(err || e, deployTarget);
-    });
-}
-
-function uninstall(deployTarget, allDone) {
-    var script = path.join(process.env.CORDOVA_BBTOOLS, "blackberry-deploy"),
-        args = [
-            "-listInstalledApps",
-            "-device",
-            deployTarget.ip
-        ],
-        projectRootDir = path.normalize(path.join(__dirname, "..")),
-        installedAppsOutput,
-        runTasks = [];
-
-    if (program.uninstall) {
-        if (deployTarget.password) {
-            args.push("-password", deployTarget.password);
-        }
-        runTasks = [
-            utils.exec.bind(this, script, args, { "cwd": projectRootDir, _customOptions: {silent: true}}),
-            function listInstalledAppsOutput (stdout, stderr, done) {
-                installedAppsOutput = stdout;
-                fs.readFile(path.join(__dirname + "/../../www/", "config.xml"), done);
-            },
-            function configXMLOutput (result, done) {
-                var parser = new xml2js.Parser();
-                parser.parseString(result, done);
-            },
-            function parsedConfigXMLOutput (result, done) {
-                if (installedAppsOutput.indexOf(result['@'].id) !== -1) {
-                    var options = generateOptions(deployTarget, true);
-                    execNativeDeploy(options, done);
-                } else {
-                    done();
-                }
-            }
-
-        ]
-    }
-
-    async.waterfall(runTasks,
-        function (err, results) {
-            //Absorb error for uninstallation
-            allDone(null, deployTarget);
-        }
-    );
-}
-
-function handleDebugToken(deployTarget, allDone) {
-    program.keystorepass = program.keystorepass || properties.keystorepass;
-
-    // if target has no pin, skip the debug token feature
-    if (deployTarget.pin) {
-        async.waterfall(
-            [
-                debugTokenHelper.checkDebugToken.bind(this, deployTarget.pin),
-                function (done) {
-                    //If no keystorepass is provided debugTokenHelper will throw an error.
-                    if (!program.keystorepass && program.query) {
-                        utils.prompt({description: "Please enter your keystore password: ", hidden: true}, function (err, result) {
-                            program.keystorepass = result;
-                            done(err, result);
-                        });
-                    } else {
-                        done(null, program.keystorepass);
-                    }
-                },
-                debugTokenHelper.createToken.bind(this, properties, "all")
-
-        ],
-        function (err, results) {
-            // If the error is true, then the debug token is valid and creation was skipped.
-            if (err === true) {
-                logger.info(localize.translate("PROGRESS_DEBUG_TOKEN_IS_VALID"));
-                //Clear the error so it is still deployed
-                err = null;
-            }
-
-            if (!err) {
-                debugTokenHelper.deployToken(deployTarget.name, deployTarget.ip, deployTarget.password, function (code) {
-                    allDone(code, deployTarget);
-                });
-            } else {
-                allDone(err);
-            }
-        }
-        );
-    } else {
-        allDone(null, deployTarget);
-    }
-}
+    async = require("async");
 
 function install(deployTarget, done) {
     var buildCmd = utils.isWindows() ? "build" : "./build",
-        buildArgs = program.keystorepass ? ["-k", program.keystorepass] : [],
+        buildArgs = options.keystorepass ? ["-k", options.keystorepass] : [],
         projectRootDir = path.normalize(path.join(__dirname, "..")),
         installTasks = [];
 
-    if (program.build) {
+    if (options.build) {
         installTasks.push(utils.exec.bind(this, buildCmd, buildArgs, {"cwd": projectRootDir}));
     }
 
-    installTasks.push(uninstall.bind(this, deployTarget),
-                      execNativeDeploy.bind(this, generateOptions(deployTarget)));
+    installTasks.push(runUtils.uninstall.bind(this, options, deployTarget),
+                      runUtils.deployToTarget.bind(this, options, deployTarget));
 
     async.series(installTasks, done);
 }
 
-
-program
+options
     .usage('[--device] [--emulator] [--target=<id>]    [--query] [-k | --keystorepass] [-devicepass]    [--no-launch] [--no-uninstall] [--no-build]')
     .option('-k, --keystorepass <password>', 'the password of signing key; needed for creating debug token')
     .option('--device', 'run on connected device')
@@ -325,13 +66,11 @@ process.argv.forEach(function (argument, index, args) {
     }
 });
 
-program.parse(process.argv);
+options.parse(process.argv);
 
 async.waterfall(
     [
-        getTargetName,
-        validateTarget,
-        handleDebugToken,
+        runUtils.getValidatedTarget.bind(this, options),
         install
     ],
     function (err) {

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/a009d879/blackberry10/bin/templates/project/cordova/lib/run-utils.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/run-utils.js b/blackberry10/bin/templates/project/cordova/lib/run-utils.js
new file mode 100644
index 0000000..aff856e
--- /dev/null
+++ b/blackberry10/bin/templates/project/cordova/lib/run-utils.js
@@ -0,0 +1,303 @@
+/*
+ *  Copyright 2012 Research In Motion Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var fs = require("fs"),
+    path = require("path"),
+    utils = require("./utils"),
+    targetUtils = require("./target-utils.js"),
+    localize = require("./localize"),
+    pkgrUtils = require("./packager-utils"),
+    debugTokenHelper = require("./debugtoken-helper"),
+    xml2js = require('xml2js'),
+    logger = require("./logger"),
+    async = require("async"),
+    properties = utils.getProperties(),
+    workingdir = path.normalize(__dirname + "/..");
+
+function getTargetName(options, done) {
+    var ipFinder = options.device ? targetUtils.findConnectedDevice : targetUtils.findConnectedSimulator,
+        targetType = options.device ? "device" : "emulator";
+
+    if (options.target) {
+        done(null, options, options.target);
+    } else if (options.device || options.emulator) {
+        if (options.device && options.emulator) {
+            localize.translate("WARN_RUN_DEVICE_OVERIDES_EMULATOR");
+        }
+
+        async.series(
+        {
+            ip: function (done) {
+                ipFinder(function (ip) {
+                   done(ip ? null : "No connected BlackBerry 10 " + targetType + " found", ip);
+                });
+            },
+            devicePass: function (done) {
+                if (!options.devicepass && options.devicepass !== "") {
+                    if (options.query) {
+                        utils.prompt({description: "Please enter your " + targetType +  " password: ", hidden: true}, done);
+                    } else {
+                        done("Please provide device password using --devicepass");
+                    }
+                } else {
+                    done(null, options.devicepass);
+                }
+            }
+        },
+        function (err, results) {
+            if (err) {
+                done(err);
+            } else {
+                options.devicepass = results.devicePass;
+                checkDeviceInfo(results.ip, targetType, results.devicePass, done);
+            }
+        });
+    } else {
+        done(null, options, properties.defaultTarget);
+    }
+}
+
+function validateTarget(options, targetName, allDone) {
+    var deployTarget,
+        err,
+        runTasks = [];
+
+    if (!targetName) {
+        err = "No target exists, to add that target please run target add <name> <ip> [-t | --type <device | simulator>] [-p <password>] [--pin <devicepin>]";
+    } else if (!properties.targets[targetName]) {
+        err = "The target \"" + targetName + "\" does not exist, to add that target please run target add " + targetName + " <ip> [-t | --type <device | simulator>] [-p <password>] [--pin <devicepin>]";
+    } else {
+        deployTarget = utils.clone(properties.targets[targetName]);
+        deployTarget.name = targetName;
+
+        if (!deployTarget.ip) {
+            if (options.query) {
+                runTasks.push(function (done) {
+                    utils.prompt({description: "Please enter the IP address for target " + deployTarget.name + ": "}, function (e, ip) {
+                        deployTarget.ip = ip;
+                        done(e);
+                    });
+                });
+            } else {
+                err = "IP is not defined in target \"" + target + "\"";
+            }
+        }
+
+        if (!deployTarget.password && deployTarget.password !== "") {
+            if (options.devicepass || options.devicepass === "") {
+                deployTarget.password = options.devicepass;
+            } else {
+                if (options.query) {
+                    runTasks.push(function (done) {
+                        utils.prompt({description: "Please enter your " + deployTarget.type +  " password: ", hidden: true}, function (e, devicePass) {
+                            deployTarget.password = devicePass;
+                            done(e);
+                        });
+                    });
+                } else {
+                    err = "Please provide device password using --devicepass or add one to the target " + deployTarget.name + " defined at " + utils.getPropertiesFilePath();
+                }
+            }
+        }
+    }
+
+    async.series(runTasks, function (e) {
+        var finalErr = err || e;
+        if (!finalErr && deployTarget) {
+            logger.info("Target " + deployTarget.name + " selected");
+        }
+        allDone(err || e, deployTarget);
+    });
+}
+//options are keystorepass, query
+function handleDebugToken(options, deployTarget, allDone) {
+    options.keystorepass = options.keystorepass || properties.keystorepass;
+
+    // if target has no pin, skip the debug token feature
+    if (deployTarget.pin) {
+        async.waterfall(
+            [
+                debugTokenHelper.checkDebugToken.bind(this, deployTarget.pin),
+                function (done) {
+                    //If no keystorepass is provided debugTokenHelper will throw an error.
+                    if (!options.keystorepass && options.query) {
+                        utils.prompt({description: "Please enter your keystore password: ", hidden: true}, function (err, result) {
+                            options.keystorepass = result;
+                            done(err, result);
+                        });
+                    } else {
+                        done(null, options.keystorepass);
+                    }
+                },
+                debugTokenHelper.createToken.bind(this, properties, "all")
+            ],
+                function (err, results) {
+                    // If the error is true, then the debug token is valid and creation was skipped.
+                    if (err === true) {
+                        logger.info(localize.translate("PROGRESS_DEBUG_TOKEN_IS_VALID"));
+                        //Clear the error so it is still deployed
+                        err = null;
+                    }
+
+                    if (!err) {
+                        debugTokenHelper.deployToken(deployTarget.name, deployTarget.ip, deployTarget.password, function (code) {
+                            allDone(code, deployTarget);
+                        });
+                    } else {
+                        allDone(err);
+                    }
+                }
+        );
+    } else {
+        allDone(null, deployTarget);
+    }
+}
+
+function generateDeployOptions(options, deployTarget, uninstall) {
+    var deployOptions = [],
+        barPath = pkgrUtils.escapeStringForShell(
+            path.normalize(__dirname + "/../../build/" +
+                (deployTarget.type === "device" ? "device" : "simulator") +
+                "/" + utils.genBarName() + ".bar"));
+
+    deployOptions.push("-device");
+    deployOptions.push(deployTarget.ip);
+
+    if (deployTarget.password) {
+        deployOptions.push("-password");
+        deployOptions.push(deployTarget.password);
+    }
+
+    deployOptions.push("-package");
+    deployOptions.push(barPath);
+
+    if (uninstall) {
+        deployOptions.push("-uninstallApp");
+        return deployOptions;
+    } else {
+
+        deployOptions.push("-installApp");
+
+        if (options.launch) {
+            deployOptions.push("-launchApp");
+        }
+
+        return deployOptions;
+    }
+}
+
+function execNativeDeploy(options, callback) {
+    var script = path.normalize(path.join(process.env.CORDOVA_BBTOOLS, "blackberry-deploy"));
+
+    utils.exec(script, options, {
+        "cwd": workingdir,
+        "env": process.env
+    }, callback);
+}
+
+_self = {
+    //options looking for are: query, devicepass, password, target, (device || emulator)
+    getValidatedTarget : function (options, callback) {
+        async.waterfall(
+            [
+                getTargetName.bind(this, options),
+                validateTarget,
+            ], callback
+        );
+    },
+    //options looking for are: launch
+    deployToTarget : function (options, deployTarget, callback) {
+        execNativeDeploy(generateDeployOptions(options, deployTarget, false));
+    },
+
+    uninstall : function (options, deployTarget, allDone) {
+        var script = path.join(process.env.CORDOVA_BBTOOLS, "blackberry-deploy"),
+            args = [
+                "-listInstalledApps",
+                "-device",
+                deployTarget.ip
+            ],
+            projectRootDir = path.normalize(path.join(__dirname, "..")),
+            installedAppsOutput,
+            runTasks = [];
+
+        if (options.uninstall) {
+            if (deployTarget.password) {
+                args.push("-password", deployTarget.password);
+            }
+            runTasks = [
+            utils.exec.bind(this, script, args, { "cwd": projectRootDir, _customOptions: {silent: true}}),
+            function listInstalledAppsOutput (stdout, stderr, done) {
+                installedAppsOutput = stdout;
+                fs.readFile(path.join(__dirname + "/../../www/", "config.xml"), done);
+            },
+            function configXMLOutput (result, done) {
+                var parser = new xml2js.Parser();
+                parser.parseString(result, done);
+            },
+            function parsedConfigXMLOutput (result, done) {
+                if (installedAppsOutput.indexOf(result['@'].id) !== -1) {
+                    var options = generateDeployOptions(options, deployTarget, true);
+                    execNativeDeploy(options, done);
+                } else {
+                    done();
+                }
+            }
+
+            ]
+        }
+
+        async.waterfall(runTasks,
+            function (err, results) {
+                //Absorb error for uninstallation
+                allDone(null, deployTarget);
+            }
+            );
+    },
+
+    checkBuild : function (deployTarget, allDone) {
+        barPath = pkgrUtils.escapeStringForShell(
+            path.normalize(__dirname + "/../../build/" +
+                (deployTarget.type === "device" ? "device" : "simulator") +
+                "/" + utils.genBarName() + ".bar"));
+        if (fs.existsSync(barPath)) {
+            allDone(null, deployTarget);
+        } else {
+            allDone(err = "No build file exists, please run: build [--debug] [--release] [-k | --keystorepass] [-b | --buildId <number>] [-p | --params <json>] [-ll | --loglevel <level>] ");
+        }
+
+    },
+
+    checkDeviceInfo : function (ip, deviceType, devicePass, done) {
+        var props = utils.getProperties(),
+        targetName;
+
+        targetUtils.getDeviceInfo(ip, devicePass, function (err, device) {
+            if (!err) {
+                targetName = device.name + "-" + device.pin;
+                props.targets[targetName] = {
+                    ip: ip,
+                    pin: device.pin,
+                    type: deviceType
+                };
+                utils.writeToPropertiesFile(props);
+            }
+            done(err, targetName);
+        });
+    }
+};
+
+module.exports = _self;

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/a009d879/blackberry10/bin/templates/project/cordova/run
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/run b/blackberry10/bin/templates/project/cordova/run
index a95bdde..2f80244 100755
--- a/blackberry10/bin/templates/project/cordova/run
+++ b/blackberry10/bin/templates/project/cordova/run
@@ -1,4 +1,22 @@
 #!/bin/sh
+<<COMMENT
+    Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+COMMENT
 CORDOVA_DIR=$(dirname "$0")
 source "$CORDOVA_DIR/init"
 

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/a009d879/blackberry10/bin/templates/project/cordova/version
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/version b/blackberry10/bin/templates/project/cordova/version
index b5deda2..cc69080 100755
--- a/blackberry10/bin/templates/project/cordova/version
+++ b/blackberry10/bin/templates/project/cordova/version
@@ -1,4 +1,22 @@
 #!/bin/sh
+<<COMMENT
+    Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+COMMENT
 CORDOVA_DIR=$(dirname "$0")
 source "$CORDOVA_DIR/init"
 


[2/2] webworks commit: [CB-2980] Added the install-emulator script

Posted by bh...@apache.org.
[CB-2980] Added the install-emulator script

Reviewed by Jeffrey Heifetz <jh...@blackberry.com>
Tested by Tracy Li <tl...@blackberry.com>


Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/6f63be2c
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/6f63be2c
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/6f63be2c

Branch: refs/heads/master
Commit: 6f63be2cc4cf0f997a4a69ef348e7216d9414d4a
Parents: a009d87
Author: DanielAudino <da...@blackberry.com>
Authored: Fri Sep 13 18:07:43 2013 -0400
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Wed Oct 2 09:37:16 2013 -0400

----------------------------------------------------------------------
 .../templates/project/cordova/install-emulator  | 23 +++++++
 .../project/cordova/install-emulator.bat        | 21 ++++++
 .../project/cordova/lib/install-device          |  4 ++
 .../project/cordova/lib/install-emulator        | 69 ++++++++++++++++++++
 .../templates/project/cordova/lib/localize.js   |  2 +-
 .../templates/project/cordova/lib/run-utils.js  | 48 ++++++++------
 6 files changed, 146 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/6f63be2c/blackberry10/bin/templates/project/cordova/install-emulator
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/install-emulator b/blackberry10/bin/templates/project/cordova/install-emulator
new file mode 100644
index 0000000..b4aeb5c
--- /dev/null
+++ b/blackberry10/bin/templates/project/cordova/install-emulator
@@ -0,0 +1,23 @@
+#!/bin/sh
+<<COMMENT
+    Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+COMMENT
+CORDOVA_DIR=$(dirname "$0")
+source "$CORDOVA_DIR/init"
+
+"$CORDOVA_NODE/node" "$CORDOVA_DIR/lib/install-emulator" "$@"

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/6f63be2c/blackberry10/bin/templates/project/cordova/install-emulator.bat
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/install-emulator.bat b/blackberry10/bin/templates/project/cordova/install-emulator.bat
new file mode 100644
index 0000000..9516315
--- /dev/null
+++ b/blackberry10/bin/templates/project/cordova/install-emulator.bat
@@ -0,0 +1,21 @@
+@ECHO OFF
+goto comment
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+:comment
+call "%~dps0init"
+"%CORDOVA_NODE%\node.exe" "%~dps0\lib\install-emulator" %*

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/6f63be2c/blackberry10/bin/templates/project/cordova/lib/install-device
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/install-device b/blackberry10/bin/templates/project/cordova/lib/install-device
index c63cbee..5809a41 100644
--- a/blackberry10/bin/templates/project/cordova/lib/install-device
+++ b/blackberry10/bin/templates/project/cordova/lib/install-device
@@ -26,8 +26,11 @@ var path = require("path"),
 options
     .usage('[--target=id]')
     .option('--target <id>', 'specifies the target to run the application')
+    .option('-k, --keystorepass <password>', 'the password of signing key; needed for creating debug token')
     .option('--query', 'query on the commandline when a password is needed')
+    .option('--devicepass <password>', 'device password')
     .option('--no-uninstall', 'does not uninstall application from device')
+    .option('--no-launch', 'do not launch the application on device')
     .on('--help', function() {
         console.log('  Examples:');
         console.log('');
@@ -43,6 +46,7 @@ process.argv.forEach(function (argument, index, args) {
 
 options.parse(process.argv);
 
+options.device = true;
 async.waterfall(
     [
         runUtils.getValidatedTarget.bind(this, options),

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/6f63be2c/blackberry10/bin/templates/project/cordova/lib/install-emulator
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/install-emulator b/blackberry10/bin/templates/project/cordova/lib/install-emulator
new file mode 100644
index 0000000..972c475
--- /dev/null
+++ b/blackberry10/bin/templates/project/cordova/lib/install-emulator
@@ -0,0 +1,69 @@
+#!/usr/bin/env node
+
+/*
+ *  Copyright 2012 Research In Motion Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var path = require("path"),
+    utils = require("./utils"),
+    options = require('commander'),
+    runUtils = require("./run-utils"),
+    logger = require("./logger"),
+    async = require("async");
+
+options
+    .usage('[--target=id]')
+    .option('--target <id>', 'specifies the target to run the application')
+    .option('--devicepass <password>', 'device password')
+    .option('--query', 'query on the commandline when a password is needed')
+    .option('-k, --keystorepass <password>', 'the password of signing key; needed for creating debug token')
+    .option('--no-uninstall', 'does not uninstall application from device')
+    .option('--no-launch', 'do not launch the application on device')
+    .on('--help', function() {
+        console.log('  Examples:');
+        console.log('');
+        console.log("  Deploying to a predefined target");
+        console.log('    $ run --target=Z10');
+        console.log('');
+    });
+process.argv.forEach(function (argument, index, args) {
+    if (argument.match(/^--target=/)) {
+        args.splice(index, 1, "--target", argument.substr("--target=".length));
+    }
+});
+
+options.parse(process.argv);
+
+options.emulator = true;
+async.waterfall(
+    [
+        runUtils.getValidatedTarget.bind(this, options),
+        runUtils.checkBuild,
+        runUtils.uninstall.bind(this, options),
+        runUtils.deployToTarget.bind(this, options)
+    ],
+    function (err) {
+        if (err) {
+            if (typeof err === "string") {
+                logger.error(err);
+                process.exit(1);
+            } else if (typeof err === "number") {
+                process.exit(err);
+            }
+        } else {
+            process.exit(0);
+        }
+    }
+);

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/6f63be2c/blackberry10/bin/templates/project/cordova/lib/localize.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/localize.js b/blackberry10/bin/templates/project/cordova/lib/localize.js
index 94d4673..38cf7a9 100755
--- a/blackberry10/bin/templates/project/cordova/lib/localize.js
+++ b/blackberry10/bin/templates/project/cordova/lib/localize.js
@@ -191,7 +191,7 @@ var Localize = require("localize"),
             "en": "No device PIN found, will omit debug token generation"
         },
         "WARN_NO_SIGNING_PASSWORD_PROVIDED": {
-            "en": "No signing password provided, debug token cannot be generated. Please enter a value for 'keystorepass' in %HOME%/.cordova/blackberry10.json or use --keystorepass via command-line directly from the project cordova scripts (WILL NOT WORK FROM CLI)."
+            "en": "No signing password provided, debug token cannot be generated. Please enter a value for 'keystorepass' in %HOME%/.cordova/blackberry10.json or use --keystorepass via command-line directly from the project cordova scripts."
         },
         "PROGRESS_GENERATING_DEBUG_TOKEN": {
             "en": "Generating debug token"

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/6f63be2c/blackberry10/bin/templates/project/cordova/lib/run-utils.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/cordova/lib/run-utils.js b/blackberry10/bin/templates/project/cordova/lib/run-utils.js
index aff856e..18e8c58 100644
--- a/blackberry10/bin/templates/project/cordova/lib/run-utils.js
+++ b/blackberry10/bin/templates/project/cordova/lib/run-utils.js
@@ -27,6 +27,7 @@ var fs = require("fs"),
     properties = utils.getProperties(),
     workingdir = path.normalize(__dirname + "/..");
 
+//Options looking for are: (Device | Emulator, query, devicepass). Calls back with:  (error || options object, target object)
 function getTargetName(options, done) {
     var ipFinder = options.device ? targetUtils.findConnectedDevice : targetUtils.findConnectedSimulator,
         targetType = options.device ? "device" : "emulator";
@@ -48,9 +49,12 @@ function getTargetName(options, done) {
             devicePass: function (done) {
                 if (!options.devicepass && options.devicepass !== "") {
                     if (options.query) {
-                        utils.prompt({description: "Please enter your " + targetType +  " password: ", hidden: true}, done);
-                    } else {
+                        var description = options.device ? "Please enter your " + targetType +  " password: " : "Please enter your " + targetType +  " password (For no password press Enter): ";
+                        utils.prompt({description: description, hidden: true}, done);
+                    } else if (!options.emulator) {
                         done("Please provide device password using --devicepass");
+                    } else {
+                        done("");
                     }
                 } else {
                     done(null, options.devicepass);
@@ -62,7 +66,7 @@ function getTargetName(options, done) {
                 done(err);
             } else {
                 options.devicepass = results.devicePass;
-                checkDeviceInfo(results.ip, targetType, results.devicePass, done);
+                _self.checkDeviceInfo(options, results.ip, targetType, results.devicePass, done);
             }
         });
     } else {
@@ -70,6 +74,7 @@ function getTargetName(options, done) {
     }
 }
 
+//Options looking for are: (query, devicepass). Calls back with:  (error || target object)
 function validateTarget(options, targetName, allDone) {
     var deployTarget,
         err,
@@ -95,19 +100,19 @@ function validateTarget(options, targetName, allDone) {
                 err = "IP is not defined in target \"" + target + "\"";
             }
         }
-
         if (!deployTarget.password && deployTarget.password !== "") {
             if (options.devicepass || options.devicepass === "") {
                 deployTarget.password = options.devicepass;
             } else {
                 if (options.query) {
                     runTasks.push(function (done) {
-                        utils.prompt({description: "Please enter your " + deployTarget.type +  " password: ", hidden: true}, function (e, devicePass) {
+                         var description = options.device ? "Please enter your " + deployTarget.type +  " password: " : "Please enter your " + deployTarget.type +  " password (For no password press Enter): ";
+                        utils.prompt({description: description, hidden: true}, function (e, devicePass) {
                             deployTarget.password = devicePass;
                             done(e);
                         });
                     });
-                } else {
+                } else if (!options.emulator) {
                     err = "Please provide device password using --devicepass or add one to the target " + deployTarget.name + " defined at " + utils.getPropertiesFilePath();
                 }
             }
@@ -119,15 +124,15 @@ function validateTarget(options, targetName, allDone) {
         if (!finalErr && deployTarget) {
             logger.info("Target " + deployTarget.name + " selected");
         }
-        allDone(err || e, deployTarget);
+        allDone(err || e, options, deployTarget);
     });
 }
-//options are keystorepass, query
+//Options looking for are: (keystorepass, query). Calls back with:  (error || target object)
 function handleDebugToken(options, deployTarget, allDone) {
     options.keystorepass = options.keystorepass || properties.keystorepass;
 
     // if target has no pin, skip the debug token feature
-    if (deployTarget.pin) {
+    if (deployTarget.pin && !options.emulator) {
         async.waterfall(
             [
                 debugTokenHelper.checkDebugToken.bind(this, deployTarget.pin),
@@ -199,30 +204,32 @@ function generateDeployOptions(options, deployTarget, uninstall) {
     }
 }
 
-function execNativeDeploy(options, callback) {
+function execNativeDeploy(deployOptions, callback) {
     var script = path.normalize(path.join(process.env.CORDOVA_BBTOOLS, "blackberry-deploy"));
 
-    utils.exec(script, options, {
+    utils.exec(script, deployOptions, {
         "cwd": workingdir,
         "env": process.env
     }, callback);
 }
 
 _self = {
-    //options looking for are: query, devicepass, password, target, (device || emulator)
+    //options looking for are: (query, devicepass, password, target, (device || emulator)) Function returns (error || deployTarget)
     getValidatedTarget : function (options, callback) {
         async.waterfall(
             [
                 getTargetName.bind(this, options),
                 validateTarget,
+                handleDebugToken,
             ], callback
         );
     },
-    //options looking for are: launch
+    //options looking for are: (launch) Function returns (error || null)
     deployToTarget : function (options, deployTarget, callback) {
         execNativeDeploy(generateDeployOptions(options, deployTarget, false));
     },
 
+    //options looking for are: (uninstall) Function returns (error || null)
     uninstall : function (options, deployTarget, allDone) {
         var script = path.join(process.env.CORDOVA_BBTOOLS, "blackberry-deploy"),
             args = [
@@ -250,8 +257,8 @@ _self = {
             },
             function parsedConfigXMLOutput (result, done) {
                 if (installedAppsOutput.indexOf(result['@'].id) !== -1) {
-                    var options = generateDeployOptions(options, deployTarget, true);
-                    execNativeDeploy(options, done);
+                    var deployOptions = generateDeployOptions(options, deployTarget, true);
+                    execNativeDeploy(deployOptions, done);
                 } else {
                     done();
                 }
@@ -268,11 +275,11 @@ _self = {
             );
     },
 
+    //Function returns (error || deployTarget)
     checkBuild : function (deployTarget, allDone) {
-        barPath = pkgrUtils.escapeStringForShell(
-            path.normalize(__dirname + "/../../build/" +
+        barPath = path.normalize(__dirname + "/../../build/" +
                 (deployTarget.type === "device" ? "device" : "simulator") +
-                "/" + utils.genBarName() + ".bar"));
+                "/" + utils.genBarName() + ".bar");
         if (fs.existsSync(barPath)) {
             allDone(null, deployTarget);
         } else {
@@ -281,7 +288,8 @@ _self = {
 
     },
 
-    checkDeviceInfo : function (ip, deviceType, devicePass, done) {
+    //No options needed within function Function returns (error || options, targetName)
+    checkDeviceInfo : function (options, ip, deviceType, devicePass, done) {
         var props = utils.getProperties(),
         targetName;
 
@@ -295,7 +303,7 @@ _self = {
                 };
                 utils.writeToPropertiesFile(props);
             }
-            done(err, targetName);
+            done(err, options, targetName);
         });
     }
 };