Skip to content

Commit aef007e

Browse files
committed
Update robolectric to workaround robolectric/robolectric#5456 and then workaround all the update consequences
1 parent cd5cbb9 commit aef007e

File tree

6 files changed

+51
-52
lines changed

6 files changed

+51
-52
lines changed

buildSrc/src/main/kotlin/UnpackAar.kt

+32-1
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,49 @@
22
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
import org.gradle.api.*
56
import org.gradle.api.artifacts.transform.InputArtifact
67
import org.gradle.api.artifacts.transform.TransformAction
78
import org.gradle.api.artifacts.transform.TransformOutputs
89
import org.gradle.api.artifacts.transform.TransformParameters
10+
import org.gradle.api.attributes.*
911
import org.gradle.api.file.FileSystemLocation
1012
import org.gradle.api.provider.Provider
13+
import org.gradle.kotlin.dsl.*
1114
import java.io.File
1215
import java.nio.file.Files
1316
import java.util.zip.ZipEntry
1417
import java.util.zip.ZipFile
1518

16-
// TODO move back to kotlinx-coroutines-play-services when it's migrated to the kts
19+
// Attributes used by aar dependencies
20+
val artifactType = Attribute.of("artifactType", String::class.java)
21+
val unpackedAar = Attribute.of("unpackedAar", Boolean::class.javaObjectType)
22+
23+
fun Project.configureAar() = configurations.configureEach {
24+
afterEvaluate {
25+
if (isCanBeResolved) {
26+
attributes.attribute(unpackedAar, true) // request all AARs to be unpacked
27+
}
28+
}
29+
}
30+
31+
fun DependencyHandlerScope.configureAarUnpacking() {
32+
attributesSchema {
33+
attribute(unpackedAar)
34+
}
35+
36+
artifactTypes {
37+
create("aar") {
38+
attributes.attribute(unpackedAar, false)
39+
}
40+
}
41+
42+
registerTransform(UnpackAar::class.java) {
43+
from.attribute(unpackedAar, false).attribute(artifactType, "aar")
44+
to.attribute(unpackedAar, true).attribute(artifactType, "jar")
45+
}
46+
}
47+
1748
@Suppress("UnstableApiUsage")
1849
abstract class UnpackAar : TransformAction<TransformParameters.None> {
1950
@get:InputArtifact

integration/kotlinx-coroutines-play-services/build.gradle.kts

+6-25
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,17 @@
44

55
val tasksVersion = "16.0.1"
66

7-
val artifactType = Attribute.of("artifactType", String::class.java)
8-
val unpackedAar = Attribute.of("unpackedAar", Boolean::class.javaObjectType)
9-
10-
configurations.configureEach {
11-
afterEvaluate {
12-
if (isCanBeResolved) {
13-
attributes.attribute(unpackedAar, true) // request all AARs to be unpacked
14-
}
15-
}
16-
}
7+
project.configureAar()
178

189
dependencies {
19-
attributesSchema {
20-
attribute(unpackedAar)
21-
}
22-
23-
artifactTypes {
24-
create("aar") {
25-
attributes.attribute(unpackedAar, false)
26-
}
27-
}
28-
29-
registerTransform(UnpackAar::class.java) {
30-
from.attribute(unpackedAar, false).attribute(artifactType, "aar")
31-
to.attribute(unpackedAar, true).attribute(artifactType, "jar")
32-
}
33-
10+
configureAarUnpacking()
3411
api("com.google.android.gms:play-services-tasks:$tasksVersion") {
3512
exclude(group="com.android.support")
3613
}
14+
15+
// Required by robolectric
16+
testImplementation("androidx.test:core:1.2.0")
17+
testImplementation("androidx.test:monitor:1.2.0")
3718
}
3819

3920
externalDocumentationLink(

ui/kotlinx-coroutines-android/android-unit-tests/build.gradle.kts

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
project.configureAar()
6+
57
dependencies {
6-
kotlinCompilerPluginClasspathMain(project(":kotlinx-coroutines-core"))
8+
configureAarUnpacking()
9+
710
testImplementation("com.google.android:android:${version("android")}")
811
testImplementation("org.robolectric:robolectric:${version("robolectric")}")
12+
// Required by robolectric
13+
testImplementation("androidx.test:core:1.2.0")
14+
testImplementation("androidx.test:monitor:1.2.0")
15+
916
testImplementation(project(":kotlinx-coroutines-test"))
1017
testImplementation(project(":kotlinx-coroutines-android"))
1118
}

ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/CustomizedRobolectricTest.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class InitMainDispatcherBeforeRobolectricTestRunner(testClass: Class<*>) : Robol
2626

2727
@Config(manifest = Config.NONE, sdk = [28])
2828
@RunWith(InitMainDispatcherBeforeRobolectricTestRunner::class)
29+
@LooperMode(LooperMode.Mode.LEGACY)
2930
class CustomizedRobolectricTest : TestBase() {
3031
@Test
3132
fun testComponent() {
@@ -52,4 +53,4 @@ class CustomizedRobolectricTest : TestBase() {
5253
mainLooper.unPause()
5354
assertTrue(component.launchCompleted)
5455
}
55-
}
56+
}

ui/kotlinx-coroutines-android/android-unit-tests/test/ordered/tests/FirstRobolectricTest.kt

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import kotlin.test.*
1515

1616
@RunWith(RobolectricTestRunner::class)
1717
@Config(manifest = Config.NONE, sdk = [28])
18+
@LooperMode(LooperMode.Mode.LEGACY)
1819
open class FirstRobolectricTest {
1920
@Test
2021
fun testComponent() {

ui/kotlinx-coroutines-android/build.gradle.kts

+2-24
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,10 @@ repositories {
1212
mavenCentral()
1313
}
1414

15-
val artifactType = Attribute.of("artifactType", String::class.java)
16-
val unpackedAar = Attribute.of("unpackedAar", Boolean::class.javaObjectType)
17-
18-
configurations.configureEach {
19-
afterEvaluate {
20-
if (isCanBeResolved) {
21-
attributes.attribute(unpackedAar, true) // request all AARs to be unpacked
22-
}
23-
}
24-
}
15+
project.configureAar()
2516

2617
dependencies {
27-
attributesSchema {
28-
attribute(unpackedAar)
29-
}
30-
31-
artifactTypes {
32-
create("aar") {
33-
attributes.attribute(unpackedAar, false)
34-
}
35-
}
36-
37-
registerTransform(UnpackAar::class.java) {
38-
from.attribute(unpackedAar, false).attribute(artifactType, "aar")
39-
to.attribute(unpackedAar, true).attribute(artifactType, "jar")
40-
}
18+
configureAarUnpacking()
4119

4220
compileOnly("com.google.android:android:${version("android")}")
4321
compileOnly("androidx.annotation:annotation:${version("androidx_annotation")}")

0 commit comments

Comments
 (0)