Skip to content

Commit

Permalink
Merge pull request #10 from jampo/JENKINS-308
Browse files Browse the repository at this point in the history
JENKINS-308 add property to set emulator start verbose
  • Loading branch information
jampo authored Oct 11, 2019
2 parents c9c4d6a + 4f58015 commit 6483cf5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ This plugin allows to manage Android emulators via gradle:
### Gradle Commands
| Command | Description |
| --- | --- |
| `./gradlew startEmulator [-Pemulator=EMULATOR_NAME] [-PlogcatFile=LOGCAT_NAME] [-Pci]` | Creates the emulator if necessary, then starts it, and disables animations globally. If you configured multiple emulators you need to select which via `-Pemulator`. The logcat file is automatically stored as logcat.txt. An emulator window will be shown by default, unless this runs on Jenkins or `-Pci` is used. |
| `./gradlew startEmulatorWithAnimations [-Pemulator=EMULATOR_NAME] [-PlogcatFile=LOGCAT_NAME] [-Pci]` | Like `startEmulator` but enables global animations. |
| `./gradlew startEmulator [-Pemulator=EMULATOR_NAME] [-PlogcatFile=LOGCAT_NAME] [-Pverbose=boolean] [-Pci]` | Creates the emulator if necessary, then starts it, and disables animations globally. If you configured multiple emulators you need to select which via `-Pemulator`. The logcat file is automatically stored as logcat.txt. An emulator window will be shown by default, unless this runs on Jenkins or `-Pci` is used. |
| `./gradlew startEmulatorWithAnimations [-Pemulator=EMULATOR_NAME] [-PlogcatFile=LOGCAT_NAME] [-Pverbose=boolean] [-Pci]` | Like `startEmulator` but enables global animations. |
| `./gradlew stopEmulator` | Stops the first emulator it finds. Running multiple emulators at the same time is not supported. |
| `./gradlew adbDisableAnimationsGlobally` | Turns-off animations of the first running emulator it finds. |
| `./gradlew adbResetAnimationsGlobally` | Turns-on animations of the first running emulator it finds. |
Expand Down
2 changes: 1 addition & 1 deletion android-emulators-gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies {
}

group 'org.catrobat.gradle.androidemulators'
version '1.6.1'
version '1.6.2'

task sourcesJar(type: Jar) {
classifier = 'sources'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class EmulatorStarter {
* Starts the emulator asynchronously without checking for success.
* @return EmulatorStarter process
*/
Process start(String avdName, File sdkDirectory, Map environment, boolean showWindow, File logcat) {
Process start(String avdName, File sdkDirectory, Map environment, boolean showWindow, File logcat, boolean verbose) {
def emulator = new CommandBuilder(Utils.joinPaths(sdkDirectory, 'emulator', 'emulator'), '.exe')

emulator.addArguments(['-avd', avdName])
Expand All @@ -51,6 +51,7 @@ class EmulatorStarter {
emulator.addOptionalArguments(!showWindow, ['-no-window'])
emulator.addOptionalArguments(!keepUserData, ['-wipe-data'])
emulator.addOptionalArguments(logcat, ['-logcat-output', logcat.absolutePath])
emulator.addOptionalArguments(verbose, ['-verbose'])
emulator.addArguments(additionalParameters)

emulator.environment(environment).verbose().executeAsynchronously()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class EmulatorsPluginTasks {
private void registerStartEmulatorTask(String name, boolean withAnimations) {
registerTask(name, {
description = 'Starts the android emulator. Use -Pemulator or EMULATOR_OVERRIDE to specify the emulator to use, ' +
'and use -PlogcatFile to override the default logcat file logcat.txt.' +
(withAnimations ? ' Global animations are enabled automatically.' : ' Global animations are disabled automatically.')
'and use -PlogcatFile to override the default logcat file logcat.txt. ' +
'For verbose mode use -Pverbose=true.' +
(withAnimations ? ' Global animations are enabled automatically.' : ' Global animations are disabled automatically.')
group = 'android'

doLast {
Expand Down Expand Up @@ -168,7 +169,7 @@ class EmulatorsPluginTasks {
private Map<String, String> determineEnvironment() {
def env = new HashMap(System.getenv())

def fallbackEnv = {k, v ->
def fallbackEnv = { k, v ->
if (!env.containsKey(k)) {
println("ENV: Setting unspecified $k to [$v]")
env[k.toString()] = v.toString()
Expand All @@ -190,7 +191,7 @@ class EmulatorsPluginTasks {

@TypeChecked(TypeCheckingMode.SKIP)
private String propertyValue(String name, String defaultValue = null) {
project.properties.get(name, defaultValue)
project.properties.getOrDefault(name, defaultValue)
}

private boolean showWindow() {
Expand All @@ -217,11 +218,12 @@ class EmulatorsPluginTasks {

def emulatorStarter = lookupEmulator(emulatorName).emulatorParameters
def logcat = new File(propertyValue('logcatFile', 'logcat.txt'))
proc = emulatorStarter.start(emulatorName, sdkDirectory(), determineEnvironment(), showWindow(), logcat)
def verbose = (boolean) project.properties.getOrDefault('verbose', false)
proc = emulatorStarter.start(emulatorName, sdkDirectory(), determineEnvironment(), showWindow(), logcat, verbose)

try {
device = androidDevice(adb().waitForSerial())
} catch(NoDeviceException e) {
} catch (NoDeviceException e) {
proc.waitForOrKill(1)
throw e
}
Expand Down

0 comments on commit 6483cf5

Please sign in to comment.