Browse Source

Upgrade to Coroutines 1.5.0

This commit upgrades to Coroutines 1.5.0 while retaining
Coroutines 1.4.x compatibility.

Closes gh-26897
pull/26951/head
Sébastien Deleuze 5 years ago
parent
commit
3dba3691a7
  1. 4
      build.gradle
  2. 9
      spring-core/kotlin-coroutines/src/main/kotlin/org/springframework/core/CoroutinesUtils.kt
  3. 4
      spring-messaging/src/main/kotlin/org/springframework/messaging/rsocket/RSocketRequesterExtensions.kt
  4. 3
      spring-r2dbc/src/main/kotlin/org/springframework/r2dbc/core/DatabaseClientExtensions.kt
  5. 6
      spring-r2dbc/src/main/kotlin/org/springframework/r2dbc/core/RowsFetchSpecExtensions.kt
  6. 4
      spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java
  7. 4
      spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/ClientResponseExtensions.kt
  8. 4
      spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/WebClientExtensions.kt
  9. 5
      spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensions.kt

4
build.gradle

@ -34,7 +34,7 @@ configure(allprojects) { project -> @@ -34,7 +34,7 @@ configure(allprojects) { project ->
mavenBom "io.rsocket:rsocket-bom:1.1.0"
mavenBom "org.eclipse.jetty:jetty-bom:9.4.40.v20210413"
mavenBom "org.jetbrains.kotlin:kotlin-bom:1.5.0"
mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.4.3"
mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.5.0"
mavenBom "org.jetbrains.kotlinx:kotlinx-serialization-bom:1.2.0"
mavenBom "org.junit:junit-bom:5.7.2"
}
@ -316,7 +316,7 @@ configure([rootProject] + javaProjects) { project -> @@ -316,7 +316,7 @@ configure([rootProject] + javaProjects) { project ->
kotlinOptions {
languageVersion = "1.3"
apiVersion = "1.3"
freeCompilerArgs = ["-Xjsr305=strict", "-Xsuppress-version-warnings"]
freeCompilerArgs = ["-Xjsr305=strict", "-Xsuppress-version-warnings", "-Xopt-in=kotlin.RequiresOptIn"]
allWarningsAsErrors = true
}
}

9
spring-core/kotlin-coroutines/src/main/kotlin/org/springframework/core/CoroutinesUtils.kt

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,10 +17,7 @@ @@ -17,10 +17,7 @@
@file:JvmName("CoroutinesUtils")
package org.springframework.core
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.reactive.awaitSingleOrNull
import kotlinx.coroutines.reactor.asFlux
@ -48,6 +45,8 @@ internal fun <T: Any> deferredToMono(source: Deferred<T>) = @@ -48,6 +45,8 @@ internal fun <T: Any> deferredToMono(source: Deferred<T>) =
* @author Sebastien Deleuze
* @since 5.2
*/
@Suppress("DEPRECATION")
@OptIn(DelicateCoroutinesApi::class)
internal fun <T: Any> monoToDeferred(source: Mono<T>) =
GlobalScope.async(Dispatchers.Unconfined) { source.awaitSingleOrNull() }

4
spring-messaging/src/main/kotlin/org/springframework/messaging/rsocket/RSocketRequesterExtensions.kt

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -102,6 +102,7 @@ inline fun <reified T : Any> RSocketRequester.RequestSpec.dataWithType(flow: Flo @@ -102,6 +102,7 @@ inline fun <reified T : Any> RSocketRequester.RequestSpec.dataWithType(flow: Flo
* @author Sebastien Deleuze
* @since 5.2
*/
@Suppress("DEPRECATION")
suspend fun RSocketRequester.RetrieveSpec.sendAndAwait() {
send().awaitSingleOrNull()
}
@ -121,6 +122,7 @@ suspend inline fun <reified T : Any> RSocketRequester.RetrieveSpec.retrieveAndAw @@ -121,6 +122,7 @@ suspend inline fun <reified T : Any> RSocketRequester.RetrieveSpec.retrieveAndAw
* @author Sebastien Deleuze
* @since 5.2.1
*/
@Suppress("DEPRECATION")
suspend inline fun <reified T : Any> RSocketRequester.RetrieveSpec.retrieveAndAwaitOrNull(): T? =
retrieveMono(object : ParameterizedTypeReference<T>() {}).awaitSingleOrNull()

3
spring-r2dbc/src/main/kotlin/org/springframework/r2dbc/core/DatabaseClientExtensions.kt

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -23,6 +23,7 @@ import kotlinx.coroutines.reactive.awaitSingleOrNull @@ -23,6 +23,7 @@ import kotlinx.coroutines.reactive.awaitSingleOrNull
*
* @author Sebastien Deleuze
*/
@Suppress("DEPRECATION")
suspend fun DatabaseClient.GenericExecuteSpec.await() {
then().awaitSingleOrNull()
}

6
spring-r2dbc/src/main/kotlin/org/springframework/r2dbc/core/RowsFetchSpecExtensions.kt

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,6 +25,7 @@ import org.springframework.dao.EmptyResultDataAccessException @@ -25,6 +25,7 @@ import org.springframework.dao.EmptyResultDataAccessException
*
* @author Sebastien Deleuze
*/
@Suppress("DEPRECATION")
suspend fun <T> RowsFetchSpec<T>.awaitOne(): T {
return one().awaitSingleOrNull() ?: throw EmptyResultDataAccessException(1)
}
@ -34,6 +35,7 @@ suspend fun <T> RowsFetchSpec<T>.awaitOne(): T { @@ -34,6 +35,7 @@ suspend fun <T> RowsFetchSpec<T>.awaitOne(): T {
*
* @author Sebastien Deleuze
*/
@Suppress("DEPRECATION")
suspend fun <T> RowsFetchSpec<T>.awaitOneOrNull(): T? =
one().awaitSingleOrNull()
@ -42,6 +44,7 @@ suspend fun <T> RowsFetchSpec<T>.awaitOneOrNull(): T? = @@ -42,6 +44,7 @@ suspend fun <T> RowsFetchSpec<T>.awaitOneOrNull(): T? =
*
* @author Sebastien Deleuze
*/
@Suppress("DEPRECATION")
suspend fun <T> RowsFetchSpec<T>.awaitSingle(): T {
return first().awaitSingleOrNull() ?: throw EmptyResultDataAccessException(1)
}
@ -51,6 +54,7 @@ suspend fun <T> RowsFetchSpec<T>.awaitSingle(): T { @@ -51,6 +54,7 @@ suspend fun <T> RowsFetchSpec<T>.awaitSingle(): T {
*
* @author Sebastien Deleuze
*/
@Suppress("DEPRECATION")
suspend fun <T> RowsFetchSpec<T>.awaitSingleOrNull(): T? =
first().awaitSingleOrNull()

4
spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -878,7 +878,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init @@ -878,7 +878,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
return ReactiveFlowKt.asFlow(publisher);
}
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "deprecation"})
@Nullable
private static Object awaitSingleOrNull(Publisher<?> publisher, Object continuation) {
return AwaitKt.awaitSingleOrNull(publisher, (Continuation<Object>) continuation);

4
spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/ClientResponseExtensions.kt

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -114,6 +114,7 @@ suspend fun <T : Any> ClientResponse.awaitBody(clazz: KClass<T>): T = @@ -114,6 +114,7 @@ suspend fun <T : Any> ClientResponse.awaitBody(clazz: KClass<T>): T =
* @author Sebastien Deleuze
* @since 5.2
*/
@Suppress("DEPRECATION")
suspend inline fun <reified T : Any> ClientResponse.awaitBodyOrNull(): T? =
bodyToMono<T>().awaitSingleOrNull()
@ -124,6 +125,7 @@ suspend inline fun <reified T : Any> ClientResponse.awaitBodyOrNull(): T? = @@ -124,6 +125,7 @@ suspend inline fun <reified T : Any> ClientResponse.awaitBodyOrNull(): T? =
* @author Igor Manushin
* @since 5.3
*/
@Suppress("DEPRECATION")
suspend fun <T : Any> ClientResponse.awaitBodyOrNull(clazz: KClass<T>): T? =
bodyToMono(clazz.java).awaitSingleOrNull()

4
spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/WebClientExtensions.kt

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,7 +20,6 @@ import kotlinx.coroutines.Dispatchers @@ -20,7 +20,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.reactive.asFlow
import kotlinx.coroutines.reactive.awaitSingle
import kotlinx.coroutines.reactive.awaitSingle
import kotlinx.coroutines.reactive.awaitSingleOrNull
import kotlinx.coroutines.reactor.asFlux
import kotlinx.coroutines.reactor.mono
@ -150,6 +149,7 @@ suspend inline fun <reified T : Any> WebClient.ResponseSpec.awaitBody() : T = @@ -150,6 +149,7 @@ suspend inline fun <reified T : Any> WebClient.ResponseSpec.awaitBody() : T =
* @author Valentin Shakhov
* @since 5.3.6
*/
@Suppress("DEPRECATION")
suspend inline fun <reified T : Any> WebClient.ResponseSpec.awaitBodyOrNull() : T? =
when (T::class) {
Unit::class -> awaitBodilessEntity().let { Unit as T? }

5
spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensions.kt

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -98,6 +98,7 @@ suspend fun <T : Any> ServerRequest.awaitBody(clazz: KClass<T>): T = @@ -98,6 +98,7 @@ suspend fun <T : Any> ServerRequest.awaitBody(clazz: KClass<T>): T =
* @author Sebastien Deleuze
* @since 5.2
*/
@Suppress("DEPRECATION")
suspend inline fun <reified T : Any> ServerRequest.awaitBodyOrNull(): T? =
bodyToMono<T>().awaitSingleOrNull()
@ -108,6 +109,7 @@ suspend inline fun <reified T : Any> ServerRequest.awaitBodyOrNull(): T? = @@ -108,6 +109,7 @@ suspend inline fun <reified T : Any> ServerRequest.awaitBodyOrNull(): T? =
* @author Igor Manushin
* @since 5.3
*/
@Suppress("DEPRECATION")
suspend fun <T : Any> ServerRequest.awaitBodyOrNull(clazz: KClass<T>): T? =
bodyToMono(clazz.java).awaitSingleOrNull()
@ -135,6 +137,7 @@ suspend fun ServerRequest.awaitMultipartData(): MultiValueMap<String, Part> = @@ -135,6 +137,7 @@ suspend fun ServerRequest.awaitMultipartData(): MultiValueMap<String, Part> =
* @author Sebastien Deleuze
* @since 5.2
*/
@Suppress("DEPRECATION")
suspend fun ServerRequest.awaitPrincipal(): Principal? =
principal().awaitSingleOrNull()

Loading…
Cancel
Save