Permalink
Browse files

Kotlin extensions for core and test now next to java code

This commit pulls down kotlin extensions for core and test into the
original java project instead of a separate project/artifact.
  • Loading branch information...
sdeleuze authored and simonbasle committed Jun 19, 2017
1 parent 1ce7848 commit 5140235171ddd84a83c761a6868aa55fa2036fbd
View
@@ -15,14 +15,16 @@
*/
buildscript {
ext.kotlinVersion = '1.1.2-5'
repositories {
maven { url "http://repo.spring.io/plugins-release" }
}
dependencies {
classpath 'org.springframework.build.gradle:propdeps-plugin:0.0.7',
'io.spring.gradle:spring-io-plugin:0.0.4.RELEASE',
'com.github.jengelman.gradle.plugins:shadow:1.2.0',
'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.11'
'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.11',
"org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
}
}
@@ -61,6 +63,7 @@ ext {
configure(subprojects) { p ->
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'jacoco'
apply plugin: 'propdeps'
apply plugin: 'osgi'
@@ -124,6 +127,14 @@ configure(subprojects) { p ->
targetCompatibility = 1.8
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
if (JavaVersion.current().isJava8Compatible()) {
compileTestJava.options.compilerArgs += "-parameters"
p.tasks.withType(Javadoc) {
@@ -190,6 +201,8 @@ project('reactor-core') {
//Optional Logging Operator
optional "org.slf4j:slf4j-api:$slf4jVersion"
optional("org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}")
//Optional JDK 9 Converter
jsr166backport "io.projectreactor:jsr166:1.0.0.RELEASE"
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2011-2017 Pivotal Software Inc, All Rights Reserved.
*
* 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 reactor.core.publisher;
import java.util.function.Function;
import org.reactivestreams.Publisher;
/**
* Utilities to avoid vararg array copying overhead when relaying vararg parameters
* to underlying Java methods from their corresponding Kotlin functions.
* <p>
* When <a href="https://youtrack.jetbrains.com/issue/KT-17043">this</a> issue is
* resolved, uses of these bridge methods can be removed.
*
* @author DoHyung Kim
* @since 3.1
*/
class MonoBridges {
static Mono<Void> when(Publisher<Void>[] sources) {
return Mono.when(sources);
}
static <R> Mono<R> when(Function<? super Object[], ? extends R> combinator, Mono<?>[] monos) {
return Mono.when(combinator, monos);
}
private MonoBridges() {
// Not to be instantiated
}
}
@@ -0,0 +1,185 @@
/*
* Copyright (c) 2011-2017 Pivotal Software Inc, All Rights Reserved.
*
* 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 reactor.core.publisher
import org.reactivestreams.Publisher
import java.util.stream.Stream
import kotlin.reflect.KClass
/**
* Extension for transforming an [Iterator] to a [Flux].
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T> Iterator<T>.toFlux(): Flux<T> = toIterable().toFlux()
/**
* Extension for transforming an [Iterable] to a [Flux].
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T> Iterable<T>.toFlux(): Flux<T> = Flux.fromIterable(this)
/**
* Extension for transforming a [Sequence] to a [Flux].
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T> Sequence<T>.toFlux(): Flux<T> = Flux.fromIterable(object : Iterable<T> {
override fun iterator(): Iterator<T> = this@toFlux.iterator()
})
/**
* Extension for transforming a [Stream] to a [Flux].
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T> Stream<T>.toFlux(): Flux<T> = Flux.fromStream(this)
/**
* Extension for transforming a [BooleanArray] to a [Flux].
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun BooleanArray.toFlux(): Flux<Boolean> = this.toList().toFlux()
/**
* Extension for transforming a [ByteArray] to a [Flux].
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun ByteArray.toFlux(): Flux<Byte> = this.toList().toFlux()
/**
* Extension for transforming a [ShortArray] to a [Flux].
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun ShortArray.toFlux(): Flux<Short> = this.toList().toFlux()
/**
* Extension for transforming a [IntArray] to a [Flux].
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun IntArray.toFlux(): Flux<Int> = this.toList().toFlux()
/**
* Extension for transforming a [LongArray] to a [Flux].
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun LongArray.toFlux(): Flux<Long> = this.toList().toFlux()
/**
* Extension for transforming a [FloatArray] to a [Flux].
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun FloatArray.toFlux(): Flux<Float> = this.toList().toFlux()
/**
* Extension for transforming a [DoubleArray] to a [Flux].
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun DoubleArray.toFlux(): Flux<Double> = this.toList().toFlux()
/**
* Extension for transforming an [Array] to a [Flux].
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T> Array<out T>.toFlux(): Flux<T> = Flux.fromArray(this)
private fun <T> Iterator<T>.toIterable() = object : Iterable<T> {
override fun iterator(): Iterator<T> = this@toIterable
}
/**
* Extension for transforming an exception to a [Flux] that completes with the specified error.
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T> Throwable.toFlux(): Flux<T> = Flux.error(this)
/**
* Extension for [Flux.cast] providing a `cast<Foo>()` variant.
*
* @author Sebastien Deleuze
* @since 3.1
*/
inline fun <reified T : Any> Flux<*>.cast(): Flux<T> = cast(T::class.java)
/**
* Extension for [Flux.doOnError] providing a [KClass] based variant.
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T, E : Throwable> Flux<T>.doOnError(exceptionType: KClass<E>, onError: (E) -> Unit): Flux<T> =
doOnError(exceptionType.java, { onError(it) })
/**
* Extension for [Flux.onErrorMap] providing a [KClass] based variant.
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T, E : Throwable> Flux<T>.onErrorMap(exceptionType: KClass<E>, mapper: (E) -> Throwable): Flux<T> =
onErrorMap(exceptionType.java, { mapper(it) })
/**
* Extension for [Flux.ofType] providing a `ofType<Foo>()` variant.
*
* @author Sebastien Deleuze
* @since 3.1
*/
inline fun <reified T : Any> Flux<*>.ofType(): Flux<T> = ofType(T::class.java)
/**
* Extension for [Flux.onErrorResume] providing a [KClass] based variant.
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T : Any, E : Throwable> Flux<T>.onErrorResume(exceptionType: KClass<E>, fallback: (E) -> Publisher<T>): Flux<T> =
onErrorResume(exceptionType.java, { fallback(it) })
/**
* Extension for [Flux.onErrorReturn] providing a [KClass] based variant.
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T : Any, E : Throwable> Flux<T>.onErrorReturn(exceptionType: KClass<E>, value: T): Flux<T> =
onErrorReturn(exceptionType.java, value)
@@ -0,0 +1,106 @@
/*
* Copyright (c) 2011-2017 Pivotal Software Inc, All Rights Reserved.
*
* 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 reactor.core.publisher
import java.util.concurrent.Callable
import java.util.concurrent.CompletableFuture
import kotlin.reflect.KClass
/**
* Extension for transforming an object to a [Mono].
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T> T.toMono(): Mono<T> = Mono.just(this)
/**
* Extension for transforming an [CompletableFuture] to a [Mono].
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T> CompletableFuture<T>.toMono(): Mono<T> = Mono.fromFuture(this)
/**
* Extension for transforming an [Callable] to a [Mono].
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T> Callable<T>.toMono(): Mono<T> = Mono.fromCallable(this::call)
/**
* Extension for transforming an exception to a [Mono] that completes with the specified error.
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T> Throwable.toMono(): Mono<T> = Mono.error(this)
/**
* Extension for [Mono.cast] providing a `cast<Foo>()` variant.
*
* @author Sebastien
* @since 3.1
*/
inline fun <reified T : Any> Mono<*>.cast(): Mono<T> = cast(T::class.java)
/**
* Extension for [Mono.doOnError] providing a [KClass] based variant.
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T, E : Throwable> Mono<T>.doOnError(exceptionType: KClass<E>, onError: (E) -> Unit): Mono<T> =
doOnError(exceptionType.java, { onError(it) })
/**
* Extension for [Mono.onErrorMap] providing a [KClass] based variant.
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T, E : Throwable> Mono<T>.onErrorMap(exceptionType: KClass<E>, mapper: (E) -> Throwable): Mono<T> =
onErrorMap(exceptionType.java, { mapper(it) })
/**
* Extension for [Mono.ofType] providing a `ofType<Foo>()` variant.
*
* @author Sebastien Deleuze
* @since 3.1
*/
inline fun <reified T : Any> Mono<*>.ofType(): Mono<T> = ofType(T::class.java)
/**
* Extension for [Mono.onErrorResume] providing a [KClass] based variant.
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T : Any, E : Throwable> Mono<T>.onErrorResume(exceptionType: KClass<E>, fallback: (E) -> Mono<T>): Mono<T> =
onErrorResume(exceptionType.java, { fallback(it) })
/**
* Extension for [Mono.onErrorReturn] providing a [KClass] based variant.
*
* @author Sebastien Deleuze
* @since 3.1
*/
fun <T : Any, E : Throwable> Mono<T>.onErrorReturn(exceptionType: KClass<E>, value: T): Mono<T> =
onErrorReturn(exceptionType.java, value)
Oops, something went wrong.

0 comments on commit 5140235

Please sign in to comment.