Skip to content

Commit 72fc79d

Browse files
authored
Fix Groovy DSL for new splitter style (#8669)
* Fix Groovy DSL for new splitter style * Introduce a new `GroovyIntegrationFlowDefinition.splitWith()` to avoid clashing with existing method * Deprecate all other `split()` variants, but left one without arguments for a default splitting options * Fix doc for new splitter style * * Fix tab indentations in `groovy-dsl.adoc`
1 parent 34f901f commit 72fc79d

File tree

5 files changed

+83
-11
lines changed

5 files changed

+83
-11
lines changed

spring-integration-groovy/src/main/groovy/org/springframework/integration/groovy/dsl/GroovyIntegrationFlowDefinition.groovy

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import org.springframework.integration.dsl.ResequencerSpec
4747
import org.springframework.integration.dsl.RouterSpec
4848
import org.springframework.integration.dsl.ScatterGatherSpec
4949
import org.springframework.integration.dsl.SplitterEndpointSpec
50+
import org.springframework.integration.dsl.SplitterSpec
5051
import org.springframework.integration.dsl.TransformerEndpointSpec
5152
import org.springframework.integration.dsl.WireTapSpec
5253
import org.springframework.integration.filter.MethodInvokingSelector
@@ -710,18 +711,47 @@ class GroovyIntegrationFlowDefinition {
710711
this
711712
}
712713

714+
/**
715+
* Populate the {@link DefaultMessageSplitter} with default options to the current integration flow position.
716+
*/
717+
GroovyIntegrationFlowDefinition split() {
718+
this.delegate.split()
719+
this
720+
}
721+
713722
/**
714723
* Populate the {@link DefaultMessageSplitter} with provided options
715724
* to the current integration flow position.
716725
* Used with a Closure expression (optional).
717726
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
718727
* and for {@link DefaultMessageSplitter}.
728+
* @since 6.2
729+
* @see SplitterSpec
730+
*/
731+
GroovyIntegrationFlowDefinition splitWith(
732+
@DelegatesTo(value = SplitterSpec, strategy = Closure.DELEGATE_FIRST)
733+
@ClosureParams(value = SimpleType.class, options = 'org.springframework.integration.dsl.SplitterSpec')
734+
Closure<?> splitConfigurer) {
735+
736+
this.delegate.splitWith createConfigurerIfAny(splitConfigurer)
737+
this
738+
}
739+
740+
/**
741+
* Populate the {@link DefaultMessageSplitter} with provided options
742+
* to the current integration flow position.
743+
* Used with a Closure expression.
744+
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
745+
* and for {@link DefaultMessageSplitter}.
746+
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
719747
* @see SplitterEndpointSpec
720748
*/
749+
@Deprecated(since = '6.2', forRemoval = true)
750+
@SuppressWarnings(['removal', 'deprecation'])
721751
GroovyIntegrationFlowDefinition split(
722752
@DelegatesTo(value = SplitterEndpointSpec<DefaultMessageSplitter>, strategy = Closure.DELEGATE_FIRST)
723753
@ClosureParams(value = SimpleType.class, options = 'org.springframework.integration.dsl.SplitterEndpointSpec')
724-
Closure<?> endpointConfigurer = null) {
754+
Closure<?> endpointConfigurer) {
725755

726756
this.delegate.split createConfigurerIfAny(endpointConfigurer)
727757
this
@@ -733,7 +763,10 @@ class GroovyIntegrationFlowDefinition {
733763
* @param expression the splitter SpEL expression.
734764
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
735765
* and for {@link ExpressionEvaluatingSplitter}.
766+
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
736767
*/
768+
@Deprecated(since = '6.2', forRemoval = true)
769+
@SuppressWarnings(['removal', 'deprecation'])
737770
GroovyIntegrationFlowDefinition split(
738771
String expression,
739772
@DelegatesTo(value = SplitterEndpointSpec<ExpressionEvaluatingSplitter>, strategy = Closure.DELEGATE_FIRST)
@@ -752,7 +785,10 @@ class GroovyIntegrationFlowDefinition {
752785
* @param methodName the method to invoke.
753786
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
754787
* and for {@link MethodInvokingSplitter}.
788+
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
755789
*/
790+
@Deprecated(since = '6.2', forRemoval = true)
791+
@SuppressWarnings(['removal', 'deprecation'])
756792
GroovyIntegrationFlowDefinition split(
757793
Object service, String methodName = null,
758794
@DelegatesTo(value = SplitterEndpointSpec<MethodInvokingSplitter>, strategy = Closure.DELEGATE_FIRST)
@@ -772,7 +808,10 @@ class GroovyIntegrationFlowDefinition {
772808
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
773809
* and for {@link MethodInvokingSplitter}.
774810
* @see org.springframework.integration.dsl.SplitterEndpointSpec
811+
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
775812
*/
813+
@Deprecated(since = '6.2', forRemoval = true)
814+
@SuppressWarnings(['removal', 'deprecation'])
776815
GroovyIntegrationFlowDefinition split(
777816
String beanName, String methodName,
778817
@DelegatesTo(value = SplitterEndpointSpec<MethodInvokingSplitter>, strategy = Closure.DELEGATE_FIRST)
@@ -791,7 +830,10 @@ class GroovyIntegrationFlowDefinition {
791830
* @param messageProcessorSpec the splitter {@link MessageProcessorSpec}.
792831
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options
793832
* and for {@link MethodInvokingSplitter}.
833+
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
794834
*/
835+
@Deprecated(since = '6.2', forRemoval = true)
836+
@SuppressWarnings(['removal', 'deprecation'])
795837
GroovyIntegrationFlowDefinition split(
796838
MessageProcessorSpec<?> messageProcessorSpec,
797839
@DelegatesTo(value = SplitterEndpointSpec<MethodInvokingSplitter>, strategy = Closure.DELEGATE_FIRST)
@@ -811,8 +853,11 @@ class GroovyIntegrationFlowDefinition {
811853
* Conversion to this type will be attempted, if necessary.
812854
* @param splitter the splitter {@link Function}.
813855
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
814-
* @param < P > the payload type or {@code Message.class}.
856+
* @param <P> the payload type or {@code Message.class}.
857+
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
815858
*/
859+
@Deprecated(since = '6.2', forRemoval = true)
860+
@SuppressWarnings(['removal', 'deprecation'])
816861
<P> GroovyIntegrationFlowDefinition split(
817862
Class<P> expectedType, Function<P, ?> splitter,
818863
@DelegatesTo(value = SplitterEndpointSpec<MethodInvokingSplitter>, strategy = Closure.DELEGATE_FIRST)
@@ -830,9 +875,12 @@ class GroovyIntegrationFlowDefinition {
830875
* flow position.
831876
* @param splitterMessageHandlerSpec the {@link MessageHandlerSpec} to populate.
832877
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
833-
* @param < S > the {@link AbstractMessageSplitter}
878+
* @param <S> the {@link AbstractMessageSplitter}
879+
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
834880
* @see org.springframework.integration.dsl.SplitterEndpointSpec
835881
*/
882+
@Deprecated(since = '6.2', forRemoval = true)
883+
@SuppressWarnings(['removal', 'deprecation'])
836884
<S extends AbstractMessageSplitter> GroovyIntegrationFlowDefinition split(
837885
MessageHandlerSpec<?, S> splitterMessageHandlerSpec,
838886
@DelegatesTo(value = SplitterEndpointSpec<S>, strategy = Closure.DELEGATE_FIRST)
@@ -848,9 +896,12 @@ class GroovyIntegrationFlowDefinition {
848896
* flow position.
849897
* @param splitter the {@link AbstractMessageSplitter} to populate.
850898
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
851-
* @param < S > the {@link AbstractMessageSplitter}
899+
* @param <S> the {@link AbstractMessageSplitter}
900+
* @deprecated since 6.2 in favor of {@link #splitWith(groovy.lang.Closure)}
852901
* @see org.springframework.integration.dsl.SplitterEndpointSpec
853902
*/
903+
@Deprecated(since = '6.2', forRemoval = true)
904+
@SuppressWarnings(['removal', 'deprecation'])
854905
<S extends AbstractMessageSplitter> GroovyIntegrationFlowDefinition split(
855906
S splitter,
856907
@DelegatesTo(value = SplitterEndpointSpec<S>, strategy = Closure.DELEGATE_FIRST)

spring-integration-groovy/src/test/groovy/org/springframework/integration/groovy/dsl/test/GroovyDslTests.groovy

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,15 @@ class GroovyDslTests {
269269
transform {
270270
transformer { it.toUpperCase() }
271271
}
272-
split Message<?>, { it.payload }
273-
split Object, { it }, { id 'splitterEndpoint' }
272+
splitWith {
273+
expectedType Message<?>
274+
function { it.payload }
275+
}
276+
splitWith {
277+
expectedType Object
278+
id 'splitterEndpoint'
279+
function { it }
280+
}
274281
resequence()
275282
aggregate {
276283
id 'aggregator'

src/reference/asciidoc/groovy-dsl.adoc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,15 @@ functionFlow() {
8989
transformer { it.toUpperCase() }
9090
expectedType String
9191
}
92-
split Message<?>, { it.payload }
93-
split Object, { it }, { id 'splitterEndpoint' }
92+
splitWith {
93+
expectedType Message<?>
94+
function { it.payload }
95+
}
96+
splitWith {
97+
expectedType Object
98+
id 'splitterEndpoint'
99+
function { it }
100+
}
94101
resequence()
95102
aggregate {
96103
id 'aggregator'

src/reference/asciidoc/splitter.adoc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ fun someFlow() =
9797
@Bean
9898
someFlow() {
9999
integrationFlow {
100-
split Message<?>, { it.payload }
100+
splitWith {
101+
expectedType Message<?>
102+
function { it.payload }
103+
}
101104
}
102105
}
103106
----

src/reference/asciidoc/zip.adoc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,12 @@ fun unzipFlow(executor: Executor) =
229229
unzipFlow(Executor executor) {
230230
integrationFlow 'unzipChannel',
231231
{
232-
transform new UnZipTransformer()
233-
split new UnZipResultSplitter()
232+
transformWith {
233+
ref new UnZipTransformer()
234+
}
235+
splitWith {
236+
ref new UnZipResultSplitter()
237+
}
234238
channel { executor 'entriesChannel', executor }
235239
}
236240
}

0 commit comments

Comments
 (0)