Skip to content

Commit

Permalink
Merge pull request #3 from trevjonez/AGP-3.0.0
Browse files Browse the repository at this point in the history
Agp 3.0.0
  • Loading branch information
trevjonez authored Oct 23, 2017
2 parents 625328d + 82fb17d commit cab90e5
Show file tree
Hide file tree
Showing 19 changed files with 168 additions and 118 deletions.
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ In the appropriate `build.gradle` file(s):
1. Add the jitpack maven repository and classpath dependency.
```groovy
buildscript {
ext.kontrast_version = '0.1.1'
ext.kontrast_version = '0.2.0'
repositories {
maven { url "https://jitpack.io" }
}
Expand Down Expand Up @@ -64,22 +64,6 @@ Kontrast {
targetVariant "ciDebug" //Only create tasks for ciDebug variant. can be called multiple times to create tasks for multiple variants.
}
```

8. Specify telnet path (Environment dependant)

In your `gradle.properties` file:
```properties
kontrast.telnetPath=/usr/local/bin/telnet
```
You can also specify it via the kontrast dsl although the properties mechanism is usually more appropriate.
```groovy
Kontrast {
telnetPath '/usr/local/bin/telnet'
}
```
You might be asking at this point "why telnet?".
The answer is, it is used to lookup the name of the running emulators.
If you know a better way please let me know by filing an issue.

#### Write your test cases

Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ android {
}

dependencies {
compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: kotlin_version
api group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: kotlin_version
kapt group: 'com.android.databinding', name: 'compiler', version: android_plugin_version
compile group: 'com.android.support', name: 'cardview-v7', version: support_lib_version
compile group: 'com.android.support.constraint', name: 'constraint-layout', version: '1.0.2'
api group: 'com.android.support', name: 'cardview-v7', version: support_lib_version
api group: 'com.android.support.constraint', name: 'constraint-layout', version: '1.0.2'

androidTestCompile group: 'junit', name: 'junit', version: '4.12'
androidTestImplementation group: 'junit', name: 'junit', version: '4.12'
}

apply from: 'kontrast.gradle'
4 changes: 2 additions & 2 deletions app/kontrast.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
*/

dependencies {
debugCompile project(':appClient')
androidTestCompile project(':androidTestClient')
debugApi project(':appClient')
androidTestImplementation project(':androidTestClient')
}
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/

buildscript {
ext.kotlin_version = '1.1.4'
ext.kotlin_version = '1.1.51'
ext.kotlinx_html_version = '0.6.3'
ext.android_plugin_version = '2.3.3'
ext.build_tools_version = '26.0.1'
ext.support_lib_version = '26.0.1'
ext.android_plugin_version = '3.0.0-rc2'
ext.build_tools_version = '26.0.2'
ext.support_lib_version = '26.1.0'
ext.min_sdk = 16
ext.target_sdk = 26

Expand Down Expand Up @@ -47,4 +47,4 @@ task clean(type: Delete) {
}

group = 'com.github.trevjonez.Kontrast'
version = '0.1.2'
version = '0.2.0'
12 changes: 0 additions & 12 deletions example/.idea/runConfigurations.xml

This file was deleted.

16 changes: 8 additions & 8 deletions example/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ android {
def supportLibVer = '26.0.1'

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "com.android.support:appcompat-v7:$supportLibVer"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
kapt 'com.android.databinding:compiler:2.3.3'
api "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
api "com.android.support:appcompat-v7:$supportLibVer"
api 'com.android.support.constraint:constraint-layout:1.0.2'
kapt 'com.android.databinding:compiler:3.0.0-beta2'

debugCompile 'com.github.trevjonez.Kontrast:appClient:0.1.1'
debugApi "com.github.trevjonez.Kontrast:appClient:$kontrast_version"

androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:1.0.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.0'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.0'
}

configurations.all {
Expand Down
7 changes: 4 additions & 3 deletions example/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
buildscript {
ext.kotlin_version = '1.1.4'
ext.kotlin_version = '1.1.4-2'
ext.kontrast_version = 'AGP-3.0.0-SNAPSHOT'
repositories {
google()
jcenter()
mavenLocal()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.github.trevjonez.Kontrast:plugin:0.1.1"
classpath "com.github.trevjonez.Kontrast:plugin:$kontrast_version"
}
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Sat Aug 05 13:57:46 MDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
2 changes: 1 addition & 1 deletion plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ gradlePlugin {

dependencies {
compile group: 'org.jetbrains.kotlinx', name: 'kotlinx-html-jvm', version: kotlinx_html_version
compile group: 'com.android.tools.build', name: 'gradle', version: '2.3.3'
compile group: 'com.android.tools.build', name: 'gradle', version: android_plugin_version
compile group: 'io.reactivex.rxjava2', name: 'rxjava', version: '2.1.1'
compile group: 'azadev.kotlin', name: 'aza-kotlin-css', version: '1.0'
compile group: 'com.squareup.moshi', name:'moshi', version: '1.5.0'
Expand Down
12 changes: 8 additions & 4 deletions plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class KontrastPlugin : Plugin<Project> {
companion object {
const val KONTRAST_CONFIG = "kontrast"
const val GROUP = "Kontrast"
const val VERSION = "0.1.2"
const val VERSION = "0.2.0"
}

internal lateinit var adb: Adb
Expand All @@ -68,7 +68,8 @@ class KontrastPlugin : Plugin<Project> {
project.dependencies.add(KONTRAST_CONFIG, "com.github.trevjonez.Kontrast:unitTestClient:$VERSION")
}

project.dependencies.add("androidTestCompile", "com.github.trevjonez.Kontrast:androidTestClient:$VERSION")
project.dependencies.add("androidTestImplementation", "com.github.trevjonez.Kontrast:androidTestClient:$VERSION")


val unzipTestTask = project.createTask(type = Copy::class,
name = "unpackageKontrastTestJar",
Expand Down Expand Up @@ -106,7 +107,7 @@ class KontrastPlugin : Plugin<Project> {
.filter { it.status == AdbStatus.ONLINE }
.flatMapSingle { adbDevice ->
if (adbDevice.isEmulator) {
Single.fromCallable { getEmulatorName(adbDevice, kontrastDsl.telnetPath) }
Single.fromCallable { getEmulatorName(adbDevice) }
.subscribeOn(Schedulers.io())
} else {
kontrastDsl.deviceAliases[adbDevice.id]?.let { alias: String ->
Expand Down Expand Up @@ -253,8 +254,11 @@ class KontrastPlugin : Plugin<Project> {
}
}

/**
* TODO: what will this do in an apk split situation
*/
private val ApplicationVariant.apk: File
get() = this.outputs.map { it.mainOutputFile }.single().outputFile
get() = this.outputs.single().outputFile

private val ApplicationVariant.testApk: File
get() = this.testVariant.outputs.single().outputFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ package com.trevjonez.kontrast.adb

data class AdbDevice(val id: String, val status: AdbStatus, val alias: String? = null) {
val isEmulator: Boolean = id.startsWith("emulator")
val portNumber: Int
get() {
require(isEmulator) { "attempting to read port number from physical device" }
return id.removePrefix("emulator-").toInt()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2017 Trevor Jones
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.trevjonez.kontrast.adb

import com.trevjonez.kontrast.internal.doOnFirst
import com.trevjonez.kontrast.internal.toObservable
import io.reactivex.schedulers.Schedulers
import io.reactivex.subjects.PublishSubject
import java.net.Socket

fun getEmulatorName(adbDevice: AdbDevice): AdbDevice {
val sendSubject = PublishSubject.create<String>()
val emulatorName = Socket("localhost", adbDevice.portNumber)
.toObservable(sendSubject)
.subscribeOn(Schedulers.io())
.skipWhile { it.trim() != "OK" }
.doOnFirst { sendSubject.onNext("avd name") }
.filter { it != "OK" }
.firstOrError()
.blockingGet()

return adbDevice.copy(alias = emulatorName)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,4 @@ open class KontrastExtension(project: Project) {
fun targetVariant(variantName: String) {
targetVariants.add(variantName)
}

var telnetPath = project.properties["kontrast.telnetPath"] as? String ?: "telnet"

fun telnetPath(path: String) {
telnetPath = path
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,94 @@
* limitations under the License.
*/

@file:Suppress("NOTHING_TO_INLINE")

package com.trevjonez.kontrast.internal

import io.reactivex.Completable
import io.reactivex.Observable
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import okio.BufferedSource
import okio.Okio.buffer
import okio.Okio.source
import java.net.Socket

internal fun <T> Completable.andThenEmit(value: T) = andThenObserve { Observable.just(value) }

internal inline fun <T> Completable.andThenObserve(crossinline func: () -> Observable<T>): Observable<T> =
andThen(Observable.unsafeCreate { func().subscribe(it::onNext, it::onError, it::onComplete) })
andThen(Observable.unsafeCreate { func().subscribe(it::onNext, it::onError, it::onComplete) })

fun Socket.toObservable(input: Observable<String>): Observable<String> {
return Observable.create { emitter ->
try {
val disposable = CompositeDisposable()
emitter.setDisposable(disposable)

val out = getOutputStream().bufferedWriter()
input.observeOn(Schedulers.io()).subscribe {
out.write(it)
out.newLine()
out.flush()
} addTo disposable

buffer(source(getInputStream()))
.readLines()
.subscribeOn(Schedulers.io())
.subscribe { emitter.onNext(it) } addTo disposable

object : Disposable {
override fun isDisposed(): Boolean {
return isClosed
}

override fun dispose() {
close()
}
} addTo disposable
} catch (error: Throwable) {
if (!emitter.isDisposed) emitter.onError(error)
}
}
}

inline infix fun Disposable.addTo(compositeDisposable: CompositeDisposable) = apply {
compositeDisposable.add(this)
}

fun BufferedSource.readLines(): Observable<String> {
return Observable.create { emitter ->
try {
emitter.setDisposable(object : Disposable {
override fun isDisposed(): Boolean {
return false
}

override fun dispose() {
close()
}
})
var next = readUtf8Line()
while (next != null) {
if (!emitter.isDisposed) emitter.onNext(next)
next = readUtf8Line()
}
if (!emitter.isDisposed) emitter.onComplete()
} catch (error: Throwable) {
if (error is IllegalStateException && error.message?.contains("closed") == true) {
if (!emitter.isDisposed) emitter.onComplete()
} else if (!emitter.isDisposed) emitter.onError(error)
}
}
}

inline fun <T> Observable<T>.doOnFirst(crossinline action: (T) -> Unit): Observable<T> {
var first = true
return doOnNext {
if (first) {
first = false
action(it)
}
}
}
Loading

0 comments on commit cab90e5

Please sign in to comment.