Skip to content

Commit

Permalink
Support passing runInstrumentation flag as gradle argument (#237)
Browse files Browse the repository at this point in the history
* Support passing `runInstrumentation` flag as gradle argument

Will allow overriding the configuration set in the gradle file with the commandline argument. 

e.g ./gradlew executeScreenshotTests -PrunInstrumentation=false

* Run formatting command

Co-authored-by: Sam <samdc@apadmi.com>
  • Loading branch information
SamCosta1 and SamC-Apadmi authored Jul 2, 2021
1 parent 16312db commit 6efd906
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion shot/src/main/scala/com/karumi/shot/ShotPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.gradle.api.artifacts.DependencySet
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.{Plugin, Project}

import scala.util.Try
class ShotPlugin extends Plugin[Project] {

private val console = new Console
Expand Down Expand Up @@ -182,7 +183,7 @@ class ShotPlugin extends Plugin[Project] {
task.appId = appId
}

if (extension.runInstrumentation) {
if (runInstrumentation(project, extension)) {
executeScreenshot.configure { task =>
task.dependsOn(instrumentationTaskName)
task.dependsOn(downloadScreenshots)
Expand Down Expand Up @@ -219,6 +220,20 @@ class ShotPlugin extends Plugin[Project] {
}
}

private def runInstrumentation(project: Project, extension: ShotExtension): Boolean = {
val property = project.findProperty("runInstrumentation").asInstanceOf[String]

if (property != null) {
if (Try(property.toBoolean).getOrElse(null) == null) {
throw ShotException("runInstrumentation value must be true|false")
}

return property.toBoolean
}

extension.runInstrumentation
}

private def isAnAndroidLibrary(project: Project): Boolean =
try {
getAndroidLibraryExtension(project)
Expand Down

0 comments on commit 6efd906

Please sign in to comment.