diff --git a/core/src/main/scala/com/karumi/shot/Shot.scala b/core/src/main/scala/com/karumi/shot/Shot.scala index fbd53a08..8bf14396 100644 --- a/core/src/main/scala/com/karumi/shot/Shot.scala +++ b/core/src/main/scala/com/karumi/shot/Shot.scala @@ -35,10 +35,6 @@ class Shot( consoleReporter: ConsoleReporter, envVars: EnvVars ) { - def configureAdbPath(adbPath: Folder): Unit = { - Adb.adbBinaryPath = adbPath - } - def downloadScreenshots(appId: AppId, shotFolder: ShotFolder, orchestrated: Boolean): Unit = { console.show("⬇️ Pulling screenshots from your connected devices!") pullScreenshots(appId, shotFolder, orchestrated) diff --git a/core/src/main/scala/com/karumi/shot/android/Adb.scala b/core/src/main/scala/com/karumi/shot/android/Adb.scala index 5a234366..b669cd15 100644 --- a/core/src/main/scala/com/karumi/shot/android/Adb.scala +++ b/core/src/main/scala/com/karumi/shot/android/Adb.scala @@ -6,14 +6,15 @@ import com.karumi.shot.domain.model.{AppId, Folder} import scala.sys.process._ object Adb { - var adbBinaryPath: String = "" // To be able to support API 29+ with scoped storage we need to change // the base url where the app saves our screenshots inside the device. // This value is computed in runtime in shot-android AndroidStorageInfo. private val baseStoragePath = "/storage/emulated/0/Download" } -class Adb { +class Adb( + adbPath: String +) { private final val CR_ASCII_DECIMAL = 13 private val logger = ProcessLogger( @@ -94,10 +95,10 @@ class Adb { } private def executeAdbCommand(command: String): Int = - s"${Adb.adbBinaryPath} $command" ! logger + s"${adbPath} $command" ! logger private def executeAdbCommandWithResult(command: String): String = - s"${Adb.adbBinaryPath} $command" !! logger + s"${adbPath} $command" !! logger private def isCarriageReturnASCII(device: String): Boolean = device.charAt(0) == CR_ASCII_DECIMAL diff --git a/core/src/test/scala/com/karumi/shot/ShotSpec.scala b/core/src/test/scala/com/karumi/shot/ShotSpec.scala index 78ce995a..e5c66185 100644 --- a/core/src/test/scala/com/karumi/shot/ShotSpec.scala +++ b/core/src/test/scala/com/karumi/shot/ShotSpec.scala @@ -128,14 +128,6 @@ class ShotSpec ) } - it should "configure adb path" in { - val anyAdbPath = "/Library/androidsdk/bin/adb" - - shot.configureAdbPath(anyAdbPath) - - Adb.adbBinaryPath shouldBe anyAdbPath - } - it should "should delegate screenshots cleaning to Adb using the specified ANDROID_SERIAL env var" in { val appId: AppId = AppIdMother.anyAppId val device1: String = "emulator-5554" diff --git a/shot/src/main/scala/com/karumi/shot/ShotPlugin.scala b/shot/src/main/scala/com/karumi/shot/ShotPlugin.scala index 6432b1d1..cba6544f 100644 --- a/shot/src/main/scala/com/karumi/shot/ShotPlugin.scala +++ b/shot/src/main/scala/com/karumi/shot/ShotPlugin.scala @@ -3,17 +3,8 @@ package com.karumi.shot import com.android.build.gradle.api.BaseVariant import com.android.build.gradle.{AppExtension, LibraryExtension} import com.android.builder.model.{BuildType, ProductFlavor} -import com.karumi.shot.android.Adb -import com.karumi.shot.base64.Base64Encoder import com.karumi.shot.domain.Config import com.karumi.shot.exceptions.ShotException -import com.karumi.shot.reports.{ConsoleReporter, ExecutionReporter} -import com.karumi.shot.screenshots.{ - ScreenshotsComparator, - ScreenshotsDiffGenerator, - ScreenshotsSaver -} -import com.karumi.shot.system.EnvVars import com.karumi.shot.tasks.{ DownloadScreenshotsTask, ExecuteScreenshotTests, @@ -29,25 +20,12 @@ import scala.util.Try class ShotPlugin extends Plugin[Project] { private val console = new Console - private lazy val shot: Shot = - new Shot( - new Adb, - new Files, - new ScreenshotsComparator, - new ScreenshotsDiffGenerator(new Base64Encoder), - new ScreenshotsSaver, - console, - new ExecutionReporter, - new ConsoleReporter(console), - new EnvVars() - ) override def apply(project: Project): Unit = { addExtensions(project) addAndroidTestDependency(project) project.afterEvaluate { project => { - configureAdb(project) addTasks(project) } } @@ -55,7 +33,10 @@ class ShotPlugin extends Plugin[Project] { private def configureAdb(project: Project): Unit = { val adbPath = AdbPathExtractor.extractPath(project) - shot.configureAdbPath(adbPath) + } + + private def findAdbPath(project: Project): String = { + AdbPathExtractor.extractPath(project) } private def addTasks(project: Project): Unit = { @@ -170,7 +151,7 @@ class ShotPlugin extends Plugin[Project] { RemoveScreenshotsTask.name(flavor, buildType, beforeExecution = true), classOf[RemoveScreenshotsTask] ) - + val adbPath = findAdbPath(project) removeScreenshotsAfterExecution.configure { task => task.setDescription(RemoveScreenshotsTask.description(flavor, buildType)) task.flavor = flavor @@ -187,6 +168,7 @@ class ShotPlugin extends Plugin[Project] { task.recordScreenshots = project.hasProperty("record") task.printBase64 = project.hasProperty("printBase64") task.projectName = project.getName + task.adbPath = adbPath } removeScreenshotsBeforeExecution.configure { task => task.setDescription(RemoveScreenshotsTask.description(flavor, buildType)) @@ -204,6 +186,7 @@ class ShotPlugin extends Plugin[Project] { task.recordScreenshots = project.hasProperty("record") task.printBase64 = project.hasProperty("printBase64") task.projectName = project.getName + task.adbPath = adbPath } val downloadScreenshots = tasks @@ -224,6 +207,7 @@ class ShotPlugin extends Plugin[Project] { task.recordScreenshots = project.hasProperty("record") task.printBase64 = project.hasProperty("printBase64") task.projectName = project.getName + task.adbPath = adbPath } val executeScreenshot = tasks .register(ExecuteScreenshotTests.name(flavor, buildType), classOf[ExecuteScreenshotTests]) @@ -243,6 +227,7 @@ class ShotPlugin extends Plugin[Project] { task.recordScreenshots = project.hasProperty("record") task.printBase64 = project.hasProperty("printBase64") task.projectName = project.getName + task.adbPath = adbPath } if (runInstrumentation(project, extension)) { diff --git a/shot/src/main/scala/com/karumi/shot/tasks/Tasks.scala b/shot/src/main/scala/com/karumi/shot/tasks/Tasks.scala index 61f38224..c7bcf639 100644 --- a/shot/src/main/scala/com/karumi/shot/tasks/Tasks.scala +++ b/shot/src/main/scala/com/karumi/shot/tasks/Tasks.scala @@ -13,27 +13,28 @@ import com.karumi.shot.screenshots.{ import com.karumi.shot.system.EnvVars import com.karumi.shot.ui.Console import com.karumi.shot.{Files, Shot, ShotExtension} -import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.{Input, TaskAction} import org.gradle.api.{DefaultTask, GradleException} import java.io.File abstract class ShotTask extends DefaultTask { - var appId: String = _ - var flavor: Option[String] = _ - var buildTypeName: String = _ - var orchestrated: Boolean = false - var projectPath: String = _ - var buildPath: String = _ - var shotExtension: ShotExtension = _ - var directorySuffix: Option[String] = _ - var recordScreenshots: Boolean = _ - var printBase64: Boolean = _ - var projectName: String = _ - private val console = new Console - protected val shot: Shot = + @Input var appId: String = _ + @Input var flavor: Option[String] = _ + @Input var buildTypeName: String = _ + @Input var orchestrated: Boolean = false + @Input var projectPath: String = _ + @Input var buildPath: String = _ + @Input var shotExtension: ShotExtension = _ + @Input var directorySuffix: Option[String] = _ + @Input var recordScreenshots: Boolean = _ + @Input var printBase64: Boolean = _ + @Input var projectName: String = _ + @Input var adbPath: String = _ + protected def shot: Shot = { + val console = new Console new Shot( - new Adb, + new Adb(adbPath), new Files, new ScreenshotsComparator, new ScreenshotsDiffGenerator(new Base64Encoder), @@ -43,6 +44,7 @@ abstract class ShotTask extends DefaultTask { new ConsoleReporter(console), new EnvVars() ) + } protected def shotFolder: ShotFolder = { ShotFolder(