CB-10699: Attempt to uninstall mobilespec on Android emulator before run

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

Branch: refs/heads/master
Commit: cea6c852e39766aa54032e75879b50912f1541ba
Parents: e583d86
Author: riknoll <richard.b.kn...@gmail.com>
Authored: Thu Feb 25 11:18:43 2016 -0800
Committer: riknoll <richard.b.kn...@gmail.com>
Committed: Thu Feb 25 11:23:50 2016 -0800

----------------------------------------------------------------------
 lib/util.js        | 23 ++++++++++++++++++++++-
 medic/medic-log.js | 14 +-------------
 medic/medic-run.js | 20 ++++++++++++++++++++
 3 files changed, 43 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/cea6c852/lib/util.js
----------------------------------------------------------------------
diff --git a/lib/util.js b/lib/util.js
index a636358..06da676 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -24,11 +24,14 @@
 module.exports = (function () {
 
     var os = require("os");
+    var shelljs = require("shelljs");
 
     // constants
     var ESCAPE    = String.fromCharCode(27);
     var RED_COLOR = ESCAPE + "[31m";
     var NO_COLOR  = ESCAPE + "[m";
+    var DEVICE_ROW_PATTERN = /(emulator|device|host)/m;
+    var HEADING_LINE_PATTERN = /List of devices/m;
 
     function medicLog(message) {
         console.log(RED_COLOR + "[MEDIC LOG " + new Date().toUTCString() + "]" 
+ NO_COLOR + " " + message);
@@ -54,6 +57,23 @@ module.exports = (function () {
         return Math.ceil(seconds / 60);
     }
 
+    function countAndroidDevices() {
+        var listCommand = "adb devices";
+
+        medicLog("running:");
+        medicLog("    " + listCommand);
+
+        var numDevices = 0;
+        var result = shelljs.exec(listCommand, {silent: false, async: false});
+        result.output.split('\n').forEach(function (line) {
+            if (!HEADING_LINE_PATTERN.test(line) && 
DEVICE_ROW_PATTERN.test(line)) {
+                numDevices += 1;
+            }
+        });
+
+        return numDevices;
+    }
+
     return {
 
         // constants
@@ -71,6 +91,7 @@ module.exports = (function () {
         isWindows: isWindows,
         medicLog:  medicLog,
         contains:  contains,
-        secToMin:  secToMin
+        secToMin:  secToMin,
+        countAndroidDevices: countAndroidDevices
     };
 }());

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/cea6c852/medic/medic-log.js
----------------------------------------------------------------------
diff --git a/medic/medic-log.js b/medic/medic-log.js
index a25c5b2..660e87c 100644
--- a/medic/medic-log.js
+++ b/medic/medic-log.js
@@ -31,27 +31,15 @@ var path     = require("path");
 var util = require("../lib/util");
 
 // constants
-var DEVICE_ROW_PATTERN = /(emulator|device|host)/m;
-var HEADING_LINE_PATTERN = /List of devices/m;
 var DEFAULT_APP_PATH = "mobilespec";
 
 // helpers
 function logAndroid() {
 
     var logCommand = "adb logcat -d";
-    var listCommand = "adb devices";
-
-    util.medicLog("running:");
-    util.medicLog("    " + listCommand);
 
     // bail out if there is more/less than one device
-    var numDevices = 0;
-    var result = shelljs.exec(listCommand, {silent: false, async: false});
-    result.output.split('\n').forEach(function (line) {
-        if (!HEADING_LINE_PATTERN.test(line) && DEVICE_ROW_PATTERN.test(line)) 
{
-            numDevices += 1;
-        }
-    });
+    var numDevices = util.countAndroidDevices();
     if (numDevices != 1) {
         util.fatal("there must be exactly one emulator/device attached");
     }

http://git-wip-us.apache.org/repos/asf/cordova-medic/blob/cea6c852/medic/medic-run.js
----------------------------------------------------------------------
diff --git a/medic/medic-run.js b/medic/medic-run.js
index 53c89c8..984c102 100644
--- a/medic/medic-run.js
+++ b/medic/medic-run.js
@@ -423,6 +423,26 @@ function main() {
                     util.fatal("Could not start Android emulator");
                 } else {
                     util.medicLog("Android emulator started");
+
+                    // CB-10699: We try to uninstall the app once the emulator
+                    // boots up, because sometimes the adb command that 
"cordova
+                    // run" uses fails to uninstall the app and errors out
+
+                    // There needs to be only one device for uninstall to work
+                    var numDevices = util.countAndroidDevices();
+                    if (numDevices != 1) {
+                        util.medicLog("WARNING: There is more than one 
device/emulator attached, skipping uninstall step");
+                    } else {
+                        var uninstallCommand = "adb uninstall 
org.apache.mobilespec";
+
+                        util.medicLog("Running the following command:");
+                        util.medicLog("    " + uninstallCommand);
+
+                        // This command will fail if the app is not installed,
+                        // so we set it to silent so as to not confuse anyone
+                        var uninstallResult = shelljs.exec(uninstallCommand, 
{silent: true, async: false});
+                    }
+
                     runOnEmulator();
                 }
             } else {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to