Add support for Kotlin JSR223 scripts (#2898)
* Add support for Kotlin JSR223 scripts * Add required Kotlin dependencies into the `spring-integration-scripting` module * Introduce `KotlinScriptExecutor` to interact with the `KotlinJsr223JvmLocalScriptEngineFactory` directly since there is no `META-INF/services/javax.script.ScriptEngineFactory` file in the Kotlin * Also set an `idea.use.native.fs.for.win` system property to `false` in this class to disable check for native support on Windows. (Might be removed in future Kotlin versions) * Move `ScriptParser.getLanguageFromFileExtension()` logic into the `ScriptExecutorFactory.deriveLanguageFromFileExtension()` since the same one must be applied in the `DslScriptExecutingMessageProcessor`, too. * Modify tests to reflect Kotlin support * Fix some test scripts to their official extensions * * Add JavaDocs * Polishing according Sonar objections
This commit is contained in:
committed by
Gary Russell
parent
9cc0cbe3bd
commit
7dff1d5416
@@ -2,7 +2,7 @@
|
||||
=== Scripting Support
|
||||
|
||||
Spring Integration 2.1 added support for the https://www.jcp.org/en/jsr/detail?id=223[JSR223 Scripting for Java specification], introduced in Java version 6.
|
||||
It lets you use scripts written in any supported language (including Ruby, JRuby, Javascript, and Groovy) to provide the logic for various integration components, similar to the way the Spring Expression Language (SpEL) is used in Spring Integration.
|
||||
It lets you use scripts written in any supported language (including Ruby, JRuby, Javascript, Groovy and Kotlin) to provide the logic for various integration components, similar to the way the Spring Expression Language (SpEL) is used in Spring Integration.
|
||||
For more information about JSR223, see the https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/prog_guide/api.html[documentation].
|
||||
|
||||
You need to include this dependency into your project:
|
||||
@@ -27,6 +27,19 @@ compile "org.springframework.integration:spring-integration-scripting:{project-v
|
||||
|
||||
In addition you need to add a script engine implementation, e.g. JRuby, Jython.
|
||||
|
||||
Starting with version 5.2, Spring Integration provides a Kotlin Jsr223 support.
|
||||
You need to add these dependencies into your project to make it working:
|
||||
|
||||
[source, groovy]
|
||||
----
|
||||
runtime 'org.jetbrains.kotlin:kotlin-script-util'
|
||||
runtime 'org.jetbrains.kotlin:kotlin-compiler-embeddable'
|
||||
runtime 'org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable'
|
||||
----
|
||||
====
|
||||
|
||||
The `KotlinScriptExecutor` is selected by the provided `kotlin` language indicator or script file comes with the `.kts` extension.
|
||||
|
||||
IMPORTANT: Note that this feature requires Java 6 or higher.
|
||||
|
||||
In order to use a JVM scripting language, a JSR223 implementation for that language must be included in your class path.
|
||||
@@ -52,7 +65,7 @@ The following pair of examples show sample configurations that create filters:
|
||||
[source,xml]
|
||||
----
|
||||
<int:filter input-channel="referencedScriptInput">
|
||||
<int-script:script lang="ruby" location="some/path/to/ruby/script/RubyFilterTests.rb"/>
|
||||
<int-script:script location="some/path/to/ruby/script/RubyFilterTests.rb"/>
|
||||
</int:filter>
|
||||
|
||||
<int:filter input-channel="inlineScriptInput">
|
||||
|
||||
@@ -19,6 +19,11 @@ See <<rate-limiter-advice>> for more information.
|
||||
The `CacheRequestHandlerAdvice` is now available for caching request results on handlers.
|
||||
See <<cache-advice>> for more information.
|
||||
|
||||
[[x5.2-kotlinScripts]]
|
||||
=== Kotlin Scripts Support
|
||||
|
||||
The JSR223 scripting module now includes a support for Kotlin scripts.
|
||||
See <<scripting>> for more information.
|
||||
|
||||
[[x5.2-general]]
|
||||
=== General Changes
|
||||
|
||||
Reference in New Issue
Block a user