Github user sarangan12 commented on a diff in the pull request:

    https://github.com/apache/cordova-paramedic/pull/5#discussion_r62578550
  
    --- Diff: lib/ParamedicTargetChooser.js ---
    @@ -0,0 +1,126 @@
    +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;
    +
    +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)
    --- End diff --
    
    Added 5 mins timeout


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to