-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Choose Target and use it for logging & uninstall #5
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
var shelljs = require('shelljs'); | ||
var path = require('path'); | ||
var fs = require("fs"); | ||
var logger = require('./utils').logger; | ||
var util = require('./utils').utilities; | ||
|
||
function ParamedicAppUninstall(appPath, platform) { | ||
this.appPath = appPath; | ||
this.platform = platform; | ||
} | ||
|
||
ParamedicAppUninstall.prototype.uninstallApp = function(targetObj, app) { | ||
if(!targetObj || !targetObj.target) | ||
return; | ||
|
||
switch(this.platform) { | ||
case util.ANDROID: | ||
this.uninstallAppAndroid(targetObj, app); | ||
break; | ||
case util.IOS: | ||
this.uninstallAppIOS(targetObj, app); | ||
break; | ||
case util.WINDOWS: | ||
this.uninstallAppWindows(targetObj, app); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
ParamedicAppUninstall.prototype.uninstallAppAndroid = function(targetObj, app) { | ||
var uninstallCommand = "adb -s " + targetObj.target + " uninstall " + app; | ||
this.executeUninstallCommand(uninstallCommand); | ||
} | ||
|
||
ParamedicAppUninstall.prototype.uninstallAppWindows = function(targetObj, app) { | ||
var platformPath = path.join(this.appPath, "platforms", "windows"); | ||
var packageJSPath = path.join(platformPath, "cordova", "lib", "package.js"); | ||
var programFilesPath = process.env["ProgramFiles(x86)"] || process.env["ProgramFiles"]; | ||
var appDeployPath = path.join(programFilesPath, "Microsoft SDKs", | ||
"Windows Phone", "v8.1", "Tools", "AppDeploy", "AppDeployCmd.exe"); | ||
appDeployPath = '"' + appDeployPath + '"'; | ||
|
||
if (fs.existsSync(packageJSPath)) { | ||
var packageJS = require(packageJSPath); | ||
var appId = packageJS.getAppId(platformPath); | ||
var uninstallCommand = appDeployPath + " /uninstall " + appId + " /targetdevice:" + targetObj.target; | ||
this.executeUninstallCommand(uninstallCommand); | ||
} | ||
return; | ||
} | ||
|
||
ParamedicAppUninstall.prototype.uninstallAppIOS = function(targetObj, app) { | ||
var uninstallCommand = "xcrun simctl uninstall " + targetObj.simId + " uninstall " + app; | ||
this.executeUninstallCommand(uninstallCommand); | ||
} | ||
|
||
ParamedicAppUninstall.prototype.executeUninstallCommand = function(uninstallCommand) { | ||
logger.info("cordova-paramedic: Running command: " + uninstallCommand); | ||
var uninstallResult = shelljs.exec(uninstallCommand, {silent: false, async: false}); | ||
if (uninstallResult.code > 0) { | ||
logger.error("Failed to uninstall the app" ); | ||
logger.error("Error code: " + uninstallResult.code); | ||
} | ||
return; | ||
} | ||
|
||
module.exports = ParamedicAppUninstall; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
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(emulatorId){ | ||
var obj = {}; | ||
obj.target = emulatorId; | ||
return obj; | ||
}); | ||
} | ||
|
||
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 { | ||
logger.error("cordova-paramedic: Could not start an android emulator"); | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: should we log an error if we run out of tries? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} | ||
}); | ||
}; | ||
|
||
// Check if the emulator has already been started | ||
return emulator.list_started() | ||
.then(function(started) { | ||
if (started && started.length > 0) { | ||
return started[0]; | ||
} else { | ||
return tryStart(ANDROID_RETRY_TIMES); | ||
} | ||
}); | ||
} | ||
|
||
ParamedicTargetChooser.prototype.chooseTargetForWindows = function(emulator) { | ||
logger.info("cordova-paramedic: Choosing Target for Windows"); | ||
var windowsCommand = "cordova run --list --emulator"; | ||
|
||
logger.info("cordova-paramedic: Running command: " + windowsCommand); | ||
var devicesResult = shelljs.exec(windowsCommand, {silent: true, async: false}); | ||
if (devicesResult.code > 0) { | ||
logger.error("Failed to get the list of devices for windows"); | ||
return Q({target: undefined}); | ||
} | ||
|
||
var lines = devicesResult.output.split(/\n/); | ||
if(lines.length <= 1) { | ||
logger.error("No devices/emulators available for windows"); | ||
return Q({target: undefined}); | ||
} | ||
|
||
return Q({target: lines[1].split('. ')[0].trim()}); | ||
} | ||
|
||
ParamedicTargetChooser.prototype.chooseTargetForIOS = function(emulator) { | ||
logger.info("cordova-paramedic: Choosing Target for iOS"); | ||
var simulatorModelId = util.getSimulatorModelId(); | ||
var split = simulatorModelId.split(", "); | ||
var device = split[0].trim(); | ||
|
||
var simId = util.getSimulatorId(simulatorModelId); | ||
return Q({target: device, simId: simId}); | ||
} | ||
|
||
module.exports = ParamedicTargetChooser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be great to also log the stderr in this case to see the cause of the failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed the silent to false. This will give the result either way