From d14847fbfac52a9a7fd8b19f57f336cc3ecbdf52 Mon Sep 17 00:00:00 2001 From: Przemyslaw Szymkowiak Date: Tue, 16 Oct 2018 18:27:12 +0200 Subject: [PATCH] Improved way of passing params to process builder and added updated readme. --- README.md | 15 ++++++ plugin/build.gradle | 2 +- .../cloud/FirebaseTestLabProcessCreator.kt | 50 +++++++++---------- .../firebasetestlabplugin/model/Device.kt | 2 +- 4 files changed, 42 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 62a7220..26a957b 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,21 @@ firebaseTestLab { // You can set timeout (in seconds) for test // timeout = 6000 + + // Enable Android Test Orchestrator more info at: https://developer.android.com/training/testing/junit-runner + // isUseOrchestrator = true // default false + + // A list of one or more test target filters to apply (default: run all test targets) + // testTargets = ["size large"] + + // Environment variables are mirrored as extra options to the am instrument -e KEY1 VALUE1 + // environmentVariables = ["clearPackageData=true", "coverage=true"] + + // The fully-qualified Java class name of the instrumentation test runner + // testRunnerClass = "com.my.package.MyRunner" + + // Pass any custom param for gcloud + // customParamsForGCloudTool = --no-performance-metrics } // You can define more devices someOtherDevices { diff --git a/plugin/build.gradle b/plugin/build.gradle index f1f4ff6..ef8a366 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -5,7 +5,7 @@ apply plugin: "maven" apply plugin: "com.gradle.plugin-publish" group = "firebase.test.lab" -version = "1.1.3-SNAPSHOT" +version = "1.1.5" gradlePlugin { diff --git a/plugin/src/main/java/com/appunite/firebasetestlabplugin/cloud/FirebaseTestLabProcessCreator.kt b/plugin/src/main/java/com/appunite/firebasetestlabplugin/cloud/FirebaseTestLabProcessCreator.kt index 257d426..5d7f753 100644 --- a/plugin/src/main/java/com/appunite/firebasetestlabplugin/cloud/FirebaseTestLabProcessCreator.kt +++ b/plugin/src/main/java/com/appunite/firebasetestlabplugin/cloud/FirebaseTestLabProcessCreator.kt @@ -3,7 +3,6 @@ package com.appunite.firebasetestlabplugin.cloud import com.appunite.firebasetestlabplugin.FirebaseTestLabPlugin import com.appunite.firebasetestlabplugin.model.Device import com.appunite.firebasetestlabplugin.model.TestResults -import com.appunite.firebasetestlabplugin.utils.asCommand import com.appunite.firebasetestlabplugin.utils.joinArgs import org.gradle.api.logging.Logger import java.io.File @@ -31,30 +30,31 @@ internal class FirebaseTestLabProcessCreator( ) fun callFirebaseTestLab(device: Device, apk: File, testType: TestType): TestResults { - val type = when (testType) { - TestType.Robo -> "--type robo" - is TestType.Instrumentation -> "--type instrumentation --test ${testType.testApk}" - } - - val processBuilder = ProcessBuilder(""" - ${sdk.gcloud.absolutePath} - firebase test android run - --format json - ${if (gCloudBucketName != null) "--results-bucket $gCloudBucketName" else ""} - ${if (gCloudDirectory != null) "--results-dir $gCloudDirectory" else ""} - $type - --locales ${device.locales.joinArgs()}, - --os-version-ids ${device.androidApiLevels.joinArgs()} - --orientations ${device.screenOrientations.map { orientation -> orientation.gcloudName }.joinArgs()} - ${if(device.isUseOrchestrator) "--use-orchestrator" else ""} - ${if (device.environmentVariables.isNotEmpty()) "--environment-variables ${device.environmentVariables.joinToString(",")}" else ""} - ${if (device.testTargets.isNotEmpty()) "--test-targets ${device.testTargets.joinToString(",", transform = { "\"$it\"" })}" else ""} - ${device.customParamsForGCloudTool} - ${device.testRunnerClass?.let { "--test-runner-class \"$it\"" } ?: ""} - --device-ids ${device .deviceIds.joinArgs()} - --app $apk - ${if (device.timeout > 0) "--timeoutSec ${device.timeout}s" else ""} - """.asCommand()) + val processBuilder = ProcessBuilder( + sequenceOf( + sdk.gcloud.absolutePath, + "firebase", "test", "android", "run", + "--format=json", + "--device-ids=${device.deviceIds.joinArgs()}", + "--app=$apk", + "--locales=${device.locales.joinArgs()}", + "--os-version-ids=${device.androidApiLevels.joinArgs()}", + "--orientations=${device.screenOrientations.map { orientation -> orientation.gcloudName }.joinArgs()}") + .plus(when (testType) { + TestType.Robo -> sequenceOf("--type=robo") + is TestType.Instrumentation -> sequenceOf("--type=instrumentation", "--test=${testType.testApk}") + }) + .plus(gCloudBucketName?.let { sequenceOf("--results-bucket=$it") } ?: sequenceOf()) + .plus(gCloudDirectory?.let { sequenceOf("--results-dir=$it") } ?: sequenceOf()) + .plus(if (device.isUseOrchestrator) sequenceOf("--use-orchestrator") else sequenceOf()) + .plus(if (device.environmentVariables.isNotEmpty()) sequenceOf("--environment-variables=${device.environmentVariables.joinToString(",")}") else sequenceOf()) + .plus(if (device.testTargets.isNotEmpty()) sequenceOf("--test-targets=${device.testTargets.joinToString(",")}") else sequenceOf()) + .plus(device.customParamsForGCloudTool) + .plus(device.testRunnerClass?.let { sequenceOf("--test-runner-class=$it") } ?: sequenceOf()) + .plus(if (device.timeout > 0) sequenceOf("--timeoutSec=${device.timeout}s") else sequenceOf()) + .toList() + ) + logger.debug(processBuilder.command().joinToString(separator = " ", transform = { "\"$it\"" })) val process = processBuilder.start() process.errorStream.bufferedReader().forEachLine { logger.lifecycle(it) } process.inputStream.bufferedReader().forEachLine { logger.lifecycle(it) } diff --git a/plugin/src/main/java/com/appunite/firebasetestlabplugin/model/Device.kt b/plugin/src/main/java/com/appunite/firebasetestlabplugin/model/Device.kt index dd76758..da1dd2f 100644 --- a/plugin/src/main/java/com/appunite/firebasetestlabplugin/model/Device.kt +++ b/plugin/src/main/java/com/appunite/firebasetestlabplugin/model/Device.kt @@ -13,7 +13,7 @@ class Device(val name: String) { var abiSplits: Set = setOf() var isUseOrchestrator = false var environmentVariables: List = listOf() - var customParamsForGCloudTool: String = "" + var customParamsForGCloudTool: List = listOf() var testTargets: List = listOf() var testRunnerClass: String? = null }