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 Fri, 06 May 2016 22:47:05 GMT
Github user riknoll commented on a diff in the pull request:

    https://github.com/apache/cordova-paramedic/pull/5#discussion_r62401164
  
    --- 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 --
    
    Why not pass a timeout to `emulator.start`? The emulator startup can hang, which is why
we added the retry logic to medic in the first place.


---
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