Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Modernization and adb deletions #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
apply from: 'dependencies.gradle'
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {
// Gradle will not find vars defined in an external file when referring to them
// in the buildscript block, unless you link it from the buildscript block, too.
apply from: 'dependencies.gradle'

repositories {
jcenter()
}

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
classpath 'com.github.ben-manes:gradle-versions-plugin:0.13.0'
classpath "org.junit.platform:junit-platform-gradle-plugin:$versions.junitPlatform"
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.40"
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
}
}

allprojects {
repositories {
jcenter()
}

apply plugin: 'com.github.ben-manes.versions'
tasks.withType(KotlinCompile).all {
kotlinOptions {
freeCompilerArgs += '-XXLanguage:+NewInference'
}
}
}

def gitTag() {
Expand All @@ -35,9 +32,7 @@ def gitTag() {
return tag
}

def projectVersion() {
def tag = gitTag()

def projectVersion(tag) {
if (tag.startsWith('v')) {
return tag.substring(1)
} else if (tag.isEmpty()) {
Expand All @@ -48,11 +43,18 @@ def projectVersion() {
}

def validateTagAndVersion() {
if (gitTag().isEmpty()) {
def gitTag = gitTag()
def tagVersion = projectVersion(gitTag)

if (gitTag.isEmpty()) {
throw new IllegalStateException('Publishing is not allowed because current commit has no tag')
}

if (projectVersion().isEmpty()) {
if (tagVersion.isEmpty()) {
throw new IllegalStateException('Publishing is not allowed because current projectVersion is empty')
}

if (tagVersion != project.version) {
throw new IllegalStateException('Publishing not allowed because current tag version does not match version declared in gradle.properties')
}
}
90 changes: 35 additions & 55 deletions composer/build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
apply plugin: 'kotlin'
apply plugin: 'application'
apply plugin: 'org.junit.platform.gradle.plugin'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'

mainClassName = 'com.gojuno.composer.MainKt'

dependencies {
compile libraries.kotlinStd
compile libraries.rxJava
compile libraries.jCommander
compile libraries.commanderOs
compile libraries.commanderAndroid
compile libraries.apacheCommonsIo
compile libraries.apacheCommonsLang
compile libraries.gson
compile libraries.dexParser
}

dependencies {
testCompile libraries.spek
testCompile libraries.junitPlatformRunner
testCompile libraries.spekJunitPlatformEngine
testCompile libraries.assertJ
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
api "com.gojuno.commander:android:0.2.0"
api "com.beust:jcommander:1.71"
api "commons-io:commons-io:2.6"
api "org.apache.commons:commons-text:1.6"
api "com.google.code.gson:gson:2.8.5"
api "com.linkedin.dextestparser:parser:1.1.0"

testImplementation "org.assertj:assertj-core:3.11.1"
testImplementation "org.spekframework.spek2:spek-dsl-jvm:2.0.5"
testRuntimeOnly "org.spekframework.spek2:spek-runner-junit5:2.0.5"
testRuntimeOnly "org.jetbrains.kotlin:kotlin-reflect"
}

jar {
Expand All @@ -39,23 +33,19 @@ jar {
}
}

junitPlatform {
platformVersion = versions.junitPlatform

filters {
engines {
include 'spek'
}
test {
useJUnitPlatform {
includeEngines 'spek2'
}
}

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

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}

Expand All @@ -67,23 +57,6 @@ task validatePublishing {

bintrayUpload.dependsOn validatePublishing

def pomConfig = {
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'gojuno'
name 'Juno Inc.'
email '[email protected]'
}
}
}

publishing {
publications {
ComposerPublication(MavenPublication) {
Expand All @@ -92,16 +65,23 @@ publishing {
artifact sourcesJar
artifact javadocJar

groupId 'com.gojuno.composer'
artifactId 'composer'
version projectVersion()

pom.withXml {
def root = asNode()
root.appendNode('description', 'Reactive Android Instrumentation Test Runner.')
root.appendNode('name', 'Composer')
root.appendNode('url', 'https://github.com/gojuno/composer')
root.children().last() + pomConfig
pom {
description ='Reactive Android Instrumentation Test Runner.'
url ='https://github.com/gojuno/composer'
licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'repo'
}
}
developers {
developer {
id = 'gojuno'
name = 'Juno Inc.'
email = '[email protected]'
}
}
}
}
}
Expand All @@ -121,7 +101,7 @@ bintray {
publications = ['ComposerPublication']

version {
name = projectVersion()
name = project.version
vcsTag = gitTag()

gpg {
Expand Down
10 changes: 4 additions & 6 deletions composer/src/main/kotlin/com/gojuno/composer/Apk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ fun parseTestPackage(testApkPath: String): TestPackage =
?.let(TestPackage::Valid)
?: TestPackage.ParseError("Cannot parse test package from `aapt dump badging \$APK` output.")
}
.toSingle()
.toBlocking()
.value()
.singleOrError()
.blockingGet()

fun parseTestRunner(testApkPath: String): TestRunner =
process(
Expand All @@ -60,9 +59,8 @@ fun parseTestRunner(testApkPath: String): TestRunner =
?.let(TestRunner::Valid)
?: TestRunner.ParseError("Cannot parse test runner from `aapt dump xmltree \$TEST_APK AndroidManifest.xml` output.")
}
.toSingle()
.toBlocking()
.value()
.singleOrError()
.blockingGet()

fun parseTests(testApkPath: String): List<TestMethod> =
DexParser.findTestMethods(testApkPath).map { TestMethod(it.testName, it.annotationNames) }
25 changes: 10 additions & 15 deletions composer/src/main/kotlin/com/gojuno/composer/Files.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
package com.gojuno.composer

import io.reactivex.Observable
import org.apache.commons.io.input.Tailer
import org.apache.commons.io.input.TailerListener
import rx.Emitter.BackpressureMode
import rx.Observable
import java.io.File
import java.io.FileNotFoundException
import java.lang.Exception

fun tail(file: File): Observable<String> = Observable.create<String>(
{ emitter ->
Tailer.create(file, object : TailerListener {
override fun init(tailer: Tailer) = emitter.setCancellation { tailer.stop() }
override fun handle(line: String) = emitter.onNext(line)
override fun handle(e: Exception) = emitter.onError(e)
override fun fileRotated() = emitter.onError(IllegalStateException("Output rotation detected $file"))
override fun fileNotFound() = emitter.onError(FileNotFoundException("$file file was not found"))
})
},
BackpressureMode.BUFFER
)
fun tail(file: File): Observable<String> = Observable.create { emitter ->
Tailer.create(file, object : TailerListener {
override fun init(tailer: Tailer) = emitter.setCancellable { tailer.stop() }
override fun handle(line: String) = emitter.onNext(line)
override fun handle(e: Exception) = emitter.onError(e)
override fun fileRotated() = emitter.onError(IllegalStateException("Output rotation detected $file"))
override fun fileNotFound() = emitter.onError(FileNotFoundException("$file file was not found"))
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.gojuno.composer
import com.gojuno.composer.InstrumentationTest.Status.Failed
import com.gojuno.composer.InstrumentationTest.Status.Ignored
import com.gojuno.composer.InstrumentationTest.Status.Passed
import rx.Observable
import io.reactivex.Observable
import java.io.File

data class InstrumentationTest(
Expand Down Expand Up @@ -186,5 +186,5 @@ fun Observable<InstrumentationEntry>.asTests(): Observable<InstrumentationTest>
}
}
.filter { it.tests.isNotEmpty() }
.flatMap { Observable.from(it.tests) }
.flatMap { Observable.fromIterable(it.tests) }
}
8 changes: 4 additions & 4 deletions composer/src/main/kotlin/com/gojuno/composer/JUnitReport.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.gojuno.composer

import com.gojuno.composer.AdbDeviceTest.Status.*
import org.apache.commons.lang3.StringEscapeUtils
import rx.Completable
import rx.Single
import io.reactivex.Completable
import io.reactivex.Single
import org.apache.commons.text.StringEscapeUtils
import java.io.File
import java.text.SimpleDateFormat
import java.util.*
Expand Down Expand Up @@ -73,4 +73,4 @@ fun writeJunit4Report(suite: Suite, outputFile: File): Completable = Single
}
}
.map { xml -> outputFile.writeText(xml) }
.toCompletable()
.ignoreElement()
19 changes: 9 additions & 10 deletions composer/src/main/kotlin/com/gojuno/composer/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import com.gojuno.commander.os.log
import com.gojuno.commander.os.nanosToHumanReadableTime
import com.gojuno.composer.html.writeHtmlReport
import com.google.gson.Gson
import rx.Observable
import rx.schedulers.Schedulers
import io.reactivex.Observable
import io.reactivex.Single
import io.reactivex.schedulers.Schedulers
import java.io.File
import java.util.*
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -105,9 +106,9 @@ private fun runAllTests(args: Args, testPackage: TestPackage.Valid, testRunner:
}
}
}
.doOnNext { log("${it.size} connected adb device(s): $it") }
.doOnSuccess { log("${it.size} connected adb device(s): $it") }
.flatMap { connectedAdbDevices ->
val runTestsOnDevices: List<Observable<AdbDeviceTestRun>> = connectedAdbDevices.mapIndexed { index, device ->
val runTestsOnDevices: List<Single<AdbDeviceTestRun>> = connectedAdbDevices.mapIndexed { index, device ->
val installTimeout = Pair(args.installTimeoutSeconds, TimeUnit.SECONDS)
val installAppApk = device.installApk(pathToApk = args.appApkPath, timeout = installTimeout)
val installTestApk = device.installApk(pathToApk = args.testApkPath, timeout = installTimeout)
Expand Down Expand Up @@ -160,10 +161,9 @@ private fun runAllTests(args: Args, testPackage: TestPackage.Valid, testRunner:
).toSingleDefault(adbDeviceTestRun)
}
.subscribeOn(Schedulers.io())
.toObservable()
}
}
Observable.zip(runTestsOnDevices, { results -> results.map { it as AdbDeviceTestRun } })
Single.zip(runTestsOnDevices, { results: Array<Any> -> results.map { it as AdbDeviceTestRun } })
}
.map { adbDeviceTestRuns ->
when (args.shard) {
Expand Down Expand Up @@ -199,11 +199,10 @@ private fun runAllTests(args: Args, testPackage: TestPackage.Valid, testRunner:
log("Generating HTML report...")
val htmlReportStartTime = System.nanoTime()
writeHtmlReport(gson, suites, File(args.outputDirectory, "html-report"), Date())
.doOnCompleted { log("HTML report generated, took ${(System.nanoTime() - htmlReportStartTime).nanosToHumanReadableTime()}.") }
.andThen(Observable.just(suites))
.doOnComplete { log("HTML report generated, took ${(System.nanoTime() - htmlReportStartTime).nanosToHumanReadableTime()}.") }
.andThen(Single.just(suites))
}
.toBlocking()
.first()
.blockingGet()
}

private fun List<String>.pairArguments(): List<Pair<String, String>> =
Expand Down
Loading