Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Commit

Permalink
Added options to redirect output of emulator and to keep that output …
Browse files Browse the repository at this point in the history
…on exit. (#32)
  • Loading branch information
yunikkk authored Oct 4, 2017
1 parent 7920e36 commit f74c96f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
22 changes: 20 additions & 2 deletions swarmer/src/main/kotlin/com/gojuno/swarmer/Args.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.gojuno.swarmer
import com.beust.jcommander.JCommander
import com.beust.jcommander.Parameter
import com.beust.jcommander.Parameters
import java.util.*
import java.util.Collections.emptyList

// No way to share array both for runtime and annotation without reflection.
private const val PARAMETER_EMULATOR_NAME = "--emulator-name"
Expand Down Expand Up @@ -89,13 +91,29 @@ sealed class Commands {
)
var redirectLogcatTo: String? = null,

@Parameter(
names = arrayOf("--redirect-output-to"),
required = false,
description = "Path either relative or absolute to the directory that will be used to redirect emulator command output. No redirection will happen if parameter is not presented.",
order = 8
)
var redirectOutputTo: String? = null,

@Parameter(
names = arrayOf("--verbose-emulator"),
required = false,
description = "Print verbose emulator initialization messages.",
order = 8
order = 9
)
var verbose: Boolean = false,

@Parameter(
names = arrayOf("--keep-output-on-exit"),
required = false,
description = "Keep output of emulator command on exit. False by default.",
order = 10
)
var verbose: Boolean = false
var keepOutputOnExit: Boolean = false

) : Commands()

Expand Down
6 changes: 4 additions & 2 deletions swarmer/src/main/kotlin/com/gojuno/swarmer/Emulators.kt
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,10 @@ private fun waitForEmulatorToFinishBoot(targetEmulator: Emulator): Observable<Em

private fun Long.nanosAsSeconds(): Float = NANOSECONDS.toMillis(this) / 1000f

private fun outputFileForEmulator(args: Commands.Start) = File("${args.emulatorName}.output")
.apply { deleteOnExit() }
private fun outputFileForEmulator(args: Commands.Start) =
File(args.redirectOutputTo ?: "", "${args.emulatorName}.output").apply {
if (!args.keepOutputOnExit) deleteOnExit()
}

private fun connectedEmulators(): Single<Set<AdbDevice>> =
connectedAdbDevices().take(1).toSingle().map { it.filter { it.isEmulator }.toSet() }
5 changes: 3 additions & 2 deletions swarmer/src/test/kotlin/com/gojuno/swarmer/ArgsSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ArgsSpec : Spek({
"--emulator-start-options", "-prop option=value",
"--emulator-start-timeout-seconds", "180",
"--redirect-logcat-to", "logcat.txt",
"--verbose-emulator"
"--verbose-emulator", "--keep-output-on-exit"
)

on("parse args with only required fields") {
Expand Down Expand Up @@ -52,7 +52,8 @@ class ArgsSpec : Spek({
emulatorStartOptions = listOf("-prop option=value"),
emulatorStartTimeoutSeconds = 180L,
redirectLogcatTo = "logcat.txt",
verbose = true
verbose = true,
keepOutputOnExit = true
)))
}
}
Expand Down
10 changes: 7 additions & 3 deletions swarmer/src/test/kotlin/com/gojuno/swarmer/EmulatorsSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ class EmulatorsSpec : Spek({
pathToConfigIni = "config.ini",
emulatorStartOptions = listOf("--no-window"),
emulatorStartTimeoutSeconds = 45L,
verbose = true
redirectOutputTo = "output-dir",
verbose = true,
keepOutputOnExit = true
),
Commands.Start(
emulatorName = "emulator_2",
Expand All @@ -72,6 +74,7 @@ class EmulatorsSpec : Spek({
pathToConfigIni = "config2.ini",
emulatorStartOptions = listOf("--no-window"),
emulatorStartTimeoutSeconds = 45L,
redirectOutputTo = "output-dir",
verbose = true
),
Commands.Start(
Expand All @@ -81,7 +84,8 @@ class EmulatorsSpec : Spek({
pathToConfigIni = "config3.ini",
emulatorStartOptions = listOf("--no-window --some option"),
emulatorStartTimeoutSeconds = 60L,
verbose = false
verbose = false,
keepOutputOnExit = true
)
)

Expand Down Expand Up @@ -174,7 +178,7 @@ class EmulatorsSpec : Spek({
"/bin/sh", "-c",
"${emulator()} ${if (command.verbose) "-verbose" else ""} -avd ${command.emulatorName} -ports ${EMULATOR_PORTS.first},${EMULATOR_PORTS.second} ${command.emulatorStartOptions.joinToString(" ")} &"
),
File("${command.emulatorName}.output")
File(command.redirectOutputTo ?: "", "${command.emulatorName}.output")
)
}
}
Expand Down

0 comments on commit f74c96f

Please sign in to comment.