diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/FilteringPluginConfiguration.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/FilteringPluginConfiguration.kt index 583d7945a..c3f3919f3 100644 --- a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/FilteringPluginConfiguration.kt +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/FilteringPluginConfiguration.kt @@ -1,23 +1,33 @@ package com.malinskiy.marathon +import com.malinskiy.marathon.execution.AnnotationFilter import com.malinskiy.marathon.execution.FilteringConfiguration +import com.malinskiy.marathon.execution.FullyQualifiedClassnameFilter +import com.malinskiy.marathon.execution.SimpleClassnameFilter import com.malinskiy.marathon.execution.TestFilter +import com.malinskiy.marathon.execution.TestPackageFilter import groovy.lang.Closure open class FilteringPluginConfiguration { - var whitelist: MutableCollection = mutableListOf() - var blacklist: MutableCollection = mutableListOf() + //groovy + var groovyWhiteList: Wrapper? = null + var groovyBlackList: Wrapper? = null fun whitelist(closure: Closure<*>) { - closure.delegate = whitelist + groovyWhiteList = Wrapper() + closure.delegate = groovyWhiteList closure.call() } fun blacklist(closure: Closure<*>) { - closure.delegate = blacklist + groovyBlackList = Wrapper() + closure.delegate = groovyBlackList closure.call() } + //kts + var whitelist: MutableCollection = mutableListOf() + var blacklist: MutableCollection = mutableListOf() fun whitelist(block: MutableCollection.() -> Unit) { whitelist.also(block) } @@ -27,6 +37,37 @@ open class FilteringPluginConfiguration { } } +open class Wrapper { + open var simpleClassNameFilter: ArrayList? = null + open var fullyQualifiedClassnameFilter: ArrayList? = null + open var testPackageFilter: ArrayList? = null + open var annotationFilter: ArrayList? = null +} + +fun Wrapper.toList(): List { + val mutableList = mutableListOf() + this.annotationFilter?.map { AnnotationFilter(it.toRegex()) }?.let { + mutableList.addAll(it) + } + this.fullyQualifiedClassnameFilter?.map { FullyQualifiedClassnameFilter(it.toRegex()) }?.let { + mutableList.addAll(it) + } + this.testPackageFilter?.map { TestPackageFilter(it.toRegex()) }?.let { + mutableList.addAll(it) + } + this.simpleClassNameFilter?.map { SimpleClassnameFilter(it.toRegex()) }?.let { + mutableList.addAll(it) + } + return mutableList +} + fun FilteringPluginConfiguration.toFilteringConfiguration(): FilteringConfiguration { + if (groovyWhiteList != null || groovyBlackList != null) { + val white = groovyWhiteList?.toList() ?: emptyList() + + val black = groovyBlackList?.toList() ?: emptyList() + return FilteringConfiguration(white, black) + } return FilteringConfiguration(whitelist, blacklist) } + diff --git a/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/executor/listeners/video/ScreenRecorderTestRunListener.kt b/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/executor/listeners/video/ScreenRecorderTestRunListener.kt index 405276e58..d7af59025 100644 --- a/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/executor/listeners/video/ScreenRecorderTestRunListener.kt +++ b/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/executor/listeners/video/ScreenRecorderTestRunListener.kt @@ -1,6 +1,7 @@ package com.malinskiy.marathon.android.executor.listeners.video import com.android.ddmlib.IDevice +import com.android.ddmlib.SyncException import com.android.ddmlib.testrunner.TestIdentifier import com.malinskiy.marathon.android.AndroidDevice import com.malinskiy.marathon.android.RemoteFileManager @@ -23,13 +24,16 @@ internal class ScreenRecorderTestRunListener(private val fileManager: FileManage private var hasFailed: Boolean = false private var screenRecorderStopper: ScreenRecorderStopper? = null + private var thread: Thread? = null + + private val awaitMillis = 10_000L override fun testStarted(test: TestIdentifier) { hasFailed = false screenRecorderStopper = ScreenRecorderStopper(deviceInterface) val screenRecorder = ScreenRecorder(deviceInterface, test) - Thread(screenRecorder, "ScreenRecorder").start() + thread = Thread(screenRecorder, "ScreenRecorder").also { it.start() } } override fun testFailed(test: TestIdentifier, trace: String) { @@ -38,26 +42,31 @@ internal class ScreenRecorderTestRunListener(private val fileManager: FileManage override fun testAssumptionFailure(test: TestIdentifier, trace: String) { screenRecorderStopper!!.stopScreenRecord(hasFailed) - if (hasFailed) { - pullTestVideo(test) + pullVideo(test) + } + + private fun pullVideo(test: TestIdentifier) { + try { + thread?.join(awaitMillis) + if (hasFailed) { + pullTestVideo(test) + } + removeTestVideo(test) + } catch (e: InterruptedException) { + logger.warn { "Can't stop recording" } + } catch (e: SyncException) { + logger.warn { "Can't pull video" } } - removeTestVideo(test) } override fun testIgnored(test: TestIdentifier) { screenRecorderStopper!!.stopScreenRecord(hasFailed) - if (hasFailed) { - pullTestVideo(test) - } - removeTestVideo(test) + pullVideo(test) } override fun testEnded(test: TestIdentifier, testMetrics: Map) { screenRecorderStopper!!.stopScreenRecord(hasFailed) - if (hasFailed) { - pullTestVideo(test) - } - removeTestVideo(test) + pullVideo(test) } private fun pullTestVideo(test: TestIdentifier) {