Skip to content

Commit

Permalink
Merge pull request #98 from Karumi/integrate-new-shot-android-module
Browse files Browse the repository at this point in the history
Improve release process and link shot-android module
  • Loading branch information
pedrovgs committed Apr 22, 2020
2 parents 98e65af + 9b82ed2 commit 19ec35b
Show file tree
Hide file tree
Showing 37 changed files with 338 additions and 354 deletions.
7 changes: 3 additions & 4 deletions build.gradle
@@ -1,9 +1,8 @@
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
google()
jcenter()
}
Expand All @@ -17,4 +16,4 @@ buildscript {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jlleitschuh.gradle:ktlint-gradle:8.2.0"
}
}
}
93 changes: 3 additions & 90 deletions core/build.gradle
@@ -1,10 +1,10 @@
group 'com.karumi'
version '4.0.0'

group GROUP
version VERSION_NAME
apply plugin: 'scala'
apply plugin: 'jacoco'
apply plugin: 'com.github.maiflai.scalatest'
apply plugin: 'scalafmt'
apply from: '../release.gradle'

repositories {
mavenCentral()
Expand All @@ -22,93 +22,6 @@ dependencies {
testCompile 'org.scalamock:scalamock-scalatest-support_2.12:3.5.0'
}

apply plugin: 'maven'
apply plugin: 'signing'

install {
repositories {
mavenDeployer {
repository(url: uri('../repo'))
}
}
}

def isReleaseBuild() {
return VERSION_NAME.contains("SNAPSHOT") == false
}

def getRepositoryUsername() {
return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
}

def getRepositoryPassword() {
return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
}

signing {
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}

task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}

artifacts {
archives javadocJar, sourcesJar
}

uploadArchives {
repositories {
mavenDeployer {
// POM signature
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
// Target repository
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}

pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME

pom.project {
name POM_NAME
description POM_DESCRIPTION
packaging POM_PACKAGING
url POM_URL

scm {
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
url POM_SCM_URL
}

licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}

developers {
developer {
id = POM_DEVELOPER_ID
name = POM_DEVELOPER_NAME
}
}
}
}
}
}

sourceSets {
test {
output.resourcesDir = "build/classes/test/resources"
Expand Down
4 changes: 2 additions & 2 deletions core/gradle.properties
@@ -1,3 +1,3 @@
POM_NAME=shot core
POM_ARTIFACT_ID=core
POM_NAME=Shot Core components
POM_ARTIFACT_ID=shot-core
POM_PACKAGING=jar
6 changes: 3 additions & 3 deletions core/src/main/scala/com/karumi/shot/domain/model.scala
Expand Up @@ -17,9 +17,9 @@ object model {
object Config {

val androidDependencyMode: FilePath = "androidTestImplementation"
val androidDependencyGroup: String = "com.facebook.testing.screenshot"
val androidDependencyName: String = "core"
val androidDependencyVersion: String = "0.12.0"
val androidDependencyGroup: String = "com.karumi"
val androidDependencyName: String = "shot-android"
val androidDependencyVersion: String = "4.0.1-SNAPSHOT"
val androidDependency: FilePath =
s"$androidDependencyGroup:$androidDependencyName:$androidDependencyVersion"
def screenshotsFolderName(flavor: String, buildType: String): FilePath =
Expand Down
Expand Up @@ -6,7 +6,7 @@ import org.scalatest.{FlatSpec, Matchers}
class ConfigSpec extends FlatSpec with Matchers {

"Config" should "use the screenshot tests library implemented by Facebook" in {
Config.androidDependency shouldBe "com.facebook.testing.screenshot:core:0.12.0"
Config.androidDependency shouldBe "com.karumi:shot-android:4.0.1-SNAPSHOT"
}

it should "add the dependency using the androidTestImplementation mode" in {
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
@@ -1,13 +1,13 @@
VERSION_CODE=040000
VERSION_NAME=4.0.0
VERSION_NAME=4.0.1-SNAPSHOT
VERSION_CODE=400001
GROUP=com.karumi
POM_DESCRIPTION=Gradle plugin developed to facilitate screenshot testing for Android.
POM_URL=https://github.com/karumi/shot
POM_SCM_URL=https://github.com/karumi/shot
POM_SCM_CONNECTION=scm:git@github.com:karumi/shot.git
POM_SCM_DEV_CONNECTION=scm:git@github.com:karumi/shot.git
POM_LICENCE_NAME=NONE
POM_LICENCE_URL=NONE
POM_LICENCE_DIST=NONE
POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=karumi
POM_DEVELOPER_NAME=karumi
POM_DEVELOPER_NAME=Karumi
109 changes: 109 additions & 0 deletions release.gradle
@@ -0,0 +1,109 @@
apply plugin: 'maven'
apply plugin: 'signing'

def isReleaseBuild() {
return VERSION_NAME.contains("SNAPSHOT") == false
}

def getReleaseRepositoryUrl() {
return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
}

def getSnapshotRepositoryUrl() {
return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
: "https://oss.sonatype.org/content/repositories/snapshots/"
}

def getRepositoryUsername() {
return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
}

def getRepositoryPassword() {
return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
}

afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME

if (isReleaseBuild()) {
repository(url: getReleaseRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
snapshotRepository(url: getSnapshotRepositoryUrl()) {
authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
}
} else {
repository(url: uri('../repo'))
}

pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL

scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}

licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}

developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}
}

signing {
required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}

def isAndroidProject = project.getPlugins().hasPlugin('com.android.application') || project.getPlugins().hasPlugin('com.android.library')
if (isAndroidProject) {
task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.sourceFiles
}

artifacts {
archives androidSourcesJar
}
} else {
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}

artifacts {
archives javadocJar, sourcesJar
}
}

}
3 changes: 3 additions & 0 deletions shot-android/build.gradle
@@ -1,6 +1,7 @@
apply plugin: "com.android.library"
apply plugin: "kotlin-android"
apply plugin: "org.jlleitschuh.gradle.ktlint"
apply from: '../release.gradle'

android {
compileSdkVersion 29
Expand All @@ -23,6 +24,7 @@ android {

repositories {
mavenCentral()
mavenLocal()
google()
jcenter()
}
Expand All @@ -32,4 +34,5 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "com.facebook.testing.screenshot:core:0.12.0"
implementation "androidx.test:runner:1.2.0"
implementation "androidx.recyclerview:recyclerview:1.1.0"
}
3 changes: 3 additions & 0 deletions shot-android/gradle.properties
@@ -0,0 +1,3 @@
POM_NAME=Shot Android Companion Library
POM_ARTIFACT_ID=shot-android
POM_PACKAGING=aar
20 changes: 19 additions & 1 deletion shot-android/src/main/java/com/karumi/shot/ScreenshotTest.kt
Expand Up @@ -6,7 +6,9 @@ import android.content.Context
import android.util.DisplayMetrics
import android.view.View
import android.view.WindowManager
import android.widget.EditText
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.RecyclerView
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import com.facebook.testing.screenshot.Screenshot
import com.facebook.testing.screenshot.Screenshot.snapActivity
Expand All @@ -23,11 +25,13 @@ interface ScreenshotTest {
widthInPx: Int? = null,
backgroundColor: Int = android.R.color.white
) {
val view = activity.findViewById<View>(android.R.id.content)

if (heightInPx == null && widthInPx == null) {
disableFlakyComponents(view)
waitForAnimationsToFinish()
snapActivity(activity).record()
} else {
val view = activity.findViewById<View>(android.R.id.content)
runOnUi {
view.setBackgroundResource(backgroundColor)
}
Expand All @@ -52,7 +56,11 @@ interface ScreenshotTest {
}
}

fun compareScreenshot(holder: RecyclerView.ViewHolder, heightInPx: Int, widthInPx: Int? = null) =
compareScreenshot(view = holder.itemView, heightInPx = heightInPx, widthInPx = widthInPx)

fun compareScreenshot(view: View, heightInPx: Int? = null, widthInPx: Int? = null, name: String? = null) {
disableFlakyComponents(view)
waitForAnimationsToFinish()

val context = getInstrumentation().targetContext
Expand Down Expand Up @@ -84,4 +92,14 @@ interface ScreenshotTest {
fun runOnUi(block: () -> Unit) {
getInstrumentation().runOnMainSync { block() }
}

fun disableFlakyComponents(view: View) {
ViewUtils.getFilteredChildren(view) {
it is EditText
}.forEach {
if (it is EditText) {
runOnUi { it.isCursorVisible = false }
}
}
}
}
Expand Up @@ -4,7 +4,7 @@ import android.os.Bundle
import androidx.test.runner.AndroidJUnitRunner
import com.facebook.testing.screenshot.ScreenshotRunner

class ShotTestRunner : AndroidJUnitRunner() {
open class ShotTestRunner : AndroidJUnitRunner() {

override fun onCreate(args: Bundle) {
super.onCreate(args)
Expand Down

0 comments on commit 19ec35b

Please sign in to comment.