From 75bfc2a88bca0caa9a0d23937090bfad129aa6b8 Mon Sep 17 00:00:00 2001 From: TrevJonez Date: Fri, 18 Aug 2017 14:02:34 -0600 Subject: [PATCH 1/7] agp3.0 prep --- app/build.gradle | 8 ++++---- app/kontrast.gradle | 4 ++-- build.gradle | 4 ++-- gradle/wrapper/gradle-wrapper.jar | Bin 54712 -> 54708 bytes gradle/wrapper/gradle-wrapper.properties | 3 +-- plugin/build.gradle | 2 +- .../com/trevjonez/kontrast/KontrastPlugin.kt | 13 +++++++------ .../trevjonez/kontrast/KontrastPluginTest.kt | 6 +++--- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1c6ac49..ae54c7f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' diff --git a/app/kontrast.gradle b/app/kontrast.gradle index f54b40e..ab76c13 100644 --- a/app/kontrast.gradle +++ b/app/kontrast.gradle @@ -15,6 +15,6 @@ */ dependencies { - debugCompile project(':appClient') - androidTestCompile project(':androidTestClient') + debugApi project(':appClient') + androidTestImplementation project(':androidTestClient') } \ No newline at end of file diff --git a/build.gradle b/build.gradle index dff3fc3..5ee12cf 100644 --- a/build.gradle +++ b/build.gradle @@ -15,9 +15,9 @@ */ buildscript { - ext.kotlin_version = '1.1.4' + ext.kotlin_version = '1.1.4-2' ext.kotlinx_html_version = '0.6.3' - ext.android_plugin_version = '2.3.3' + ext.android_plugin_version = '3.0.0-beta2' ext.build_tools_version = '26.0.1' ext.support_lib_version = '26.0.1' ext.min_sdk = 16 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 6d99c690593968ee330b5b7a66c96feb76fdcf06..7a3265ee94c0ab25cf079ac8ccdf87f41d455d42 100644 GIT binary patch delta 673 zcmYL{T}YEr9LC@CS2iPM?-E7dDatC-SEkOe=9HWi7A|cvi!7}mR_kk$kr%=)BqA>g zwTIC+k+YNsInN&s|1%lPmm+E8Eh%)}BF_bAu%@Q_3^@dEz<l3g#bM?1)#;Dy%C z*08Rfp_Kwr&n_$#^@k<$_J3tb8p5lYQ&ern_>2i&vk|sgm5ME*;j$Po#HGGU$o4ut zVzaems!Pipl+CHkkB+&cBs+!K)|La8vj8h|Dk*JgD;Jh|m0CK5^vxfpvMzy<`9q9g zTsTe!4=kSDxVNA(A0`(X>6r&_J$qqD%BYVhRPN=n5NEx+gf+&k=v55*itr`UOy_+Z zD@AfLs!*sG-+Ig8NXU4}<)fRpKDZOVqE@=yFHq}OaQd@KrU4Wmd>#aSeGwT?5UXcak+u^JQr9RKSG`{j%M7A*Dx9H<8Jl?#zYtUjVpqWOon)o1DZFX^1&JE}ZvX%Q delta 808 zcmYk4T}YEr7{}l9XmeXrw`w}yW-CS5-l3&oS}xQ+XtWeTs~M49XogfPAukLG=|U>e z<)5-lk-X?e2!shjfyOqqeKbF2H+5Z-H%Sp)bkW&SbLZ;+e}2#NoO7OYeB&uo<0;-U zjk?KRQY}f+g(p=F>eZa}_VsoqdF2V8!=GB_+2O)3|53xjVUp@xY3h64#(5)8-VI0K z>~<;o1NG`*9{04j9zYAr^2*l55CMP zRGhaN%Et4k9`?fId`qE#wS}4J;mwRi$xu@yV0qC7w3Q~q+)@G0m8Ofz$IfJU-znf5 zrw*PE3hi=nn}=GLNgTmiqu;r8U`a9$gzCxJAPU+-XUN(pK0B@c0Y>yD-q@V>w?U*V2jOUddh<~co!?kI4GohP$$}^4kZuk&kF%7hO+nu3M~zb zwwWUa-cKRhsIcZ`C$)~Dd(4WyWj@hKWW@PICsm^1?{~=){f_i_BmJ0$cE*9eh#tPU p%mRqTuhF0%6aE8mujnj^kNy8I^XD*aKM7Z>c(7tuoeU&`{{X&35Rm`? diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 02f5c02..bf1b63c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/plugin/build.gradle b/plugin/build.gradle index cea0bad..2f94114 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -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' diff --git a/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt b/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt index e1d1355..206eaea 100644 --- a/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt +++ b/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt @@ -68,8 +68,7 @@ class KontrastPlugin : Plugin { 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") + project.dependencies.add("androidTestImplementation", "com.github.trevjonez.Kontrast:androidTestClient:$VERSION") val unzipTestTask = project.createTask(type = Copy::class, @@ -187,12 +186,12 @@ class KontrastPlugin : Plugin { val inputExtras = try { adapter.fromJson(buffer(source(File(renderTask.outputsDir, "${names.joinToString(File.separator)}${File.separator}extras.json")))) ?: mapOf() - } catch(ignore: FileNotFoundException) { + } catch (ignore: FileNotFoundException) { mapOf() } val keyExtras = try { adapter.fromJson(buffer(source(File(keyTask.outputsDir, "${names.joinToString(File.separator)}${File.separator}extras.json")))) ?: mapOf() - } catch(ignore: FileNotFoundException) { + } catch (ignore: FileNotFoundException) { mapOf() } @@ -250,9 +249,11 @@ class KontrastPlugin : Plugin { } } + /** + * 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 //3.0.0-beta2 + get() = this.outputs.single().outputFile private val ApplicationVariant.testApk: File get() = this.testVariant.outputs.single().outputFile diff --git a/plugin/src/test/kotlin/com/trevjonez/kontrast/KontrastPluginTest.kt b/plugin/src/test/kotlin/com/trevjonez/kontrast/KontrastPluginTest.kt index 6652ef0..fbe1328 100644 --- a/plugin/src/test/kotlin/com/trevjonez/kontrast/KontrastPluginTest.kt +++ b/plugin/src/test/kotlin/com/trevjonez/kontrast/KontrastPluginTest.kt @@ -41,7 +41,7 @@ class KontrastPluginTest { GradleRunner.create() .withProjectDir(projectDir) .forwardOutput() - .withArguments("app:captureDebugTestKeys_Nexus_5X_API_O") + .withArguments("app:captureDebugTestKeys_Nexus_5X_API_O", "--stacktrace") .build() assertThat(File(projectDir, "app/Kontrast/debug/Nexus_5X_API_O/com.trevjonez.kontrast.app.CardLayoutKontrastTest")).isDirectory().satisfies { @@ -104,7 +104,7 @@ class KontrastPluginTest { buildscript { ext.kotlin_version = '1.1.3-2' ext.kotlinx_html_version = '0.6.3' - ext.android_plugin_version = '2.3.3' + ext.android_plugin_version = '3.0.0-beta2' ext.build_tools_version = '26.0.1' ext.support_lib_version = '26.0.1' ext.min_sdk = 16 @@ -138,7 +138,7 @@ allprojects { apply plugin: 'kontrast' dependencies { - debugCompile group: 'com.github.trevjonez.Kontrast', name: 'appClient', version: '$kontrastVersion' + debugApi group: 'com.github.trevjonez.Kontrast', name: 'appClient', version: '$kontrastVersion' } """ } \ No newline at end of file From 79aba14a2e65437103e52b8a4411a4fb160b3214 Mon Sep 17 00:00:00 2001 From: TrevJonez Date: Fri, 18 Aug 2017 16:53:03 -0600 Subject: [PATCH 2/7] never up to date on the report task --- plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt b/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt index 206eaea..ddadf13 100644 --- a/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt +++ b/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt @@ -157,6 +157,7 @@ class KontrastPlugin : Plugin { outputDir = File(project.buildDir, "reports${File.separator}Kontrast${File.separator}${variant.name}${File.separator}${targetDevice.alias ?: targetDevice.id}") variantName = variant.name deviceAlias = targetDevice.alias ?: targetDevice.id + outputs.upToDateWhen { false } } } From 81c0c5b977ed28dff7bdf5a55fd4733ab039b32a Mon Sep 17 00:00:00 2001 From: TrevJonez Date: Fri, 18 Aug 2017 17:29:19 -0600 Subject: [PATCH 3/7] update example project to agp 3.0.0-beta2 --- example/app/build.gradle | 16 ++++++++-------- example/build.gradle | 7 ++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/example/app/build.gradle b/example/app/build.gradle index 7e217f7..86de0ae 100644 --- a/example/app/build.gradle +++ b/example/app/build.gradle @@ -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.0' + 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 { diff --git a/example/build.gradle b/example/build.gradle index 6daabf0..eaa224a 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -1,5 +1,6 @@ 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() @@ -7,9 +8,9 @@ buildscript { maven { url 'https://jitpack.io' } } dependencies { - classpath 'com.android.tools.build:gradle:2.3.3' + classpath 'com.android.tools.build:gradle:3.0.0-beta2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "com.github.trevjonez.Kontrast:plugin:0.1.0" + classpath "com.github.trevjonez.Kontrast:plugin:$kontrast_version" } } From 02accb54a40aa47e915a331cd78390fbc03c1c08 Mon Sep 17 00:00:00 2001 From: TrevJonez Date: Fri, 18 Aug 2017 17:48:35 -0600 Subject: [PATCH 4/7] filter on target variants not on device aliases. :beers: --- plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt b/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt index e589ff2..3a74e67 100644 --- a/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt +++ b/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt @@ -139,7 +139,7 @@ class KontrastPlugin : Plugin { androidExt.applicationVariants.all { variant -> if (variant.testVariant == null) return@all - kontrastDsl.deviceAliases.let { + kontrastDsl.targetVariants.let { if (it.isNotEmpty() && !it.contains(variant.name)) return@all } From b3e75a476dfb839bedab5e5cdbfa6eab237d7baf Mon Sep 17 00:00:00 2001 From: TrevJonez Date: Fri, 18 Aug 2017 17:51:48 -0600 Subject: [PATCH 5/7] use the snapshot deps for the agp3 line of plugin --- plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt b/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt index 3a74e67..a1321c6 100644 --- a/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt +++ b/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt @@ -51,7 +51,7 @@ class KontrastPlugin : Plugin { companion object { const val KONTRAST_CONFIG = "kontrast" const val GROUP = "Kontrast" - const val VERSION = "0.1.0" + const val VERSION = "AGP-3.0.0-SNAPSHOT" } internal lateinit var adb: Adb From 1e5c6bb0703333b29c11080fc17cffa01b32b705 Mon Sep 17 00:00:00 2001 From: TrevJonez Date: Thu, 28 Sep 2017 19:04:26 -0600 Subject: [PATCH 6/7] android plugin version bump --- build.gradle | 4 ++-- example/build.gradle | 2 +- .../test/kotlin/com/trevjonez/kontrast/KontrastPluginTest.kt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index e8da053..925aab0 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ buildscript { ext.kotlin_version = '1.1.4-2' ext.kotlinx_html_version = '0.6.3' - ext.android_plugin_version = '3.0.0-beta2' + ext.android_plugin_version = '3.0.0-beta6' ext.build_tools_version = '26.0.1' ext.support_lib_version = '26.0.1' ext.min_sdk = 16 @@ -47,4 +47,4 @@ task clean(type: Delete) { } group = 'com.github.trevjonez.Kontrast' -version = '0.1.1' +version = 'AGP-3.0.0-SNAPSHOT' diff --git a/example/build.gradle b/example/build.gradle index eaa224a..03aa2a8 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -8,7 +8,7 @@ buildscript { maven { url 'https://jitpack.io' } } dependencies { - classpath 'com.android.tools.build:gradle:3.0.0-beta2' + 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:$kontrast_version" } diff --git a/plugin/src/test/kotlin/com/trevjonez/kontrast/KontrastPluginTest.kt b/plugin/src/test/kotlin/com/trevjonez/kontrast/KontrastPluginTest.kt index 51c426c..c1a0cdf 100644 --- a/plugin/src/test/kotlin/com/trevjonez/kontrast/KontrastPluginTest.kt +++ b/plugin/src/test/kotlin/com/trevjonez/kontrast/KontrastPluginTest.kt @@ -104,7 +104,7 @@ class KontrastPluginTest { buildscript { ext.kotlin_version = '1.1.3-2' ext.kotlinx_html_version = '0.6.3' - ext.android_plugin_version = '3.0.0-beta2' + ext.android_plugin_version = '3.0.0-beta6' ext.build_tools_version = '26.0.1' ext.support_lib_version = '26.0.1' ext.min_sdk = 16 From bede060bbeacfd103f70e57637a968378287753d Mon Sep 17 00:00:00 2001 From: TrevJonez Date: Mon, 23 Oct 2017 12:16:22 -0600 Subject: [PATCH 7/7] remove need for telnet and update dependencies. --- README.md | 18 +--- build.gradle | 10 +-- example/.idea/runConfigurations.xml | 12 --- .../com/trevjonez/kontrast/KontrastPlugin.kt | 4 +- .../com/trevjonez/kontrast/adb/AdbDevice.kt | 5 ++ .../kontrast/adb/EmulatorConsoleHelpers.kt | 37 ++++++++ .../adb/TelnetEmulatorConsoleHelpers.kt | 40 --------- .../kontrast/dsl/KontrastExtension.kt | 6 -- .../kontrast/internal/RxExtensions.kt | 84 ++++++++++++++++++- .../trevjonez/kontrast/report/ReportIndex.kt | 2 +- .../trevjonez/kontrast/KontrastPluginTest.kt | 16 ++-- .../adb/TelnetEmulatorConsoleHelpersTest.kt | 2 +- 12 files changed, 141 insertions(+), 95 deletions(-) delete mode 100644 example/.idea/runConfigurations.xml create mode 100644 plugin/src/main/kotlin/com/trevjonez/kontrast/adb/EmulatorConsoleHelpers.kt delete mode 100644 plugin/src/main/kotlin/com/trevjonez/kontrast/adb/TelnetEmulatorConsoleHelpers.kt diff --git a/README.md b/README.md index 9bc9c61..baebe2b 100644 --- a/README.md +++ b/README.md @@ -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" } } @@ -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 diff --git a/build.gradle b/build.gradle index 925aab0..215b907 100644 --- a/build.gradle +++ b/build.gradle @@ -15,11 +15,11 @@ */ buildscript { - ext.kotlin_version = '1.1.4-2' + ext.kotlin_version = '1.1.51' ext.kotlinx_html_version = '0.6.3' - ext.android_plugin_version = '3.0.0-beta6' - 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 @@ -47,4 +47,4 @@ task clean(type: Delete) { } group = 'com.github.trevjonez.Kontrast' -version = 'AGP-3.0.0-SNAPSHOT' +version = '0.2.0' diff --git a/example/.idea/runConfigurations.xml b/example/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/example/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt b/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt index 68d3698..967cb70 100644 --- a/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt +++ b/plugin/src/main/kotlin/com/trevjonez/kontrast/KontrastPlugin.kt @@ -51,7 +51,7 @@ class KontrastPlugin : Plugin { companion object { const val KONTRAST_CONFIG = "kontrast" const val GROUP = "Kontrast" - const val VERSION = "AGP-3.0.0-SNAPSHOT" + const val VERSION = "0.2.0" } internal lateinit var adb: Adb @@ -107,7 +107,7 @@ class KontrastPlugin : Plugin { .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 -> diff --git a/plugin/src/main/kotlin/com/trevjonez/kontrast/adb/AdbDevice.kt b/plugin/src/main/kotlin/com/trevjonez/kontrast/adb/AdbDevice.kt index 37b47c7..0abe72a 100644 --- a/plugin/src/main/kotlin/com/trevjonez/kontrast/adb/AdbDevice.kt +++ b/plugin/src/main/kotlin/com/trevjonez/kontrast/adb/AdbDevice.kt @@ -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() + } } \ No newline at end of file diff --git a/plugin/src/main/kotlin/com/trevjonez/kontrast/adb/EmulatorConsoleHelpers.kt b/plugin/src/main/kotlin/com/trevjonez/kontrast/adb/EmulatorConsoleHelpers.kt new file mode 100644 index 0000000..1b41ccd --- /dev/null +++ b/plugin/src/main/kotlin/com/trevjonez/kontrast/adb/EmulatorConsoleHelpers.kt @@ -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() + 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) +} \ No newline at end of file diff --git a/plugin/src/main/kotlin/com/trevjonez/kontrast/adb/TelnetEmulatorConsoleHelpers.kt b/plugin/src/main/kotlin/com/trevjonez/kontrast/adb/TelnetEmulatorConsoleHelpers.kt deleted file mode 100644 index bf89246..0000000 --- a/plugin/src/main/kotlin/com/trevjonez/kontrast/adb/TelnetEmulatorConsoleHelpers.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 java.io.File -import java.util.stream.Collectors - -fun getEmulatorName(adbDevice: AdbDevice, telnetPath: String): AdbDevice { - val telnet = ProcessBuilder(telnetPath, "localhost", adbDevice.id.removePrefix("emulator-")).start() - val home = System.getProperty("user.home") - val authToken = File(home, ".emulator_console_auth_token").readText() - telnet.outputStream.bufferedWriter().apply { - if (authToken.isNotBlank()) { - write("auth $authToken"); newLine(); flush() - } - write("avd name"); newLine(); flush() - write("exit"); newLine(); flush() - } - - val consoleOutput = telnet.inputStream - .bufferedReader() - .lines() - .collect(Collectors.toList()) - - return adbDevice.copy(alias = consoleOutput[consoleOutput.size - 2]) -} \ No newline at end of file diff --git a/plugin/src/main/kotlin/com/trevjonez/kontrast/dsl/KontrastExtension.kt b/plugin/src/main/kotlin/com/trevjonez/kontrast/dsl/KontrastExtension.kt index 95af56c..6cba1bf 100644 --- a/plugin/src/main/kotlin/com/trevjonez/kontrast/dsl/KontrastExtension.kt +++ b/plugin/src/main/kotlin/com/trevjonez/kontrast/dsl/KontrastExtension.kt @@ -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 - } } \ No newline at end of file diff --git a/plugin/src/main/kotlin/com/trevjonez/kontrast/internal/RxExtensions.kt b/plugin/src/main/kotlin/com/trevjonez/kontrast/internal/RxExtensions.kt index 684a07c..c0341f5 100644 --- a/plugin/src/main/kotlin/com/trevjonez/kontrast/internal/RxExtensions.kt +++ b/plugin/src/main/kotlin/com/trevjonez/kontrast/internal/RxExtensions.kt @@ -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 Completable.andThenEmit(value: T) = andThenObserve { Observable.just(value) } internal inline fun Completable.andThenObserve(crossinline func: () -> Observable): Observable = - andThen(Observable.unsafeCreate { func().subscribe(it::onNext, it::onError, it::onComplete) }) \ No newline at end of file + andThen(Observable.unsafeCreate { func().subscribe(it::onNext, it::onError, it::onComplete) }) + +fun Socket.toObservable(input: Observable): Observable { + 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 { + 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 Observable.doOnFirst(crossinline action: (T) -> Unit): Observable { + var first = true + return doOnNext { + if (first) { + first = false + action(it) + } + } +} \ No newline at end of file diff --git a/plugin/src/main/kotlin/com/trevjonez/kontrast/report/ReportIndex.kt b/plugin/src/main/kotlin/com/trevjonez/kontrast/report/ReportIndex.kt index c304d5b..c2f4523 100644 --- a/plugin/src/main/kotlin/com/trevjonez/kontrast/report/ReportIndex.kt +++ b/plugin/src/main/kotlin/com/trevjonez/kontrast/report/ReportIndex.kt @@ -26,7 +26,7 @@ class ReportIndex(val outputDir: File, val variantName: String, val deviceAlias: copyFileFromResources("material-components-web.min.css", "material-components-web.min.css", File(outputDir, "css")) copyFileFromResources("kotlin.js", "kotlin.js", File(outputDir, "js")) copyFileFromResources("material-components-web.min.js", "material-components-web.min.js", File(outputDir, "js")) - copyFileFromResources("reportJs_main.js", "kontrast.js", File(outputDir, "js")) + copyFileFromResources("reportJs.js", "kontrast.js", File(outputDir, "js")) println("Kontrast report: file://${outputDir.absolutePath}/index.html") } diff --git a/plugin/src/test/kotlin/com/trevjonez/kontrast/KontrastPluginTest.kt b/plugin/src/test/kotlin/com/trevjonez/kontrast/KontrastPluginTest.kt index c1a0cdf..c7a907c 100644 --- a/plugin/src/test/kotlin/com/trevjonez/kontrast/KontrastPluginTest.kt +++ b/plugin/src/test/kotlin/com/trevjonez/kontrast/KontrastPluginTest.kt @@ -41,7 +41,7 @@ class KontrastPluginTest { GradleRunner.create() .withProjectDir(projectDir) .forwardOutput() - .withArguments("app:captureDebugTestKeys_Nexus_5X_API_O", "-Pkontrast.telnetPath=/usr/local/bin/telnet") + .withArguments("app:captureDebugTestKeys_Nexus_5X_API_O") .build() assertThat(File(projectDir, "app/Kontrast/debug/Nexus_5X_API_O/com.trevjonez.kontrast.app.CardLayoutKontrastTest")).isDirectory().satisfies { @@ -77,7 +77,7 @@ class KontrastPluginTest { GradleRunner.create() .withProjectDir(projectDir) .forwardOutput() - .withArguments("app:testDebugKontrastTest_Nexus_5X_API_O", "-Pkontrast.telnetPath=/usr/local/bin/telnet") + .withArguments("app:testDebugKontrastTest_Nexus_5X_API_O") .buildAndFail() assertThat(File(projectDir, "app/build/reports/Kontrast/debug/Nexus_5X_API_O/images/com.trevjonez.kontrast.app.CardLayoutKontrastTest")).isDirectory().satisfies { @@ -102,11 +102,10 @@ class KontrastPluginTest { fun rootGradleFileContents(kontrastVersion: String) = """ buildscript { - ext.kotlin_version = '1.1.3-2' - ext.kotlinx_html_version = '0.6.3' - ext.android_plugin_version = '3.0.0-beta6' - ext.build_tools_version = '26.0.1' - ext.support_lib_version = '26.0.1' + ext.kotlin_version = '1.1.51' + 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 @@ -118,9 +117,6 @@ buildscript { dependencies { classpath group: 'org.jetbrains.kotlin', name: 'kotlin-gradle-plugin', version: kotlin_version classpath group: 'com.android.tools.build', name: 'gradle', version: android_plugin_version - classpath group: 'io.reactivex.rxjava2', name: 'rxjava', version: '2.1.1' - classpath group: 'com.squareup.moshi', name:'moshi', version: '1.5.0' - classpath group: 'org.jetbrains.kotlinx', name: 'kotlinx-html-jvm', version: kotlinx_html_version classpath group: 'com.github.trevjonez.Kontrast', name: 'plugin', version: '$kontrastVersion' } } diff --git a/plugin/src/test/kotlin/com/trevjonez/kontrast/adb/TelnetEmulatorConsoleHelpersTest.kt b/plugin/src/test/kotlin/com/trevjonez/kontrast/adb/TelnetEmulatorConsoleHelpersTest.kt index 8af4da8..c03c205 100644 --- a/plugin/src/test/kotlin/com/trevjonez/kontrast/adb/TelnetEmulatorConsoleHelpersTest.kt +++ b/plugin/src/test/kotlin/com/trevjonez/kontrast/adb/TelnetEmulatorConsoleHelpersTest.kt @@ -23,7 +23,7 @@ class TelnetEmulatorConsoleHelpersTest { @Test fun getEmulatorName() { val emulatorInput = AdbDevice("emulator-5554", AdbStatus.ONLINE) - val emulatorName = getEmulatorName(emulatorInput , "/usr/local/bin/telnet") + val emulatorName = getEmulatorName(emulatorInput) assertThat(emulatorName.alias).isEqualTo("Nexus_5X_API_O") } } \ No newline at end of file