@@ -18,6 +18,7 @@ import org.gradle.api.Task
1818import org.gradle.api.tasks.Exec
1919import org.gradle.kotlin.dsl.closureOf
2020import org.gradle.kotlin.dsl.register
21+ import groovy.lang.Closure
2122import java.io.ByteArrayOutputStream
2223import java.io.File
2324
@@ -45,6 +46,8 @@ internal class FirebaseTestLabPlugin : Plugin<Project> {
4546 private const val taskAuth = " firebaseTestLabAuth"
4647 private const val taskSetup = " firebaseTestLabSetup"
4748 private const val taskSetProject = " firebaseTestLabSetProject"
49+ private const val taskPrefixDownload = " firebaseTestLabDownload"
50+ private const val taskPrefixExecute = " firebaseTestLabExecute"
4851 }
4952
5053 private lateinit var project: Project
@@ -218,10 +221,9 @@ internal class FirebaseTestLabPlugin : Plugin<Project> {
218221
219222 val cleanTask = " firebaseTestLabClean${variantName.capitalize()} "
220223
221- val runTestsTask = " firebaseTestLabExecute ${ variantName.capitalize()} "
224+ val runTestsTask = taskPrefixExecute + variantName.capitalize()
222225 val runTestsTaskInstrumentation = " ${runTestsTask} Instrumentation"
223226 val runTestsTaskRobo = " ${runTestsTask} Robo"
224- val downloadTask = " firebaseTestLabDownload${variantName.capitalize()} "
225227
226228 if (downloader != null ) {
227229 project.task(cleanTask, closureOf<Task > {
@@ -293,7 +295,7 @@ internal class FirebaseTestLabPlugin : Plugin<Project> {
293295 })
294296 }
295297
296- val allInstrumentation = project.task (runTestsTaskInstrumentation, closureOf<Task > {
298+ val allInstrumentation = addExecuteAndDownload (runTestsTaskInstrumentation, downloader, cleanTask , closureOf<Task > {
297299 group = Constants .FIREBASE_TEST_LAB
298300 description = " Run all Instrumentation tests for $variantName in Firebase Test Lab"
299301 dependsOn(instrumentationTasks)
@@ -335,25 +337,12 @@ internal class FirebaseTestLabPlugin : Plugin<Project> {
335337 }
336338 })
337339
338- project.task (runTestsTask, closureOf<Task > {
340+ addExecuteAndDownload (runTestsTask, downloader, cleanTask , closureOf<Task > {
339341 group = Constants .FIREBASE_TEST_LAB
340342 description = " Run all tests for $variantName in Firebase Test Lab"
341343 dependsOn(allRobo, allInstrumentation)
342344 })
343345
344- if (downloader != null ) {
345- project.task(downloadTask, closureOf<Task > {
346- group = Constants .FIREBASE_TEST_LAB
347- description = " Run Android Tests in Firebase Test Lab and download artifacts from google storage"
348- dependsOn(taskSetup)
349- dependsOn(runTestsTask)
350- mustRunAfter(cleanTask)
351-
352- doLast {
353- downloader.getResults()
354- }
355- })
356- }
357346 }
358347
359348 private fun processResult (result : TestResults , ignoreFailures : Boolean ) {
@@ -367,11 +356,30 @@ internal class FirebaseTestLabPlugin : Plugin<Project> {
367356 }
368357 }
369358 }
359+
360+ private fun addExecuteAndDownload (name : String , downloader : CloudTestResultDownloader ? , cleanTask : String , taskClosure : Closure <Any ?>): Task {
361+ val runTask = project.task(name, taskClosure)
362+ if (downloader != null ) {
363+ val configuration = name.substring(taskPrefixExecute.length)
364+ project.task(taskPrefixDownload + configuration, closureOf<Task > {
365+ group = Constants .FIREBASE_TEST_LAB
366+ description = " Run Android Tests for $configuration in Firebase Test Lab and download artifacts from google storage"
367+ dependsOn(taskSetup)
368+ dependsOn(name)
369+ mustRunAfter(cleanTask)
370+
371+ doLast {
372+ downloader.getResults()
373+ }
374+ })
375+ }
376+ return runTask
377+ }
370378}
371379
372380
373381private fun <T1 , T2 , R > combineAll (l1 : Collection <T1 >, l2 : Collection <T2 >, func : (T1 , T2 ) -> R ): List <R > =
374382 l1.flatMap { t1 -> l2.map { t2 -> func(t1, t2)} }
375383
376384private fun dashToCamelCase (dash : String ): String =
377- dash.split(' -' , ' _' ).joinToString(" " ) { it.capitalize() }
385+ dash.split(' -' , ' _' ).joinToString(" " ) { it.capitalize() }
0 commit comments