From 4f58015a4b1b36ebe3980350b09e94e0fa4d4d68 Mon Sep 17 00:00:00 2001 From: Jakob Fahrner Date: Fri, 11 Oct 2019 11:57:27 +0200 Subject: [PATCH] JENKINS-308 add property to set emulator start verbose --- README.md | 4 ++-- android-emulators-gradle/build.gradle | 2 +- .../gradle/androidemulators/EmulatorStarter.groovy | 3 ++- .../androidemulators/EmulatorsPluginTasks.groovy | 14 ++++++++------ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 1b90837..879e3da 100644 --- a/README.md +++ b/README.md @@ -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. | diff --git a/android-emulators-gradle/build.gradle b/android-emulators-gradle/build.gradle index fa1d17a..fe54f05 100644 --- a/android-emulators-gradle/build.gradle +++ b/android-emulators-gradle/build.gradle @@ -29,7 +29,7 @@ dependencies { } group 'org.catrobat.gradle.androidemulators' -version '1.6.1' +version '1.6.2' task sourcesJar(type: Jar) { classifier = 'sources' diff --git a/android-emulators-gradle/src/main/groovy/org/catrobat/gradle/androidemulators/EmulatorStarter.groovy b/android-emulators-gradle/src/main/groovy/org/catrobat/gradle/androidemulators/EmulatorStarter.groovy index aa0a16c..6509009 100644 --- a/android-emulators-gradle/src/main/groovy/org/catrobat/gradle/androidemulators/EmulatorStarter.groovy +++ b/android-emulators-gradle/src/main/groovy/org/catrobat/gradle/androidemulators/EmulatorStarter.groovy @@ -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]) @@ -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() diff --git a/android-emulators-gradle/src/main/groovy/org/catrobat/gradle/androidemulators/EmulatorsPluginTasks.groovy b/android-emulators-gradle/src/main/groovy/org/catrobat/gradle/androidemulators/EmulatorsPluginTasks.groovy index 92756c9..9ffb2d8 100644 --- a/android-emulators-gradle/src/main/groovy/org/catrobat/gradle/androidemulators/EmulatorsPluginTasks.groovy +++ b/android-emulators-gradle/src/main/groovy/org/catrobat/gradle/androidemulators/EmulatorsPluginTasks.groovy @@ -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 { @@ -168,7 +169,7 @@ class EmulatorsPluginTasks { private Map 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() @@ -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() { @@ -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 }