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

Add windows compatibility #45

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ext.versions = [
kotlin : '1.2.41',
kotlin : '1.2.61',

rxJava : '1.3.8',
jCommander : '1.71',
commander : '0.1.8',
jCommander : '1.72',
commander : '0.1.10',

junit : '4.12',
junitPlatform: '1.0.1',
Expand Down
4 changes: 2 additions & 2 deletions swarmer/src/main/kotlin/com/gojuno/swarmer/Args.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sealed class Commands {
val ALIASES_START = listOf("start")
val ALIASES_STOP = listOf("stop")

fun fromStringAlias(alias: String): Commands? = when {
fun fromStringAlias(alias: String?): Commands? = when {
ALIASES_HELP.contains(alias) -> Help
ALIASES_STOP.contains(alias) -> Stop()
ALIASES_START.contains(alias) -> Start()
Expand Down Expand Up @@ -148,7 +148,7 @@ sealed class Commands {
) : Commands()
}

fun parseCommand(rawArgs: List<String>) = Commands.fromStringAlias(rawArgs[0])
fun parseCommand(rawArgs: List<String>) = Commands.fromStringAlias(rawArgs.getOrNull(0))

fun parseStartArguments(rawArgs: List<String>): List<Commands.Start> =
rawArgs
Expand Down
31 changes: 24 additions & 7 deletions swarmer/src/main/kotlin/com/gojuno/swarmer/Emulators.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.gojuno.commander.os.Notification
import com.gojuno.commander.os.home
import com.gojuno.commander.os.log
import com.gojuno.commander.os.process
import com.gojuno.commander.os.os
import com.gojuno.commander.os.Os
import rx.Completable
import rx.Observable
import rx.Single
Expand All @@ -18,10 +20,26 @@ import java.util.concurrent.TimeUnit.*
import java.util.concurrent.TimeoutException
import java.util.concurrent.atomic.AtomicLong

val sh: String = "/bin/sh"
val avdManager: String = "$androidHome/tools/bin/avdmanager"
val emulator = "$androidHome/emulator/emulator"
val emulatorCompat = "$androidHome/tools/emulator"
val sh: List<String> = when (os()) {
Os.Linux, Os.Mac -> listOf("/bin/sh", "-c")
Os.Windows -> listOf("cmd", "/C")
}
val runInBackground: String = when (os()) {
Os.Linux, Os.Mac -> "&"
Os.Windows -> ""
}
val avdManager: String = when (os()) {
Os.Linux, Os.Mac -> "$androidHome/tools/bin/avdmanager"
Os.Windows -> "$androidHome/tools/bin/avdmanager.bat"
}
val emulator = when (os()) {
Os.Linux, Os.Mac -> "$androidHome/emulator/emulator"
Os.Windows -> "$androidHome/emulator/emulator.exe"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.exe! RUN DON'T LOOK BACK

}
val emulatorCompat = when (os()) {
Os.Linux, Os.Mac -> "$androidHome/tools/emulator"
Os.Windows -> "$androidHome/tools/emulator.exe"
}

data class Emulator(
val id: String,
Expand Down Expand Up @@ -102,8 +120,7 @@ private fun startEmulator(
.doOnNext { log("Ports for emulator ${args.emulatorName}: ${it.first}, ${it.second}.") }
.flatMap { ports ->
startEmulatorProcess(
// Unix only, PR welcome.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I knew someone will delete this line haha

listOf(sh, "-c", "${emulator(args)} ${if (args.verbose) "-verbose" else ""} -avd ${args.emulatorName} -ports ${ports.first},${ports.second} ${args.emulatorStartOptions.joinToString(" ")} &"),
sh + "${emulator(args)} ${if (args.verbose) "-verbose " else ""}-avd ${args.emulatorName} -ports ${ports.first},${ports.second} ${args.emulatorStartOptions.joinToString(" ")} $runInBackground".trim(),
args
).let { process ->
waitForEmulatorToStart(args, connectedAdbDevices, process, ports)
Expand Down Expand Up @@ -362,4 +379,4 @@ private fun createdEmulators(args: Commands.Start, timeout: Pair<Int, TimeUnit>
.filter { !it.isBlank() }
.map { it.trim() }
.toSet()
}
}
4 changes: 2 additions & 2 deletions swarmer/src/test/kotlin/com/gojuno/swarmer/EmulatorsSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ class EmulatorsSpec : Spek({
START_COMMANDS.forEach { command ->
it("should start emulators") {
verify(startEmulatorsProcess).invoke(
sh +
listOf(
"/bin/sh", "-c",
"${emulator(command)} ${if (command.verbose) "-verbose" else ""} -avd ${command.emulatorName} -ports ${EMULATOR_PORTS.first},${EMULATOR_PORTS.second} ${command.emulatorStartOptions.joinToString(" ")} &"
"${emulator(command)} ${if (command.verbose) "-verbose" else ""} -avd ${command.emulatorName} -ports ${EMULATOR_PORTS.first},${EMULATOR_PORTS.second} ${command.emulatorStartOptions.joinToString(" ")} $runInBackground".trim()
),
command
)
Expand Down