Package com.avoka.core.groovy.runtime
Class GroovyScriptRuntime
- java.lang.Object
-
- com.avoka.core.groovy.runtime.GroovyScriptRuntime
-
public class GroovyScriptRuntime extends Object
Provides Groovy Script execution utility methods.
-
-
Constructor Summary
Constructors Constructor Description GroovyScriptRuntime()Create a new GroovyScript runtime.GroovyScriptRuntime(ClassLoader classLoader)Create a new GroovyScript runtime with the given class loader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectexecuteScript(String script, Map<String,Object> parameters)Execute the provided Groovy Script content, binding the given parameters and returning the result object.intgetExcutionTimeout()booleanisCaptureOutput()Return true if the runtime will capture the script output for running in shell mode.booleanisSecureGroovyAPI()GroovyScriptRuntimesetBindable(IBindable bindable)Set an bindable object to bind to the Groovy script object before it is invoked.GroovyScriptRuntimesetCaptureOutput(boolean captureOutput)Specify whether the runtime should capture the script output for running in shell mode.GroovyScriptRuntimesetClassLoader(ClassLoader classLoader)Set the GroovyScript class loader.GroovyScriptRuntimesetExecutionTimeout(int timeout)Set the GroovyScript execution timeout in milliseconds, a value of 0 means the script will run indefinitely.GroovyScriptRuntimesetParseOnly(boolean parseOnly)GroovyScriptRuntimesetSecureGroovyAPI(boolean secureGroovyAPI)GroovyScriptRuntimesetSecurityContext(String securityContext)Set the security context of the class loader.GroovyScriptRuntimesetThreadListener(IGroovyThreadListener threadListener)StringvalidateScript(String script)Validates the provided Groovy script, and return a validation error message if errors are found.
-
-
-
Constructor Detail
-
GroovyScriptRuntime
public GroovyScriptRuntime()
Create a new GroovyScript runtime.- Since:
- 17.10.0
-
GroovyScriptRuntime
public GroovyScriptRuntime(ClassLoader classLoader)
Create a new GroovyScript runtime with the given class loader.- Parameters:
classLoader- the script class loader- Since:
- 4.2.0
-
-
Method Detail
-
executeScript
public Object executeScript(String script, Map<String,Object> parameters)
Execute the provided Groovy Script content, binding the given parameters and returning the result object.- Parameters:
script- the Groovy script content to executeparameters- the input parameter to bind into the script- Returns:
- the result the result from the executed Groovy script
-
validateScript
public String validateScript(String script)
Validates the provided Groovy script, and return a validation error message if errors are found.- Parameters:
script- the Groovy script (required)- Returns:
- null if the script validated successfully, an error message otherwise
-
setBindable
public GroovyScriptRuntime setBindable(IBindable bindable)
Set an bindable object to bind to the Groovy script object before it is invoked.- Parameters:
bindable- the object to bind to the Groovy script object to be invoked (optional)- Returns:
- the groovy script runtime
- Since:
- 17.10.0
-
isCaptureOutput
public boolean isCaptureOutput()
Return true if the runtime will capture the script output for running in shell mode.- Returns:
- true if the runtime will capture the script output for running in shell mode
- Since:
- 4.0.0
-
setCaptureOutput
public GroovyScriptRuntime setCaptureOutput(boolean captureOutput)
Specify whether the runtime should capture the script output for running in shell mode.- Parameters:
captureOutput- the captureOutput to set- Returns:
- the groovy script runtime
- Since:
- 4.0.0
-
setClassLoader
public GroovyScriptRuntime setClassLoader(ClassLoader classLoader)
Set the GroovyScript class loader.- Parameters:
classLoader- the groovy script class loader- Returns:
- the groovy script runtime
- Since:
- 17.10.0
-
setSecurityContext
public GroovyScriptRuntime setSecurityContext(String securityContext)
Set the security context of the class loader.- Parameters:
securityContext- the class loader security context- Returns:
- the groovy script runtime
- Since:
- 17.10.0
-
setExecutionTimeout
public GroovyScriptRuntime setExecutionTimeout(int timeout)
Set the GroovyScript execution timeout in milliseconds, a value of 0 means the script will run indefinitely.- Parameters:
timeout- the GroovyScript execution timeout in milliseconds- Returns:
- the groovy script runtime
- Since:
- 4.2.0
-
getExcutionTimeout
public int getExcutionTimeout()
- Returns:
- the GroovyScript execution timeout in milliseconds.
- Since:
- 4.2.0
-
isSecureGroovyAPI
public boolean isSecureGroovyAPI()
- Returns:
- true if using the Secure Groovy API
- Since:
- 5.0.0
-
setSecureGroovyAPI
public GroovyScriptRuntime setSecureGroovyAPI(boolean secureGroovyAPI)
- Parameters:
secureGroovyAPI- the secureGroovyAPI to set- Returns:
- the groovy script runtime
- Since:
- 5.0.0
-
setThreadListener
public GroovyScriptRuntime setThreadListener(IGroovyThreadListener threadListener)
- Parameters:
threadListener- the thread listener to set- Returns:
- the groovy script runtime
- Since:
- 18.5.0
-
setParseOnly
public GroovyScriptRuntime setParseOnly(boolean parseOnly)
- Parameters:
parseOnly- the parseOnly flat to specify only to parse the script and not execute it- Returns:
- the groovy script runtime
- Since:
- 5.0.0
-
-