Skip to content

Commit 30622b2

Browse files
committed
Improve Kotlin DSL
* Add missed factories, introduced recently into Java DSL * Add `@IntegrationDsl` - a Kotlin-specific `@DslMarker` annotation to mark classes (including Java) which are used in Kotlin DSL as a builder pattern. This way the scope of the builder is honored and IDE does not suggest functions from higher lambda for builder * Fix `element-list` reference for Dokka plugin configuration from the respective module
1 parent cb8787b commit 30622b2

File tree

6 files changed

+75
-41
lines changed

6 files changed

+75
-41
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ project('spring-integration-core') {
476476
classpath.from(sourceSets['main'].runtimeClasspath)
477477
externalDocumentationLink {
478478
url.set(new URL("https://docs.spring.io/spring-integration/docs/$version/api/"))
479-
packageListUrl.set(file("$buildDir/api/element-list").toURI().toURL())
479+
packageListUrl.set(file("$buildDir/docs/javadoc/element-list").toURI().toURL())
480480
}
481481
externalDocumentationLink {
482482
url.set(new URL('https://projectreactor.io/docs/core/release/api/'))

spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
*
117117
* @see org.springframework.integration.dsl.context.IntegrationFlowBeanPostProcessor
118118
*/
119+
@IntegrationDsl
119120
public abstract class BaseIntegrationFlowDefinition<B extends BaseIntegrationFlowDefinition<B>> {
120121

121122
private static final String UNCHECKED = "unchecked";

spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationComponentSpec.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@
3333
*
3434
* @since 5.0
3535
*/
36+
@IntegrationDsl
3637
public abstract class IntegrationComponentSpec<S extends IntegrationComponentSpec<S, T>, T>
3738
extends AbstractFactoryBean<T>
3839
implements SmartLifecycle {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.dsl
18+
19+
/**
20+
* The Kotlin [DslMarker] annotation for classes used in scope of DSL, including all the Java DSL classes.
21+
*
22+
* @author Artem Bilan
23+
*
24+
* @since 5.5.8
25+
*/
26+
@DslMarker
27+
annotation class IntegrationDsl

spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/IntegrationFlowDsl.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 the original author or authors.
2+
* Copyright 2020-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,11 +25,8 @@ import org.springframework.messaging.MessageChannel
2525
import java.util.function.Consumer
2626

2727
private fun buildIntegrationFlow(flowBuilder: IntegrationFlowBuilder,
28-
flow: (KotlinIntegrationFlowDefinition) -> Unit): IntegrationFlow {
29-
30-
flow(KotlinIntegrationFlowDefinition(flowBuilder))
31-
return flowBuilder.get()
32-
}
28+
flow: (KotlinIntegrationFlowDefinition) -> Unit) =
29+
KotlinIntegrationFlowDefinition(flowBuilder).apply(flow).delegate.get()
3330

3431
/**
3532
* Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlow] lambdas.
@@ -38,7 +35,7 @@ private fun buildIntegrationFlow(flowBuilder: IntegrationFlowBuilder,
3835
*/
3936
fun integrationFlow(flow: KotlinIntegrationFlowDefinition.() -> Unit) =
4037
IntegrationFlow {
41-
flow(KotlinIntegrationFlowDefinition(it))
38+
KotlinIntegrationFlowDefinition(it).flow()
4239
}
4340

4441
/**
@@ -52,7 +49,7 @@ inline fun <reified T> integrationFlow(
5249
flow: KotlinIntegrationFlowDefinition.() -> Unit): IntegrationFlow {
5350

5451
val flowBuilder = IntegrationFlows.from(T::class.java) { gateway(it) }
55-
flow(KotlinIntegrationFlowDefinition(flowBuilder))
52+
KotlinIntegrationFlowDefinition(flowBuilder).flow()
5653
return flowBuilder.get()
5754
}
5855

@@ -84,7 +81,7 @@ fun integrationFlow(channel: MessageChannel, flow: KotlinIntegrationFlowDefiniti
8481
fun integrationFlow(messageSource: MessageSource<*>,
8582
options: SourcePollingChannelAdapterSpec.() -> Unit = {},
8683
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
87-
buildIntegrationFlow(IntegrationFlows.from(messageSource, Consumer { options(it) }), flow)
84+
buildIntegrationFlow(IntegrationFlows.from(messageSource) { options(it) }, flow)
8885

8986
/**
9087
* Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] -
@@ -157,3 +154,13 @@ fun integrationFlow(producer: MessageProducerSupport,
157154
fun integrationFlow(producerSpec: MessageProducerSpec<*, *>,
158155
flow: KotlinIntegrationFlowDefinition.() -> Unit) =
159156
buildIntegrationFlow(IntegrationFlows.from(producerSpec), flow)
157+
158+
/**
159+
* Functional [IntegrationFlow] definition in Kotlin DSL for [IntegrationFlows.from] -
160+
* `IntegrationFlows.from(IntegrationFlow)` factory method.
161+
*
162+
* @author Artem Bilan
163+
*/
164+
fun integrationFlow(sourceFlow: IntegrationFlow, flow: KotlinIntegrationFlowDefinition.() -> Unit) =
165+
buildIntegrationFlow(IntegrationFlows.from(sourceFlow), flow)
166+

spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinIntegrationFlowDefinition.kt

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import java.util.function.Consumer
6767
*
6868
* @since 5.3
6969
*/
70+
@IntegrationDsl
7071
class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: IntegrationFlowDefinition<*>) {
7172

7273
/**
@@ -171,7 +172,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
171172
* at the current [IntegrationFlow] chain position.
172173
* The provided `messageChannelName` is used for the bean registration
173174
* ([org.springframework.integration.channel.DirectChannel]), if there is no such a bean
174-
* in the application context. Otherwise the existing [MessageChannel] bean is used
175+
* in the application context. Otherwise, the existing [MessageChannel] bean is used
175176
* to wire integration endpoints.
176177
*/
177178
fun channel(messageChannelName: String) {
@@ -297,7 +298,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
297298
fun transform(transformer: Transformer,
298299
endpointConfigurer: GenericEndpointSpec<MessageTransformingHandler>.() -> Unit = {}) {
299300

300-
this.delegate.transform(transformer, Consumer { endpointConfigurer(it) })
301+
this.delegate.transform(transformer) { endpointConfigurer(it) }
301302
}
302303

303304
/**
@@ -331,7 +332,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
331332
/**
332333
* Populate the [MessageTransformingHandler] instance for the
333334
* [org.springframework.integration.handler.MessageProcessor] from provided [MessageProcessorSpec].
334-
* In addition accept options for the integration endpoint using [GenericEndpointSpec].
335+
* In addition, accept options for the integration endpoint using [GenericEndpointSpec].
335336
*/
336337
fun transform(messageProcessorSpec: MessageProcessorSpec<*>,
337338
endpointConfigurer: GenericEndpointSpec<MessageTransformingHandler>.() -> Unit = {}) {
@@ -341,7 +342,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
341342

342343
/**
343344
* Populate a [MessageFilter] with [MessageSelector] for the provided SpEL expression.
344-
* In addition accept options for the integration endpoint using [KotlinFilterEndpointSpec]:
345+
* In addition, accept options for the integration endpoint using [KotlinFilterEndpointSpec]:
345346
*/
346347
fun filter(expression: String, filterConfigurer: KotlinFilterEndpointSpec.() -> Unit = {}) {
347348
this.delegate.filter(expression) { filterConfigurer(KotlinFilterEndpointSpec(it)) }
@@ -367,7 +368,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
367368
* Populate a [MessageFilter] with [MethodInvokingSelector]
368369
* for the [MessageProcessor] from
369370
* the provided [MessageProcessorSpec].
370-
* In addition accept options for the integration endpoint using [KotlinFilterEndpointSpec].
371+
* In addition, accept options for the integration endpoint using [KotlinFilterEndpointSpec].
371372
*/
372373
fun filter(messageProcessorSpec: MessageProcessorSpec<*>,
373374
filterConfigurer: KotlinFilterEndpointSpec.() -> Unit = {}) {
@@ -378,14 +379,13 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
378379

379380
/**
380381
* Populate a [MessageFilter] with the provided [MessageSelector].
381-
* In addition accept options for the integration endpoint using [KotlinFilterEndpointSpec].
382+
* In addition, accept options for the integration endpoint using [KotlinFilterEndpointSpec].
382383
* @since 5.3.1
383384
*/
384385
fun filter(messageSelector: MessageSelector,
385386
filterConfigurer: KotlinFilterEndpointSpec.() -> Unit = {}) {
386387

387-
this.delegate.filter(Message::class.java, messageSelector,
388-
Consumer { filterConfigurer(KotlinFilterEndpointSpec(it)) })
388+
this.delegate.filter(Message::class.java, messageSelector) { filterConfigurer(KotlinFilterEndpointSpec(it)) }
389389
}
390390

391391
/**
@@ -417,7 +417,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
417417
* Populate a [ServiceActivatingHandler] for the
418418
* [org.springframework.integration.handler.MethodInvokingMessageProcessor]
419419
* to invoke the `method` for provided `bean` at runtime.
420-
* In addition accept options for the integration endpoint using [GenericEndpointSpec].
420+
* In addition, accept options for the integration endpoint using [GenericEndpointSpec].
421421
*/
422422
fun handle(beanName: String, methodName: String?,
423423
endpointConfigurer: GenericEndpointSpec<ServiceActivatingHandler>.() -> Unit) {
@@ -429,7 +429,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
429429
* Populate a [ServiceActivatingHandler] for the
430430
* [org.springframework.integration.handler.MethodInvokingMessageProcessor]
431431
* to invoke the `method` for provided `bean` at runtime.
432-
* In addition accept options for the integration endpoint using [GenericEndpointSpec].
432+
* In addition, accept options for the integration endpoint using [GenericEndpointSpec].
433433
*/
434434
fun handle(service: Any, methodName: String? = null) {
435435
this.delegate.handle(service, methodName)
@@ -439,7 +439,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
439439
* Populate a [ServiceActivatingHandler] for the
440440
* [org.springframework.integration.handler.MethodInvokingMessageProcessor]
441441
* to invoke the `method` for provided `bean` at runtime.
442-
* In addition accept options for the integration endpoint using [GenericEndpointSpec].
442+
* In addition, accept options for the integration endpoint using [GenericEndpointSpec].
443443
*/
444444
fun handle(service: Any, methodName: String?,
445445
endpointConfigurer: GenericEndpointSpec<ServiceActivatingHandler>.() -> Unit) {
@@ -460,7 +460,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
460460
* Populate a [ServiceActivatingHandler] for the
461461
* [org.springframework.integration.handler.MethodInvokingMessageProcessor]
462462
* to invoke the provided [GenericHandler] at runtime.
463-
* In addition accept options for the integration endpoint using [GenericEndpointSpec].
463+
* In addition, accept options for the integration endpoint using [GenericEndpointSpec].
464464
*/
465465
inline fun <reified P> handle(
466466
crossinline handler: (P, MessageHeaders) -> Any,
@@ -471,7 +471,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
471471

472472
/**
473473
* Populate a [ServiceActivatingHandler] for the [MessageProcessor] from the provided [MessageProcessorSpec].
474-
* In addition accept options for the integration endpoint using [GenericEndpointSpec].
474+
* In addition, accept options for the integration endpoint using [GenericEndpointSpec].
475475
*/
476476
fun handle(messageProcessorSpec: MessageProcessorSpec<*>,
477477
endpointConfigurer: GenericEndpointSpec<ServiceActivatingHandler>.() -> Unit = {}) {
@@ -482,7 +482,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
482482
/**
483483
* Populate a [ServiceActivatingHandler] for the selected protocol specific
484484
* [MessageHandler] implementation from `Namespace Factory`:
485-
* In addition accept options for the integration endpoint using [GenericEndpointSpec].
485+
* In addition, accept options for the integration endpoint using [GenericEndpointSpec].
486486
*/
487487
fun <H : MessageHandler> handle(messageHandlerSpec: MessageHandlerSpec<*, H>,
488488
endpointConfigurer: GenericEndpointSpec<H>.() -> Unit = {}) {
@@ -501,7 +501,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
501501
/**
502502
* Populate a [ServiceActivatingHandler] for the provided
503503
* [MessageHandler] lambda.
504-
* In addition accept options for the integration endpoint using [GenericEndpointSpec].
504+
* In addition, accept options for the integration endpoint using [GenericEndpointSpec].
505505
*/
506506
fun handle(messageHandler: (Message<*>) -> Unit,
507507
endpointConfigurer: GenericEndpointSpec<MessageHandler>.() -> Unit) {
@@ -512,7 +512,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
512512
/**
513513
* Populate a [ServiceActivatingHandler] for the provided
514514
* [MessageHandler] implementation.
515-
* In addition accept options for the integration endpoint using [GenericEndpointSpec].
515+
* In addition, accept options for the integration endpoint using [GenericEndpointSpec].
516516
*/
517517
fun <H : MessageHandler> handle(messageHandler: H, endpointConfigurer: GenericEndpointSpec<H>.() -> Unit = {}) {
518518
this.delegate.handle(messageHandler, endpointConfigurer)
@@ -545,7 +545,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
545545
* Populate a [MessageTransformingHandler] for
546546
* a [org.springframework.integration.transformer.HeaderEnricher]
547547
* using header values from provided [MapBuilder].
548-
* In addition accept options for the integration endpoint using [GenericEndpointSpec].
548+
* In addition, accept options for the integration endpoint using [GenericEndpointSpec].
549549
*/
550550
fun enrichHeaders(headers: MapBuilder<*, String, Any>,
551551
endpointConfigurer: GenericEndpointSpec<MessageTransformingHandler>.() -> Unit = {}) {
@@ -603,7 +603,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
603603
/**
604604
* Populate the [MethodInvokingSplitter] to evaluate the provided
605605
* `method` of the `bean` at runtime.
606-
* In addition accept options for the integration endpoint using [KotlinSplitterEndpointSpec].
606+
* In addition, accept options for the integration endpoint using [KotlinSplitterEndpointSpec].
607607
*/
608608
fun split(service: Any, methodName: String?,
609609
splitterConfigurer: KotlinSplitterEndpointSpec<MethodInvokingSplitter>.() -> Unit) {
@@ -622,7 +622,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
622622
/**
623623
* Populate the [MethodInvokingSplitter] to evaluate the provided
624624
* `method` of the `bean` at runtime.
625-
* In addition accept options for the integration endpoint using [KotlinSplitterEndpointSpec].
625+
* In addition, accept options for the integration endpoint using [KotlinSplitterEndpointSpec].
626626
*/
627627
fun split(beanName: String, methodName: String?,
628628
splitterConfigurer: KotlinSplitterEndpointSpec<MethodInvokingSplitter>.() -> Unit) {
@@ -632,9 +632,8 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
632632

633633
/**
634634
* Populate the [MethodInvokingSplitter] to evaluate the
635-
* [MessageProcessor] at runtime
636-
* from provided [MessageProcessorSpec].
637-
* In addition accept options for the integration endpoint using [KotlinSplitterEndpointSpec].
635+
* [MessageProcessor] at runtime from provided [MessageProcessorSpec].
636+
* In addition, accept options for the integration endpoint using [KotlinSplitterEndpointSpec].
638637
*/
639638
fun split(messageProcessorSpec: MessageProcessorSpec<*>,
640639
splitterConfigurer: KotlinSplitterEndpointSpec<MethodInvokingSplitter>.() -> Unit = {}) {
@@ -681,7 +680,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
681680
/**
682681
* Populate the [MessageTransformingHandler] for the [ClaimCheckInTransformer]
683682
* with provided [MessageStore].
684-
* In addition accept options for the integration endpoint using [GenericEndpointSpec].
683+
* In addition, accept options for the integration endpoint using [GenericEndpointSpec].
685684
*/
686685
fun claimCheckIn(messageStore: MessageStore,
687686
endpointConfigurer: GenericEndpointSpec<MessageTransformingHandler>.() -> Unit = {}) {
@@ -700,7 +699,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
700699
/**
701700
* Populate the [MessageTransformingHandler] for the [ClaimCheckOutTransformer]
702701
* with provided [MessageStore] and `removeMessage` flag.
703-
* In addition accept options for the integration endpoint using [GenericEndpointSpec].
702+
* In addition, accept options for the integration endpoint using [GenericEndpointSpec].
704703
*/
705704
fun claimCheckOut(messageStore: MessageStore, removeMessage: Boolean,
706705
endpointConfigurer: GenericEndpointSpec<MessageTransformingHandler>.() -> Unit) {
@@ -712,7 +711,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
712711
* Populate the
713712
* [org.springframework.integration.aggregator.ResequencingMessageHandler] with
714713
* provided options from [ResequencerSpec].
715-
* In addition accept options for the integration endpoint using [GenericEndpointSpec].
714+
* In addition, accept options for the integration endpoint using [GenericEndpointSpec].
716715
*/
717716
fun resequence(resequencer: ResequencerSpec.() -> Unit = {}) {
718717
this.delegate.resequence(resequencer)
@@ -728,7 +727,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
728727

729728
/**
730729
* Populate the [AggregatingMessageHandler] with provided options from [AggregatorSpec].
731-
* In addition accept options for the integration endpoint using [GenericEndpointSpec].
730+
* In addition, accept options for the integration endpoint using [GenericEndpointSpec].
732731
*/
733732
fun aggregate(aggregator: AggregatorSpec.() -> Unit = {}) {
734733
this.delegate.aggregate(aggregator)
@@ -781,8 +780,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
781780
}
782781

783782
/**
784-
* Populate the [MethodInvokingRouter] for the
785-
* [MessageProcessor]
783+
* Populate the [MethodInvokingRouter] for the [MessageProcessor]
786784
* from the provided [MessageProcessorSpec] with default options.
787785
*/
788786
fun route(messageProcessorSpec: MessageProcessorSpec<*>,
@@ -810,7 +808,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
810808
/**
811809
* Populate the provided [AbstractMessageRouter] implementation to the
812810
* current integration flow position.
813-
* In addition accept options for the integration endpoint using [GenericEndpointSpec].
811+
* In addition, accept options for the integration endpoint using [GenericEndpointSpec].
814812
*/
815813
fun <R : AbstractMessageRouter?> route(router: R, endpointConfigurer: GenericEndpointSpec<R>.() -> Unit = {}) {
816814
this.delegate.route(router, endpointConfigurer)
@@ -929,7 +927,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ
929927
* the `org.springframework.integration.handler.LoggingHandler`
930928
* as a default logging category and SpEL expression to evaluate
931929
* logger message at runtime against the request [Message].
932-
* When this operator is used in the end of flow, it is treated
930+
* When this operator is used in the end of flow, it is treated
933931
* as one-way handler without any replies to continue.
934932
*/
935933
fun log(level: LoggingHandler.Level, logExpression: Expression) {

0 commit comments

Comments
 (0)