public class GroovyShell
extends GroovyObjectSupport
Represents a groovy shell capable of running arbitrary groovy scripts
| Modifiers | Name | Description |
|---|---|---|
static String |
DEFAULT_CODE_BASE |
Default code base used for scripts evaluated by the shell. |
| Constructor and description |
|---|
GroovyShell()Creates a shell with a new Binding and the default compiler configuration. |
GroovyShell(Binding binding)Creates a shell with the supplied binding and the default compiler configuration. |
GroovyShell(ClassLoader parent, CompilerConfiguration config)Creates a shell with the supplied parent class loader and compiler configuration. |
GroovyShell(CompilerConfiguration config)Creates a shell with a new Binding and the supplied compiler configuration. |
GroovyShell(Binding binding, CompilerConfiguration config)Creates a shell with the supplied binding and compiler configuration. |
GroovyShell(ClassLoader parent, Binding binding)Creates a shell with the supplied parent class loader and binding. |
GroovyShell(ClassLoader parent)Creates a shell with the supplied parent class loader, a new binding and the default compiler configuration. |
GroovyShell(ClassLoader parent, Binding binding, CompilerConfiguration config)Creates a shell with explicit class loader, binding and compiler configuration. |
GroovyShell(GroovyShell shell)Creates a child shell using a new ClassLoader which uses the parent shell's class loader as its parent |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public Object |
evaluate(GroovyCodeSource codeSource)Evaluates some script against the current Binding and returns the result |
|
public Object |
evaluate(String scriptText)Evaluates some script against the current Binding and returns the result |
|
public Object |
evaluate(String scriptText, String fileName)Evaluates some script against the current Binding and returns the result |
|
public Object |
evaluate(String scriptText, String fileName, String codeBase)Evaluates some script against the current Binding and returns the result. |
|
public Object |
evaluate(File file)Evaluates some script against the current Binding and returns the result |
|
public Object |
evaluate(URI uri)Evaluates some script against the current Binding and returns the result |
|
public Object |
evaluate(Reader in)Evaluates some script against the current Binding and returns the result |
|
public Object |
evaluate(Reader in, String fileName)Evaluates some script against the current Binding and returns the result |
|
protected String |
generateScriptName()Generates a unique logical script name for anonymous shell evaluations. |
|
public GroovyClassLoader |
getClassLoader()Returns the class loader used to parse and load scripts. |
|
public Binding |
getContext()Returns the binding used as this shell's execution context. |
|
public Object |
getProperty(String property)Retrieves a property value.
|
|
public Object |
getVariable(String name)Returns the value of a variable from the shell binding. |
|
public static void |
main(String[] args)Runs the standard groovysh-style command-line entry point. |
|
public Script |
parse(Reader reader, String fileName)Parses the given script and returns it ready to be run |
|
public Script |
parse(Reader reader, String fileName, Binding binding)Parses the given script and returns it ready to be run |
|
public Script |
parse(GroovyCodeSource codeSource, Binding binding)Parses the given script and returns it ready to be run. |
|
public Script |
parse(GroovyCodeSource codeSource)Parses the given script and returns it ready to be run. |
|
public Script |
parse(File file)Parses the given script and returns it ready to be run |
|
public Script |
parse(URI uri)Parses the given script and returns it ready to be run |
|
public Script |
parse(String scriptText, Binding binding)Parses the given script and returns it ready to be run |
|
public Script |
parse(String scriptText)Parses the given script and returns it ready to be run |
|
public Script |
parse(String scriptText, String fileName, Binding binding)Parses script text using an explicit logical name and binding. |
|
public Script |
parse(String scriptText, String fileName)Parses script text using an explicit logical name and this shell's binding. |
|
public Script |
parse(Reader in)Parses the given script and returns it ready to be run |
|
public Script |
parse(Reader in, Binding binding)Parses the given script and returns it ready to be run |
|
public void |
removeVariable(String name)Removes a variable from the shell binding. |
|
public void |
resetLoadedClasses()Clears classes previously loaded by this shell class loader. |
|
public Object |
run(File scriptFile, List<String> list)A helper method which runs the given script file with the given command line arguments |
|
public Object |
run(String scriptText, String fileName, List<String> list)A helper method which runs the given cl script with the given command line arguments |
|
public Object |
run(File scriptFile, String[] args)Runs the given script file name with the given command line arguments |
|
public Object |
run(String scriptText, String fileName, String[] args)Runs the given script text with command line arguments |
|
public Object |
run(GroovyCodeSource source, List<String> args)Runs the given script source with command line arguments |
|
public Object |
run(GroovyCodeSource source, String[] args)Runs the given script source with command line arguments |
|
public Object |
run(URI source, List<String> args)Runs the given script source with command line arguments |
|
public Object |
run(URI source, String[] args)Runs the given script source with command line arguments |
|
public Object |
run(Reader in, String fileName, List<String> list)Runs the given script with command line arguments |
|
public Object |
run(Reader in, String fileName, String[] args)Runs the given script with command line arguments |
|
public void |
setProperty(String property, Object newValue)Sets the given property to the new value.
|
|
public void |
setVariable(String name, Object value)Stores a variable in the shell binding. |
|
public static GroovyShell |
withConfig(Closure<Void> spec)
|
| Methods inherited from class | Name |
|---|---|
class GroovyObjectSupport |
getMetaClass, setMetaClass |
Default code base used for scripts evaluated by the shell.
Creates a shell with a new Binding and the default compiler configuration.
Creates a shell with the supplied binding and the default compiler configuration.
binding - the binding used as the shell contextCreates a shell with the supplied parent class loader and compiler configuration.
parent - the parent class loaderconfig - the compiler configuration to useCreates a shell with a new Binding and the supplied compiler configuration.
config - the compiler configuration to useCreates a shell with the supplied binding and compiler configuration.
binding - the binding used as the shell contextconfig - the compiler configuration to useCreates a shell with the supplied parent class loader and binding.
parent - the parent class loaderbinding - the binding used as the shell contextCreates a shell with the supplied parent class loader, a new binding and the default compiler configuration.
parent - the parent class loaderCreates a shell with explicit class loader, binding and compiler configuration.
parent - the parent class loader, or null to use the shell class loaderbinding - the binding used as the shell contextconfig - the compiler configuration to useCreates a child shell using a new ClassLoader which uses the parent shell's class loader as its parent
shell - is the parent shell used for the variable bindings and the parent class loaderEvaluates some script against the current Binding and returns the result
Evaluates some script against the current Binding and returns the result
scriptText - the text of the scriptEvaluates some script against the current Binding and returns the result
scriptText - the text of the scriptfileName - is the logical file name of the script (which is used to create the class name of the script)Evaluates some script against the current Binding and returns the result. The .class file created from the script is given the supplied codeBase
Evaluates some script against the current Binding and returns the result
file - is the file of the script (which is used to create the class name of the script)Evaluates some script against the current Binding and returns the result
uri - is the URI of the script (which is used to create the class name of the script)Evaluates some script against the current Binding and returns the result
in - the stream reading the scriptEvaluates some script against the current Binding and returns the result
in - the stream reading the scriptfileName - is the logical file name of the script (which is used to create the class name of the script)Generates a unique logical script name for anonymous shell evaluations.
.groovyReturns the class loader used to parse and load scripts.
Returns the binding used as this shell's execution context.
Retrieves a property value.
propertyName - the name of the property of interestReturns the value of a variable from the shell binding.
name - the variable namenull if it is not bound Runs the standard groovysh-style command-line entry point.
args - command-line arguments passed to GroovyMainParses the given script and returns it ready to be run
reader - the stream reading the scriptfileName - is the logical file name of the script (which is used to create the class name of the script)Parses the given script and returns it ready to be run
reader - the stream reading the scriptfileName - is the logical file name of the script (which is used to create the class name of the script)binding - the context eval the scriptParses the given script and returns it ready to be run. When running in a secure environment (-Djava.security.manager) codeSource.getCodeSource() determines what policy grants should be given to the script.
Parses the given script and returns it ready to be run. When running in a secure environment (-Djava.security.manager) codeSource.getCodeSource() determines what policy grants should be given to the script.
Parses the given script and returns it ready to be run
file - is the file of the script (which is used to create the class name of the script)Parses the given script and returns it ready to be run
uri - is the URI of the script (which is used to create the class name of the script)Parses the given script and returns it ready to be run
scriptText - the text of the scriptbinding - the context eval the scriptParses the given script and returns it ready to be run
scriptText - the text of the scriptParses script text using an explicit logical name and binding.
scriptText - the Groovy source textfileName - the logical script namebinding - the binding to associate with the parsed scriptParses script text using an explicit logical name and this shell's binding.
scriptText - the Groovy source textfileName - the logical script nameParses the given script and returns it ready to be run
in - the stream reading the scriptParses the given script and returns it ready to be run
in - the stream reading the scriptbinding - the context eval the scriptRemoves a variable from the shell binding.
name - the variable nameClears classes previously loaded by this shell class loader.
A helper method which runs the given script file with the given command line arguments
scriptFile - the file of the script to runlist - the command line arguments to pass inA helper method which runs the given cl script with the given command line arguments
scriptText - is the text content of the scriptfileName - is the logical file name of the script (which is used to create the class name of the script)list - the command line arguments to pass inRuns the given script file name with the given command line arguments
scriptFile - the file name of the script to runargs - the command line arguments to pass inRuns the given script text with command line arguments
scriptText - is the text content of the scriptfileName - is the logical file name of the script (which is used to create the class name of the script)args - the command line arguments to pass inRuns the given script source with command line arguments
source - is the source content of the scriptargs - the command line arguments to pass inRuns the given script source with command line arguments
source - is the source content of the scriptargs - the command line arguments to pass inRuns the given script source with command line arguments
source - is the source content of the scriptargs - the command line arguments to pass inRuns the given script source with command line arguments
source - is the source content of the scriptargs - the command line arguments to pass inRuns the given script with command line arguments
in - the stream reading the scriptfileName - is the logical file name of the script (which is used to create the class name of the script)list - the command line arguments to pass inRuns the given script with command line arguments
in - the stream reading the scriptfileName - is the logical file name of the script (which is used to create the class name of the script)args - the command line arguments to pass inSets the given property to the new value.
propertyName - the name of the property of interestnewValue - the new value for the propertyStores a variable in the shell binding.
name - the variable namevalue - the value to bind
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.