Scripting: implement support for user-defined execution wrapper

This commit is contained in:
Ilya Chernikov
2022-05-13 17:16:43 +02:00
committed by teamcity
parent abdc2cf85e
commit 6784cb63aa
3 changed files with 52 additions and 2 deletions
@@ -96,6 +96,24 @@ val ScriptEvaluationConfigurationKeys.hostConfiguration by PropertiesCollection.
*/
val ScriptEvaluationConfigurationKeys.refineConfigurationBeforeEvaluate by PropertiesCollection.key<List<RefineEvaluationConfigurationData>>(isTransient = true)
interface ScriptExecutionWrapper<T> {
fun invoke(block: () -> T): T
}
/**
* An optional user-defined wrapper which is called with the code that actually executes script body
*/
val ScriptEvaluationConfigurationKeys.scriptExecutionWrapper by PropertiesCollection.key<ScriptExecutionWrapper<*>>(isTransient = true)
/**
* A helper to enable passing lambda directly to the scriptExecutionWrapper "keyword"
*/
fun <T> ScriptEvaluationConfiguration.Builder.scriptExecutionWrapper(wrapper: (() -> T) -> T) {
ScriptEvaluationConfiguration.scriptExecutionWrapper.put(object : ScriptExecutionWrapper<T> {
override fun invoke(block: () -> T): T = wrapper(block)
})
}
/**
* A helper to enable scriptsInstancesSharingMap with default implementation
*/