From f1ed6f0eb7fb6703ecc29db44f1882f5d3968ce4 Mon Sep 17 00:00:00 2001 From: Sarmad Ali Date: Mon, 12 Feb 2018 19:35:31 -0500 Subject: [PATCH] fix the report paths when `:` is part of device id connected to adb replace with `-` --- .../src/main/kotlin/com/gojuno/composer/Main.kt | 8 +++++--- .../src/main/kotlin/com/gojuno/composer/TestRun.kt | 13 ++++++++++--- .../kotlin/com/gojuno/composer/html/HtmlDevice.kt | 2 +- .../kotlin/com/gojuno/composer/html/HtmlFullTest.kt | 3 ++- .../kotlin/com/gojuno/composer/html/HtmlReport.kt | 3 ++- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/composer/src/main/kotlin/com/gojuno/composer/Main.kt b/composer/src/main/kotlin/com/gojuno/composer/Main.kt index 2cadb58..031c0b1 100644 --- a/composer/src/main/kotlin/com/gojuno/composer/Main.kt +++ b/composer/src/main/kotlin/com/gojuno/composer/Main.kt @@ -9,7 +9,7 @@ import com.google.gson.Gson import rx.Observable import rx.schedulers.Schedulers import java.io.File -import java.util.* +import java.util.Date import java.util.concurrent.TimeUnit sealed class Exit(val code: Int, val message: String?) { @@ -90,7 +90,7 @@ fun main(rawArgs: Array) { .flatMap { adbDeviceTestRun -> writeJunit4Report( suite = adbDeviceTestRun.toSuite(args.testPackage), - outputFile = File(File(args.outputDirectory, "junit4-reports"), "${device.id}.xml") + outputFile = File(File(args.outputDirectory, "junit4-reports"), "${device.sanitizedId()}.xml") ).toSingleDefault(adbDeviceTestRun) } .subscribeOn(Schedulers.io()) @@ -190,7 +190,9 @@ data class Device( val id: String, val logcat: File, val instrumentationOutput: File -) +){ + fun sanitizedId() = id.replace(":","-") +} fun AdbDeviceTestRun.toSuite(testPackage: String): Suite = Suite( testPackage = testPackage, diff --git a/composer/src/main/kotlin/com/gojuno/composer/TestRun.kt b/composer/src/main/kotlin/com/gojuno/composer/TestRun.kt index ce88529..2916d99 100644 --- a/composer/src/main/kotlin/com/gojuno/composer/TestRun.kt +++ b/composer/src/main/kotlin/com/gojuno/composer/TestRun.kt @@ -1,6 +1,10 @@ package com.gojuno.composer -import com.gojuno.commander.android.* +import com.gojuno.commander.android.AdbDevice +import com.gojuno.commander.android.adb +import com.gojuno.commander.android.log +import com.gojuno.commander.android.pullFolder +import com.gojuno.commander.android.redirectLogcatToFile import com.gojuno.commander.os.Notification import com.gojuno.commander.os.nanosToHumanReadableTime import com.gojuno.commander.os.process @@ -38,6 +42,8 @@ data class AdbDeviceTest( } } +fun AdbDevice.sanitizedId() = id.replace(":","-") + fun AdbDevice.runTests( testPackageName: String, testRunnerClass: String, @@ -48,7 +54,7 @@ fun AdbDevice.runTests( ): Single { val adbDevice = this - val logsDir = File(File(outputDir, "logs"), adbDevice.id) + val logsDir = File(File(outputDir, "logs"), adbDevice.sanitizedId()) val instrumentationOutputFile = File(logsDir, "instrumentation.output") val runTests = process( @@ -157,7 +163,7 @@ data class PulledFiles( private fun pullTestFiles(adbDevice: AdbDevice, test: InstrumentationTest, outputDir: File, verboseOutput: Boolean): Single = Single // TODO: Add support for spoon files dir. .fromCallable { - File(File(File(outputDir, "screenshots"), adbDevice.id), test.className).apply { mkdirs() } + File(File(File(outputDir, "screenshots"), adbDevice.sanitizedId()), test.className).apply { mkdirs() } } .flatMap { screenshotsFolderOnHostMachine -> adbDevice @@ -225,3 +231,4 @@ private fun saveLogcat(adbDevice: AdbDevice, logsDir: File): Observable null }, logcatPath = logcat.relativePathTo(htmlReportDir), - deviceId = adbDevice.id, + deviceId = adbDevice.sanitizedId(), properties = emptyMap(), // TODO: add properties support. filePaths = files.map { it.relativePathTo(htmlReportDir) }, screenshots = screenshots.map { diff --git a/composer/src/main/kotlin/com/gojuno/composer/html/HtmlReport.kt b/composer/src/main/kotlin/com/gojuno/composer/html/HtmlReport.kt index 9d892a7..390fdfc 100644 --- a/composer/src/main/kotlin/com/gojuno/composer/html/HtmlReport.kt +++ b/composer/src/main/kotlin/com/gojuno/composer/html/HtmlReport.kt @@ -1,6 +1,7 @@ package com.gojuno.composer.html import com.gojuno.composer.Suite +import com.gojuno.composer.sanitizedId import com.google.gson.Gson import org.apache.commons.lang3.StringEscapeUtils import rx.Completable @@ -66,7 +67,7 @@ fun writeHtmlReport(gson: Gson, suites: List, outputDir: File, date: Date suite .tests - .map { it to File(File(suitesDir, "$suiteId"), it.adbDevice.id).apply { mkdirs() } } + .map { it to File(File(suitesDir, "$suiteId"), it.adbDevice.sanitizedId()).apply { mkdirs() } } .map { (test, testDir) -> Triple(test, test.toHtmlFullTest(suiteId = "$suiteId", htmlReportDir = testDir), testDir) } .forEach { (test, htmlTest, testDir) -> val testJson = gson.toJson(htmlTest)