public class GroovyEngine
extends Object
implements ScriptEngine
Implements Groovy ScriptEngine. You must be very careful when using GroovyEngine in a multithreaded environment. The Binding instance is not thread safe, and it is shared by all scripts.
| Modifiers | Name | Description |
|---|---|---|
protected static class |
GroovyEngine.AccessRules |
Encapsulates access rules for code completion. |
interface |
GroovyEngine.Cloner |
Strategy used to clone session values for completion and inspection workflows. |
static class |
GroovyEngine.EngineClassLoader |
Custom class loader for dynamically loaded Groovy classes. |
enum |
GroovyEngine.Format |
Serialization/deserialization format options. |
| Modifiers | Name | Description |
|---|---|---|
static String |
ALL_CLASSES_COMPLETION |
Option key to enable completion for all classes including non-public |
static String |
ALL_CONSTRUCTORS_COMPLETION |
Option key to enable completion for all constructors including non-public |
static String |
ALL_FIELDS_COMPLETION |
Option key to enable completion for all fields including non-public |
static String |
ALL_METHODS_COMPLETION |
Option key to enable completion for all methods including non-public |
static String |
CANONICAL_NAMES |
Option key for using canonical class names in descriptions |
static String |
GROOVY_COLORS |
Environment variable for Groovy color settings |
static String |
IDENTIFIERS_COMPLETION |
Option key to enable identifier completion |
static String |
META_METHODS_COMPLETION |
Option key to enable meta-method completion |
static String |
NANORC_SYNTAX |
Option key for nanorc syntax file location |
static String |
NANORC_VALUE |
Option key for nanorc value configuration |
static String |
NO_SYNTAX_CHECK |
Option key to disable syntax checking |
static String |
RESTRICTED_COMPLETION |
Option key for restricted completion mode |
static String |
SYNTHETIC_METHODS_COMPLETION |
Option key to enable synthetic method completion |
protected GroovyEngine.EngineClassLoader |
classLoader |
Class loader for dynamically loaded Groovy classes |
protected Binding |
sharedData |
Shared binding that stores variables visible to interactive scripts. |
| Constructor and description |
|---|
GroovyEngine()Constructs a new GroovyEngine with default configuration. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
del(String vars)Deletes multiple variables from the binding. |
|
public Object |
deserialize(String value, String formatStr)Deserializes a string value according to the specified format. |
|
public Object |
execute(File script, Object[] args)Executes a Groovy script from a file. |
|
public Object |
execute(String statement)Executes a Groovy statement. |
|
public Object |
execute(Object closure, Object args)Executes a Groovy closure with the given arguments. |
|
public Map<String, Object> |
find(String name)Finds variables matching the given pattern. |
|
public Object |
get(String name)Retrieves a variable from the binding. |
|
public String |
getBuffer()Returns the current executable buffer reconstructed from the recorded snippets. |
|
public List<String> |
getDeserializationFormats()Returns the list of supported deserialization formats. |
|
public String |
getEngineName()Returns the name of this script engine. |
|
public List<String> |
getExtensions()Returns the file extensions supported by this engine. |
|
public Map<String, String> |
getImports()Returns all import statements mapped to their source definitions. |
|
public Set<String> |
getMethodNames()Returns the set of defined method names. |
|
public Map<String, String> |
getMethods()Returns all defined methods mapped to their source definitions. |
|
public GroovyEngine.Cloner |
getObjectCloner()Returns the current object cloner. |
|
public Completer |
getScriptCompleter()Returns the completer for Groovy script completions. |
|
public List<String> |
getSerializationFormats()Returns the list of supported serialization formats. |
|
protected SyntaxHighlighter |
getSyntaxHighlighter()Returns the syntax highlighter for Groovy code. |
|
public Map<String, String> |
getTypes()Returns all defined types mapped to their source definitions. |
|
public Map<String, String> |
getVariables()Returns all defined variables mapped to their source definitions. |
<T> |
protected T |
groovyOption(String option, T defval)Returns the value of a specific Groovy option. |
<T> |
protected static T |
groovyOption(Map<String, Object> options, String option, T defval)Returns the value of a specific option from the given options map. |
|
protected Map<String, Object> |
groovyOptions()Returns the current Groovy options map. |
|
public boolean |
hasVariable(String name)Checks if a variable with the given name exists in the binding. |
|
public void |
persist(Path file, Object object)Persists an object to a file using the default serialization format. |
|
public void |
persist(Path file, Object object, String format)Persists an object to a file using the specified serialization format. |
|
public void |
purgeClassCache(String regex)Purges classes from the class cache matching the given regex. |
|
public void |
put(String name, Object value)Stores a variable in the binding. |
|
public boolean |
refresh()Refreshes the syntax highlighter, forcing a reload on next use. |
|
public void |
removeImport(String name)Removes an import statement by name. |
|
public void |
removeMethod(String name)Removes a method definition by name or signature. |
|
public void |
removeType(String name)Removes a type definition by name. |
|
public void |
removeVariable(String name)Removes a variable definition by name. |
|
public void |
reset()Resets the engine state, clearing all variables, methods, types, and imports. |
|
public CmdDesc |
scriptDescription(CmdLine line)Generates a description for the given command line. |
|
public void |
setObjectCloner(GroovyEngine.Cloner objectCloner)Sets the object cloner to use for copying session values. |
|
public String |
toJson(Object obj)Converts an object to JSON format. |
|
public Map<String, Object> |
toMap(Object obj)Converts an object to a map representation. |
|
public String |
toString(Object obj)Converts an object to Groovy string format. |
Option key to enable completion for all classes including non-public
Option key to enable completion for all constructors including non-public
Option key to enable completion for all fields including non-public
Option key to enable completion for all methods including non-public
Option key for using canonical class names in descriptions
Environment variable for Groovy color settings
Option key to enable identifier completion
Option key to enable meta-method completion
Option key for nanorc syntax file location
Option key for nanorc value configuration
Option key to disable syntax checking
Option key for restricted completion mode
Option key to enable synthetic method completion
Class loader for dynamically loaded Groovy classes
Shared binding that stores variables visible to interactive scripts.
Deletes multiple variables from the binding.
vars - variable names to deleteDeserializes a string value according to the specified format.
value - the string to deserializeformatStr - the format name (JSON, GROOVY, NONE, or AUTO)Executes a Groovy script from a file.
script - the script file to executeargs - arguments to pass to the scriptExecutes a Groovy statement.
statement - the Groovy statement to executeExecutes a Groovy closure with the given arguments.
closure - the closure to executeargs - arguments to pass to the closureFinds variables matching the given pattern.
name - the variable name pattern, or null to return all variablesRetrieves a variable from the binding.
name - the variable namenull if not foundReturns the current executable buffer reconstructed from the recorded snippets.
Returns the list of supported deserialization formats.
Returns the name of this script engine.
Returns the file extensions supported by this engine.
Returns all import statements mapped to their source definitions.
Returns the set of defined method names.
Returns all defined methods mapped to their source definitions.
Returns the current object cloner.
Returns the completer for Groovy script completions.
Returns the list of supported serialization formats.
Returns the syntax highlighter for Groovy code.
Returns all defined types mapped to their source definitions.
Returns all defined variables mapped to their source definitions.
Returns the value of a specific Groovy option.
option - the option keydefval - the default value if option not foundT - the type of the option valueReturns the value of a specific option from the given options map.
options - the options mapoption - the option keydefval - the default value if option not foundT - the type of the option valueReturns the current Groovy options map.
Checks if a variable with the given name exists in the binding.
name - the variable name to checktrue if the variable exists, false otherwisePersists an object to a file using the default serialization format.
file - the target file pathobject - the object to persistPersists an object to a file using the specified serialization format.
file - the target file pathobject - the object to persistformat - the format name to usePurges classes from the class cache matching the given regex.
regex - the pattern to match class names, or null to clear allStores a variable in the binding.
name - the variable namevalue - the value to storeRefreshes the syntax highlighter, forcing a reload on next use.
Removes an import statement by name.
name - the import identifier to removeRemoves a method definition by name or signature.
name - method name or full signature to removeRemoves a type definition by name.
name - the type name to removeRemoves a variable definition by name.
name - the variable name to removeResets the engine state, clearing all variables, methods, types, and imports.
Generates a description for the given command line.
line - the command line to describeSets the object cloner to use for copying session values.
objectCloner - the cloner implementationConverts an object to JSON format.
obj - the object to convertConverts an object to a map representation.
obj - the object to convertCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.