cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From riknoll <...@git.apache.org>
Subject [GitHub] cordova-paramedic pull request: Choose Target and use it for loggi...
Date Tue, 10 May 2016 19:10:32 GMT
Github user riknoll commented on a diff in the pull request:

    https://github.com/apache/cordova-paramedic/pull/5#discussion_r62733344
  
    --- Diff: lib/ParamedicTargetChooser.js ---
    @@ -0,0 +1,127 @@
    +var Q       = require('q');
    +var shelljs = require('shelljs');
    +var path    = require("path-extra");
    +var logger  = require('./utils').logger;
    +var util    = require('./utils').utilities;
    +var spawn   = require('child_process').spawn;
    +var ParamedicKill   = require('./ParamedicKill');
    +
    +var ANDROID_RETRY_TIMES = 3;
    +var ANDROID_TIME_OUT    = 300000; //5 Minutes
    +
    +function ParamedicTargetChooser(appPath, platform) {
    +    this.appPath  = appPath;
    +    this.platform = platform;
    +}
    +
    +ParamedicTargetChooser.prototype.chooseTarget = function(emulator) {
    +    var targetObj = "";
    +    switch(this.platform) {
    +        case util.ANDROID:
    +            targetObj = this.chooseTargetForAndroid(emulator);
    +            break;
    +        case util.IOS:
    +            targetObj = this.chooseTargetForIOS(emulator);
    +            break;
    +        case util.WINDOWS:
    +            targetObj = this.chooseTargetForWindows(emulator);
    +            break;
    +        default:
    +            break;
    +    }
    +    return targetObj;
    +}
    +
    +ParamedicTargetChooser.prototype.chooseTargetForAndroid = function(emulator) {
    +    logger.info("cordova-paramedic: Choosing Target for Android");
    +    var self = this;
    +    return this.startAnAndroidEmulator().then(function(){
    +        var obj = {};
    +        obj.target = self.getRunningDeviceForAndroid();
    +        return obj;
    +    });
    +}
    +
    +ParamedicTargetChooser.prototype.getRunningDeviceForAndroid = function() {
    +    var androidCommand = "adb devices -l";
    +    logger.info("cordova-paramedic: Running command: " + androidCommand);
    +
    +    var devicesResult  = shelljs.exec(androidCommand, {silent: true, async: false});
    +    if (devicesResult.code > 0) {
    +        logger.error("Failed to get the list of devices for android" );
    +        logger.error("Error code: " + devicesResult.code);
    +        return undefined;
    +    }
    +
    +    var lines = devicesResult.output.split(/\n/);
    +    if(lines.length <= 1) {
    +        logger.error("No devices/emulators available for android");
    +        return undefined;
    +    }
    +
    +    return lines[1].split(' ')[0].trim();
    +}
    +
    +ParamedicTargetChooser.prototype.startAnAndroidEmulator = function() {
    +    logger.info("cordova-paramedic: Starting an Android emulator");
    +
    +    var emuPath = path.join(this.appPath, "platforms", "android", "cordova", "lib", "emulator");
    +    var emulator = require(emuPath);
    +
    +    var tryStart = function(numberTriesRemaining) {
    +        return emulator.start(null, ANDROID_TIME_OUT)
    +        .then(function(emulatorId) {
    +            if (emulatorId) {
    +                return emulatorId;
    +            } else if (numberTriesRemaining > 0) {
    +                var paramedicKill = new ParamedicKill(util.ANDROID);
    +                paramedicKill.kill();
    +                return tryStart(numberTriesRemaining - 1);
    +            } else {
    +                return null;
    --- End diff --
    
    Nitpick: should we log an error if we run out of tries?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@cordova.apache.org
For additional commands, e-mail: dev-help@cordova.apache.org


Mime
View raw message