From c3a802784988dfc2b1246d34346b834bb6dd4007 Mon Sep 17 00:00:00 2001 From: Leland Takamine Date: Thu, 16 Jan 2025 11:58:47 -0800 Subject: [PATCH] Enable running Maestro on Windows without WSL (#2248) * Fix Windows script error by making classpath shorting using globs * Update dadb * Do not use emojis on Windows * Fix Studio npm builds on Windows * Make OS comparison case-insensitive * Use smiley face instead of check * Use + instead of special char * Remove debug condition --------- Co-authored-by: Dan Caseley --- gradle/libs.versions.toml | 2 +- maestro-cli/build.gradle.kts | 4 +++ .../java/maestro/cli/command/TestCommand.kt | 8 +++-- .../java/maestro/cli/runner/TestRunner.kt | 3 +- .../cli/runner/resultview/AnsiResultView.kt | 34 +++++++++++++------ .../main/java/maestro/cli/util/EnvUtils.kt | 4 +++ maestro-studio/web/build.gradle | 12 +++++-- 7 files changed, 50 insertions(+), 17 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5952122c04..d8ae45667d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -17,7 +17,7 @@ axml = "2.1.2" commons-codec = "1.17.0" commons-lang3 = "3.13.0" # 3.14.0 causes weird crashes during dexing commons-io = "2.16.1" -dadb = "1.2.7" +dadb = "1.2.9" detekt = "1.19.0" googleFindbugs = "3.0.2" googleGson = "2.11.0" diff --git a/maestro-cli/build.gradle.kts b/maestro-cli/build.gradle.kts index a0e27a186a..476892d7a0 100644 --- a/maestro-cli/build.gradle.kts +++ b/maestro-cli/build.gradle.kts @@ -31,6 +31,10 @@ tasks.named("run") { workingDir = rootDir } +tasks.named("startScripts") { + classpath = files("$buildDir/libs/*") +} + dependencies { implementation(project(path = ":maestro-utils")) annotationProcessor(libs.picocli.codegen) diff --git a/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt b/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt index 717732de84..58dfcb23ea 100644 --- a/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt +++ b/maestro-cli/src/main/java/maestro/cli/command/TestCommand.kt @@ -40,6 +40,7 @@ import maestro.cli.runner.TestSuiteInteractor import maestro.cli.runner.resultview.AnsiResultView import maestro.cli.runner.resultview.PlainTextResultView import maestro.cli.session.MaestroSessionManager +import maestro.cli.util.EnvUtils import maestro.cli.util.FileUtils.isWebFlow import maestro.cli.util.PrintUtils import maestro.cli.view.box @@ -353,8 +354,11 @@ class TestCommand : Callable { debugOutputPath: Path, ): Triple { val resultView = - if (DisableAnsiMixin.ansiEnabled) AnsiResultView() - else PlainTextResultView() + if (DisableAnsiMixin.ansiEnabled) { + AnsiResultView(useEmojis = !EnvUtils.isWindows()) + } else { + PlainTextResultView() + } env = env .withInjectedShellEnvVars() diff --git a/maestro-cli/src/main/java/maestro/cli/runner/TestRunner.kt b/maestro-cli/src/main/java/maestro/cli/runner/TestRunner.kt index 4fd0c6aa21..3bfee3e381 100644 --- a/maestro-cli/src/main/java/maestro/cli/runner/TestRunner.kt +++ b/maestro-cli/src/main/java/maestro/cli/runner/TestRunner.kt @@ -14,6 +14,7 @@ import maestro.cli.report.TestDebugReporter import maestro.cli.runner.resultview.AnsiResultView import maestro.cli.runner.resultview.ResultView import maestro.cli.runner.resultview.UiState +import maestro.cli.util.EnvUtils import maestro.cli.util.PrintUtils import maestro.cli.view.ErrorViewUtils import maestro.orchestra.MaestroCommand @@ -94,7 +95,7 @@ object TestRunner { flowFile: File, env: Map, ): Nothing { - val resultView = AnsiResultView("> Press [ENTER] to restart the Flow\n\n") + val resultView = AnsiResultView("> Press [ENTER] to restart the Flow\n\n", useEmojis = !EnvUtils.isWindows()) val fileWatcher = FileWatcher() diff --git a/maestro-cli/src/main/java/maestro/cli/runner/resultview/AnsiResultView.kt b/maestro-cli/src/main/java/maestro/cli/runner/resultview/AnsiResultView.kt index a4adfc1bf0..5c0e3d165f 100644 --- a/maestro-cli/src/main/java/maestro/cli/runner/resultview/AnsiResultView.kt +++ b/maestro-cli/src/main/java/maestro/cli/runner/resultview/AnsiResultView.kt @@ -37,6 +37,7 @@ import org.fusesource.jansi.Ansi class AnsiResultView( private val prompt: String? = null, private val printCommandLogs: Boolean = true, + private val useEmojis: Boolean = true, ) : ResultView { private val startTimestamp = System.currentTimeMillis() @@ -248,18 +249,29 @@ class AnsiResultView( return Frame(System.currentTimeMillis() - startTimestamp, content) } - data class Frame(val timestamp: Long, val content: String) -} - -internal fun status(status: CommandStatus): String { - return when (status) { - CommandStatus.COMPLETED -> "✅ " - CommandStatus.FAILED -> "❌ " - CommandStatus.RUNNING -> "⏳ " - CommandStatus.PENDING -> "\uD83D\uDD32 " // 🔲 - CommandStatus.WARNED -> "⚠️ " - CommandStatus.SKIPPED -> "⚪️ " + private fun status(status: CommandStatus): String { + if (useEmojis) { + return when (status) { + CommandStatus.COMPLETED -> "✅ " + CommandStatus.FAILED -> "❌ " + CommandStatus.RUNNING -> "⏳ " + CommandStatus.PENDING -> "\uD83D\uDD32 " // 🔲 + CommandStatus.WARNED -> "⚠️ " + CommandStatus.SKIPPED -> "⚪️ " + } + } else { + return when (status) { + CommandStatus.COMPLETED -> "+ " + CommandStatus.FAILED -> "X " + CommandStatus.RUNNING -> "> " + CommandStatus.PENDING -> " " + CommandStatus.WARNED -> "! " + CommandStatus.SKIPPED -> "- " + } + } } + + data class Frame(val timestamp: Long, val content: String) } // Helper launcher to play around with presentation diff --git a/maestro-cli/src/main/java/maestro/cli/util/EnvUtils.kt b/maestro-cli/src/main/java/maestro/cli/util/EnvUtils.kt index d305942ce1..cd5883aa5e 100644 --- a/maestro-cli/src/main/java/maestro/cli/util/EnvUtils.kt +++ b/maestro-cli/src/main/java/maestro/cli/util/EnvUtils.kt @@ -75,6 +75,10 @@ object EnvUtils { return false } + fun isWindows(): Boolean { + return OS_NAME.lowercase().startsWith("windows") + } + /** * Returns major version of Java, e.g. 8, 11, 17, 21. */ diff --git a/maestro-studio/web/build.gradle b/maestro-studio/web/build.gradle index 64004225a3..a8fbdee673 100644 --- a/maestro-studio/web/build.gradle +++ b/maestro-studio/web/build.gradle @@ -1,7 +1,11 @@ tasks.register("deps", Exec.class) { inputs.file(layout.projectDirectory.file("package.json")) outputs.dir(layout.projectDirectory.dir("node_modules")) - commandLine("npm", "install") + if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) { + commandLine 'npm.cmd', 'install' + } else { + commandLine 'npm', 'install' + } } tasks.register("build", Exec.class) { @@ -11,5 +15,9 @@ tasks.register("build", Exec.class) { inputs.files(inputFiles) outputs.dir(layout.projectDirectory.dir("build")) dependsOn(tasks.deps) - commandLine("npm", "run", "build") + if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) { + commandLine 'npm.cmd', 'run', 'build' + } else { + commandLine("npm", "run", "build") + } }