From d0651490cb1d30126baeefeb759aeb30ec9caac5 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Thu, 10 Feb 2022 11:57:11 +0300 Subject: [PATCH 1/6] Update Kover to 0.5.0 --- buildSrc/build.gradle.kts | 6 +++++- buildSrc/src/main/kotlin/kover-conventions.gradle.kts | 2 +- gradle.properties | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 2637980a24..2cd46f41ef 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -60,5 +60,9 @@ dependencies { exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib") } implementation("ru.vyarus:gradle-animalsniffer-plugin:1.5.3") // Android API check - implementation("org.jetbrains.kotlinx:kover:${version("kover")}") + implementation("org.jetbrains.kotlinx:kover:${version("kover")}") { + exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8") + exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7") + exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib") + } } diff --git a/buildSrc/src/main/kotlin/kover-conventions.gradle.kts b/buildSrc/src/main/kotlin/kover-conventions.gradle.kts index 125ddb19ea..a8ea5909c3 100644 --- a/buildSrc/src/main/kotlin/kover-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/kover-conventions.gradle.kts @@ -15,7 +15,7 @@ val expectedCoverage = mutableMapOf( // Re-evaluate this along with Kover update where deprecated with error+ functions are not considered as uncovered: IDEA-287459 "kotlinx-coroutines-reactor" to 65, - "kotlinx-coroutines-rx2" to 78 + "kotlinx-coroutines-rx2" to 83 ) extensions.configure { diff --git a/gradle.properties b/gradle.properties index 922f786fb1..b2da29c799 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,7 @@ rxjava3_version=3.0.2 javafx_version=11.0.2 javafx_plugin_version=0.0.8 binary_compatibility_validator_version=0.8.0 -kover_version=0.5.0-RC2 +kover_version=0.5.0 blockhound_version=1.0.2.RELEASE jna_version=5.9.0 From c54fb0b85a775e6f58de149c6ff5e4319138753b Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Fri, 11 Feb 2022 12:50:25 +0300 Subject: [PATCH 2/6] Update Kover percentage --- buildSrc/src/main/kotlin/kover-conventions.gradle.kts | 8 ++++---- reactive/kotlinx-coroutines-reactor/build.gradle.kts | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/buildSrc/src/main/kotlin/kover-conventions.gradle.kts b/buildSrc/src/main/kotlin/kover-conventions.gradle.kts index a8ea5909c3..a469cd704d 100644 --- a/buildSrc/src/main/kotlin/kover-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/kover-conventions.gradle.kts @@ -13,10 +13,8 @@ val expectedCoverage = mutableMapOf( "kotlinx-coroutines-swing" to 70, // awaitFrame is not tested "kotlinx-coroutines-javafx" to 39, // JavaFx is not tested on TC because its graphic subsystem cannot be initialized in headless mode - // Re-evaluate this along with Kover update where deprecated with error+ functions are not considered as uncovered: IDEA-287459 - "kotlinx-coroutines-reactor" to 65, - "kotlinx-coroutines-rx2" to 83 -) + // Reactor has lower coverage in general due to various fatal error handling features + "kotlinx-coroutines-reactor" to 80) extensions.configure { disabledProjects = notCovered @@ -28,6 +26,8 @@ extensions.configure { * ./gradlew :p:koverReport -Pkover.enabled=true -- generates report */ isDisabled = !(properties["kover.enabled"]?.toString()?.toBoolean() ?: false) + // TODO remove when updating Kover to version 0.5.x + intellijEngineVersion.set("1.0.657") } subprojects { diff --git a/reactive/kotlinx-coroutines-reactor/build.gradle.kts b/reactive/kotlinx-coroutines-reactor/build.gradle.kts index 5abf3862dc..1a36ccec28 100644 --- a/reactive/kotlinx-coroutines-reactor/build.gradle.kts +++ b/reactive/kotlinx-coroutines-reactor/build.gradle.kts @@ -29,7 +29,8 @@ externalDocumentationLink( ) val commonKoverExcludes = listOf( - "kotlinx.coroutines.reactor.FlowKt" // Deprecated + "kotlinx.coroutines.reactor.FlowKt", // Deprecated + "kotlinx.coroutines.reactor.ConvertKt\$asFlux$1" // Deprecated ) tasks.koverHtmlReport { From cd5cbb9cdc381d72d33e1ace5037bf009c1f2fba Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Fri, 11 Feb 2022 14:26:12 +0300 Subject: [PATCH 3/6] Update robolectric to workaround https://github.com/robolectric/robolectric/issues/5456 and then workaround all the update consequences --- gradle.properties | 2 +- .../build.gradle.kts | 34 +++++++++++++++++-- .../test/AndroidExceptionPreHandlerTest.kt | 1 + .../test/DisabledHandlerTest.kt | 1 + .../test/HandlerDispatcherAsyncTest.kt | 1 + .../test/HandlerDispatcherTest.kt | 2 +- 6 files changed, 37 insertions(+), 4 deletions(-) diff --git a/gradle.properties b/gradle.properties index b2da29c799..44799ee9ab 100644 --- a/gradle.properties +++ b/gradle.properties @@ -30,7 +30,7 @@ jna_version=5.9.0 # Android versions android_version=4.1.1.4 androidx_annotation_version=1.1.0 -robolectric_version=4.0.2 +robolectric_version=4.4 baksmali_version=2.2.7 # JS diff --git a/ui/kotlinx-coroutines-android/build.gradle.kts b/ui/kotlinx-coroutines-android/build.gradle.kts index 145ad9f6b4..4f1d1d45da 100644 --- a/ui/kotlinx-coroutines-android/build.gradle.kts +++ b/ui/kotlinx-coroutines-android/build.gradle.kts @@ -10,16 +10,46 @@ configurations { repositories { mavenCentral() - jcenter() // https://youtrack.jetbrains.com/issue/IDEA-261387 } + +val artifactType = Attribute.of("artifactType", String::class.java) +val unpackedAar = Attribute.of("unpackedAar", Boolean::class.javaObjectType) + +configurations.configureEach { + afterEvaluate { + if (isCanBeResolved) { + attributes.attribute(unpackedAar, true) // request all AARs to be unpacked + } + } +} + dependencies { + attributesSchema { + attribute(unpackedAar) + } + + artifactTypes { + create("aar") { + attributes.attribute(unpackedAar, false) + } + } + + registerTransform(UnpackAar::class.java) { + from.attribute(unpackedAar, false).attribute(artifactType, "aar") + to.attribute(unpackedAar, true).attribute(artifactType, "jar") + } + compileOnly("com.google.android:android:${version("android")}") compileOnly("androidx.annotation:annotation:${version("androidx_annotation")}") testImplementation("com.google.android:android:${version("android")}") testImplementation("org.robolectric:robolectric:${version("robolectric")}") - testImplementation("org.smali:baksmali:${version("baksmali")}") + // Required by robolectric + testImplementation("androidx.test:core:1.2.0") + testImplementation("androidx.test:monitor:1.2.0") + + testImplementation("org.smali:baksmali:${version("baksmali")}") "r8"("com.android.tools.build:builder:7.1.0-alpha01") } diff --git a/ui/kotlinx-coroutines-android/test/AndroidExceptionPreHandlerTest.kt b/ui/kotlinx-coroutines-android/test/AndroidExceptionPreHandlerTest.kt index 4aa44eceaf..1220797009 100644 --- a/ui/kotlinx-coroutines-android/test/AndroidExceptionPreHandlerTest.kt +++ b/ui/kotlinx-coroutines-android/test/AndroidExceptionPreHandlerTest.kt @@ -13,6 +13,7 @@ import kotlin.test.* @RunWith(RobolectricTestRunner::class) @Config(manifest = Config.NONE, sdk = [27]) +@LooperMode(LooperMode.Mode.LEGACY) class AndroidExceptionPreHandlerTest : TestBase() { @Test fun testUnhandledException() = runTest { diff --git a/ui/kotlinx-coroutines-android/test/DisabledHandlerTest.kt b/ui/kotlinx-coroutines-android/test/DisabledHandlerTest.kt index a1f0a03d4a..a5b5ec95ee 100644 --- a/ui/kotlinx-coroutines-android/test/DisabledHandlerTest.kt +++ b/ui/kotlinx-coroutines-android/test/DisabledHandlerTest.kt @@ -13,6 +13,7 @@ import org.robolectric.annotation.* @RunWith(RobolectricTestRunner::class) @Config(manifest = Config.NONE, sdk = [28]) +@LooperMode(LooperMode.Mode.LEGACY) class DisabledHandlerTest : TestBase() { private var delegateToSuper = false diff --git a/ui/kotlinx-coroutines-android/test/HandlerDispatcherAsyncTest.kt b/ui/kotlinx-coroutines-android/test/HandlerDispatcherAsyncTest.kt index 7b03e771f9..c2091f339f 100644 --- a/ui/kotlinx-coroutines-android/test/HandlerDispatcherAsyncTest.kt +++ b/ui/kotlinx-coroutines-android/test/HandlerDispatcherAsyncTest.kt @@ -18,6 +18,7 @@ import kotlin.test.* @RunWith(RobolectricTestRunner::class) @Config(manifest = Config.NONE, sdk = [28]) +@LooperMode(LooperMode.Mode.LEGACY) class HandlerDispatcherAsyncTest : TestBase() { /** diff --git a/ui/kotlinx-coroutines-android/test/HandlerDispatcherTest.kt b/ui/kotlinx-coroutines-android/test/HandlerDispatcherTest.kt index 24758444b0..fe97ae8d27 100644 --- a/ui/kotlinx-coroutines-android/test/HandlerDispatcherTest.kt +++ b/ui/kotlinx-coroutines-android/test/HandlerDispatcherTest.kt @@ -16,6 +16,7 @@ import kotlin.test.* @RunWith(RobolectricTestRunner::class) @Config(manifest = Config.NONE, sdk = [28]) +@LooperMode(LooperMode.Mode.LEGACY) class HandlerDispatcherTest : TestBase() { @Test fun testImmediateDispatcherYield() = runBlocking(Dispatchers.Main) { @@ -121,7 +122,6 @@ class HandlerDispatcherTest : TestBase() { } private fun CoroutineScope.doTestAwaitWithDetectedChoreographer() { - ShadowChoreographer.reset() ShadowChoreographer.setPostFrameCallbackDelay(100) val mainLooper = Shadows.shadowOf(Looper.getMainLooper()) launch(Dispatchers.Main, start = CoroutineStart.UNDISPATCHED) { From aef007e1018ac1c9a12ef067c54e07759bd2ff83 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Mon, 14 Feb 2022 13:53:59 +0300 Subject: [PATCH 4/6] Update robolectric to workaround https://github.com/robolectric/robolectric/issues/5456 and then workaround all the update consequences --- buildSrc/src/main/kotlin/UnpackAar.kt | 33 ++++++++++++++++++- .../build.gradle.kts | 31 ++++------------- .../android-unit-tests/build.gradle.kts | 9 ++++- .../tests/CustomizedRobolectricTest.kt | 3 +- .../ordered/tests/FirstRobolectricTest.kt | 1 + .../build.gradle.kts | 26 ++------------- 6 files changed, 51 insertions(+), 52 deletions(-) diff --git a/buildSrc/src/main/kotlin/UnpackAar.kt b/buildSrc/src/main/kotlin/UnpackAar.kt index b3152d7ab0..efb0ad0a06 100644 --- a/buildSrc/src/main/kotlin/UnpackAar.kt +++ b/buildSrc/src/main/kotlin/UnpackAar.kt @@ -2,18 +2,49 @@ * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ +import org.gradle.api.* import org.gradle.api.artifacts.transform.InputArtifact import org.gradle.api.artifacts.transform.TransformAction import org.gradle.api.artifacts.transform.TransformOutputs import org.gradle.api.artifacts.transform.TransformParameters +import org.gradle.api.attributes.* import org.gradle.api.file.FileSystemLocation import org.gradle.api.provider.Provider +import org.gradle.kotlin.dsl.* import java.io.File import java.nio.file.Files import java.util.zip.ZipEntry import java.util.zip.ZipFile -// TODO move back to kotlinx-coroutines-play-services when it's migrated to the kts +// Attributes used by aar dependencies +val artifactType = Attribute.of("artifactType", String::class.java) +val unpackedAar = Attribute.of("unpackedAar", Boolean::class.javaObjectType) + +fun Project.configureAar() = configurations.configureEach { + afterEvaluate { + if (isCanBeResolved) { + attributes.attribute(unpackedAar, true) // request all AARs to be unpacked + } + } +} + +fun DependencyHandlerScope.configureAarUnpacking() { + attributesSchema { + attribute(unpackedAar) + } + + artifactTypes { + create("aar") { + attributes.attribute(unpackedAar, false) + } + } + + registerTransform(UnpackAar::class.java) { + from.attribute(unpackedAar, false).attribute(artifactType, "aar") + to.attribute(unpackedAar, true).attribute(artifactType, "jar") + } +} + @Suppress("UnstableApiUsage") abstract class UnpackAar : TransformAction { @get:InputArtifact diff --git a/integration/kotlinx-coroutines-play-services/build.gradle.kts b/integration/kotlinx-coroutines-play-services/build.gradle.kts index 59f3b0bd5a..9f8a128703 100644 --- a/integration/kotlinx-coroutines-play-services/build.gradle.kts +++ b/integration/kotlinx-coroutines-play-services/build.gradle.kts @@ -4,36 +4,17 @@ val tasksVersion = "16.0.1" -val artifactType = Attribute.of("artifactType", String::class.java) -val unpackedAar = Attribute.of("unpackedAar", Boolean::class.javaObjectType) - -configurations.configureEach { - afterEvaluate { - if (isCanBeResolved) { - attributes.attribute(unpackedAar, true) // request all AARs to be unpacked - } - } -} +project.configureAar() dependencies { - attributesSchema { - attribute(unpackedAar) - } - - artifactTypes { - create("aar") { - attributes.attribute(unpackedAar, false) - } - } - - registerTransform(UnpackAar::class.java) { - from.attribute(unpackedAar, false).attribute(artifactType, "aar") - to.attribute(unpackedAar, true).attribute(artifactType, "jar") - } - + configureAarUnpacking() api("com.google.android.gms:play-services-tasks:$tasksVersion") { exclude(group="com.android.support") } + + // Required by robolectric + testImplementation("androidx.test:core:1.2.0") + testImplementation("androidx.test:monitor:1.2.0") } externalDocumentationLink( diff --git a/ui/kotlinx-coroutines-android/android-unit-tests/build.gradle.kts b/ui/kotlinx-coroutines-android/android-unit-tests/build.gradle.kts index 2fd0b81479..625ce728b1 100644 --- a/ui/kotlinx-coroutines-android/android-unit-tests/build.gradle.kts +++ b/ui/kotlinx-coroutines-android/android-unit-tests/build.gradle.kts @@ -2,10 +2,17 @@ * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. */ +project.configureAar() + dependencies { - kotlinCompilerPluginClasspathMain(project(":kotlinx-coroutines-core")) + configureAarUnpacking() + testImplementation("com.google.android:android:${version("android")}") testImplementation("org.robolectric:robolectric:${version("robolectric")}") + // Required by robolectric + testImplementation("androidx.test:core:1.2.0") + testImplementation("androidx.test:monitor:1.2.0") + testImplementation(project(":kotlinx-coroutines-test")) testImplementation(project(":kotlinx-coroutines-android")) } diff --git a/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/CustomizedRobolectricTest.kt b/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/CustomizedRobolectricTest.kt index bcc12d5441..676ee4310d 100644 --- a/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/CustomizedRobolectricTest.kt +++ b/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/CustomizedRobolectricTest.kt @@ -26,6 +26,7 @@ class InitMainDispatcherBeforeRobolectricTestRunner(testClass: Class<*>) : Robol @Config(manifest = Config.NONE, sdk = [28]) @RunWith(InitMainDispatcherBeforeRobolectricTestRunner::class) +@LooperMode(LooperMode.Mode.LEGACY) class CustomizedRobolectricTest : TestBase() { @Test fun testComponent() { @@ -52,4 +53,4 @@ class CustomizedRobolectricTest : TestBase() { mainLooper.unPause() assertTrue(component.launchCompleted) } -} \ No newline at end of file +} diff --git a/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/FirstRobolectricTest.kt b/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/FirstRobolectricTest.kt index eab6fc17fb..99744f897f 100644 --- a/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/FirstRobolectricTest.kt +++ b/ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/FirstRobolectricTest.kt @@ -15,6 +15,7 @@ import kotlin.test.* @RunWith(RobolectricTestRunner::class) @Config(manifest = Config.NONE, sdk = [28]) +@LooperMode(LooperMode.Mode.LEGACY) open class FirstRobolectricTest { @Test fun testComponent() { diff --git a/ui/kotlinx-coroutines-android/build.gradle.kts b/ui/kotlinx-coroutines-android/build.gradle.kts index 4f1d1d45da..7618c529f7 100644 --- a/ui/kotlinx-coroutines-android/build.gradle.kts +++ b/ui/kotlinx-coroutines-android/build.gradle.kts @@ -12,32 +12,10 @@ repositories { mavenCentral() } -val artifactType = Attribute.of("artifactType", String::class.java) -val unpackedAar = Attribute.of("unpackedAar", Boolean::class.javaObjectType) - -configurations.configureEach { - afterEvaluate { - if (isCanBeResolved) { - attributes.attribute(unpackedAar, true) // request all AARs to be unpacked - } - } -} +project.configureAar() dependencies { - attributesSchema { - attribute(unpackedAar) - } - - artifactTypes { - create("aar") { - attributes.attribute(unpackedAar, false) - } - } - - registerTransform(UnpackAar::class.java) { - from.attribute(unpackedAar, false).attribute(artifactType, "aar") - to.attribute(unpackedAar, true).attribute(artifactType, "jar") - } + configureAarUnpacking() compileOnly("com.google.android:android:${version("android")}") compileOnly("androidx.annotation:annotation:${version("androidx_annotation")}") From 3dfb32831860420d448651e45c4c9d99ad17fb35 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Mon, 14 Feb 2022 17:35:12 +0300 Subject: [PATCH 5/6] Workaround for project() dependency --- buildSrc/src/main/kotlin/UnpackAar.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/UnpackAar.kt b/buildSrc/src/main/kotlin/UnpackAar.kt index efb0ad0a06..afe2627a3d 100644 --- a/buildSrc/src/main/kotlin/UnpackAar.kt +++ b/buildSrc/src/main/kotlin/UnpackAar.kt @@ -22,7 +22,7 @@ val unpackedAar = Attribute.of("unpackedAar", Boolean::class.javaObjectType) fun Project.configureAar() = configurations.configureEach { afterEvaluate { - if (isCanBeResolved) { + if (isCanBeResolved && !isCanBeConsumed) { attributes.attribute(unpackedAar, true) // request all AARs to be unpacked } } From f7ef59ed1157e8daaebc9d7fc6e20a4fae1d4213 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Tue, 15 Feb 2022 13:28:54 +0300 Subject: [PATCH 6/6] Decrease reactor koverage as previous value was in instructions count which is disabled for now --- buildSrc/src/main/kotlin/kover-conventions.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/kover-conventions.gradle.kts b/buildSrc/src/main/kotlin/kover-conventions.gradle.kts index a469cd704d..052e2bb684 100644 --- a/buildSrc/src/main/kotlin/kover-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/kover-conventions.gradle.kts @@ -14,7 +14,7 @@ val expectedCoverage = mutableMapOf( "kotlinx-coroutines-javafx" to 39, // JavaFx is not tested on TC because its graphic subsystem cannot be initialized in headless mode // Reactor has lower coverage in general due to various fatal error handling features - "kotlinx-coroutines-reactor" to 80) + "kotlinx-coroutines-reactor" to 75) extensions.configure { disabledProjects = notCovered