Skip to content

Commit

Permalink
Merge spring-integration-kotlin-dsl project
Browse files Browse the repository at this point in the history
* Migrate all the Kotlin tests to use new Kotlin DSL
* Upgrade to the latest Kotlin
* Generate KDocs
  • Loading branch information
artembilan committed Mar 5, 2020
1 parent f332a94 commit 8a38a5e
Show file tree
Hide file tree
Showing 7 changed files with 1,628 additions and 48 deletions.
50 changes: 47 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlinVersion = '1.3.61'
ext.kotlinVersion = '1.3.70'
repositories {
maven { url 'https://repo.spring.io/plugins-release' }
}
Expand All @@ -17,6 +17,7 @@ plugins {
id 'org.ajoberstar.grgit' version '4.0.1'
id "io.spring.dependency-management" version '1.0.9.RELEASE'
id 'com.jfrog.artifactory' version '4.13.0' apply false
id 'org.jetbrains.dokka' version '0.10.1'
}

if (System.getenv('TRAVIS') || System.getenv('bamboo_buildKey')) {
Expand Down Expand Up @@ -188,9 +189,14 @@ configure(javaProjects) { subproject ->
targetCompatibility = 1.8
}

compileKotlin {
kotlinOptions {
jvmTarget = '1.8'
allWarningsAsErrors = true
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = ['-Xjsr305=strict']
jvmTarget = '1.8'
}
}
Expand Down Expand Up @@ -414,10 +420,13 @@ project('spring-integration-core') {
optionalApi "com.esotericsoftware:kryo-shaded:$kryoShadedVersion"
optionalApi "io.micrometer:micrometer-core:$micrometerVersion"
optionalApi "io.github.resilience4j:resilience4j-ratelimiter:$resilience4jVersion"
optionalApi"org.apache.avro:avro:$avroVersion"
optionalApi "org.apache.avro:avro:$avroVersion"
optionalApi 'org.jetbrains.kotlin:kotlin-reflect'
optionalApi 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'

testImplementation ("org.aspectj:aspectjweaver:$aspectjVersion")
testImplementation ('com.fasterxml.jackson.datatype:jackson-datatype-jsr310')
testRuntime 'com.fasterxml.jackson.module:jackson-module-kotlin'
}
}

Expand Down Expand Up @@ -980,6 +989,38 @@ task api(type: Javadoc) {
})
}

dokka {
dependsOn api

outputFormat = 'html'
outputDirectory = "$buildDir/docs/kdoc"

configuration {
classpath = javaProjects.collect { project -> project.jar.outputs.files.getFiles() }.flatten()
classpath += files(javaProjects.collect { it.sourceSets.main.compileClasspath })
javaProjects.forEach { project ->
if(project.sourceSets.main.kotlin) {
sourceRoot {
path = project.sourceSets.main.kotlin.srcDirs.first()
}
}
}
moduleName = 'spring-integration'
externalDocumentationLink {
url = new URL("https://docs.spring.io/spring-integration/docs/$version/api/")
}
externalDocumentationLink {
url = new URL('https://docs.spring.io/spring-framework/docs/current/javadoc-api/')
}
externalDocumentationLink {
url = new URL('https://projectreactor.io/docs/core/release/api/')
}
externalDocumentationLink {
url = new URL('https://www.reactive-streams.org/reactive-streams-1.0.1-javadoc/')
}
}
}

task schemaZip(type: Zip) {
group = 'Distribution'
archiveClassifier = 'schema'
Expand Down Expand Up @@ -1038,6 +1079,9 @@ task docsZip(type: Zip, dependsOn: reference) {
rename 'index-single.pdf', 'spring-integration-reference.pdf'
into 'reference/pdf'
}
from (dokka) {
into "kdoc-api"
}
}

task distZip(type: Zip, dependsOn: [docsZip, schemaZip]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* https://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 org.springframework.integration.dsl

import org.reactivestreams.Publisher
import org.springframework.integration.core.MessageSource
import org.springframework.integration.endpoint.MessageProducerSupport
import org.springframework.integration.gateway.MessagingGatewaySupport
import org.springframework.messaging.Message
import org.springframework.messaging.MessageChannel
import java.util.function.Consumer

private fun buildIntegrationFlow(flowBuilder: IntegrationFlowBuilder,
flow: (KotlinIntegrationFlowDefinition) -> Unit): IntegrationFlow {

flow(KotlinIntegrationFlowDefinition(flowBuilder))
return flowBuilder.get()
}

/**
* Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlow] lambdas.
*
* @author Artem Bilan
*/
fun integrationFlow(flow: KotlinIntegrationFlowDefinition.() -> Unit) =
IntegrationFlow {
flow(KotlinIntegrationFlowDefinition(it))
}

/**
* Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] -
* `IntegrationFlows.from(Class<?>, Consumer<GatewayProxySpec>)` factory method.
*
* @author Artem Bilan
*/
inline fun <reified T> integrationFlow(
crossinline gateway: GatewayProxySpec.() -> Unit = {},
flow: KotlinIntegrationFlowDefinition.() -> Unit): IntegrationFlow {

val flowBuilder = IntegrationFlows.from(T::class.java) { gateway(it) }
flow(KotlinIntegrationFlowDefinition(flowBuilder))
return flowBuilder.get()
}

/**
* Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] -
* `IntegrationFlows.from(String, Boolean)` factory method.
*
* @author Artem Bilan
*/
fun integrationFlow(channelName: String, fixedSubscriber: Boolean = false,
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(channelName, fixedSubscriber), flow)

/**
* Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] -
* `IntegrationFlows.from(MessageChannel)` factory method.
*
* @author Artem Bilan
*/
fun integrationFlow(channel: MessageChannel, flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(channel), flow)

/**
* Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] -
* `IntegrationFlows.from(MessageSource<*>, Consumer<SourcePollingChannelAdapterSpec>)` factory method.
*
* @author Artem Bilan
*/
fun integrationFlow(messageSource: MessageSource<*>,
options: SourcePollingChannelAdapterSpec.() -> Unit = {},
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(messageSource, Consumer { options(it) }), flow)

/**
* Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] -
* `IntegrationFlows.from(MessageSourceSpec<*>, Consumer<SourcePollingChannelAdapterSpec>)` factory method.
*
* @author Artem Bilan
*/
fun integrationFlow(messageSource: MessageSourceSpec<*, out MessageSource<*>>,
options: SourcePollingChannelAdapterSpec.() -> Unit = {},
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(messageSource, options), flow)

/**
* Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] -
* `IntegrationFlows.from(Supplier<*>, Consumer<SourcePollingChannelAdapterSpec>)` factory method.
*
* @author Artem Bilan
*/
fun integrationFlow(source: () -> Any,
options: SourcePollingChannelAdapterSpec.() -> Unit = {},
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(source, options), flow)

/**
* Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] -
* `IntegrationFlows.from(Publisher<out Message<*>>)` factory method.
*
* @author Artem Bilan
*/
fun integrationFlow(publisher: Publisher<out Message<*>>,
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(publisher), flow)

/**
* Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] -
* `IntegrationFlows.from(MessagingGatewaySupport)` factory method.
*
* @author Artem Bilan
*/
fun integrationFlow(gateway: MessagingGatewaySupport,
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(gateway), flow)

/**
* Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] -
* `IntegrationFlows.from(MessagingGatewaySpec<*, *>)` factory method.
*
* @author Artem Bilan
*/
fun integrationFlow(gatewaySpec: MessagingGatewaySpec<*, *>,
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(gatewaySpec), flow)

/**
* Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] -
* `IntegrationFlows.from(MessageProducerSupport)` factory method.
*
* @author Artem Bilan
*/
fun integrationFlow(producer: MessageProducerSupport,
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(producer), flow)

/**
* Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] -
* `IntegrationFlows.from(MessageProducerSpec<*, *>)` factory method.
*
* @author Artem Bilan
*/
fun integrationFlow(producerSpec: MessageProducerSpec<*, *>,
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
buildIntegrationFlow(IntegrationFlows.from(producerSpec), flow)

0 comments on commit 8a38a5e

Please sign in to comment.