Package groovy.lang
Class GroovyShell
java.lang.Object
groovy.lang.GroovyObjectSupport
groovy.lang.GroovyShell
- All Implemented Interfaces:
GroovyObject
public class GroovyShell extends GroovyObjectSupport
Represents a groovy shell capable of running arbitrary groovy scripts
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_CODE_BASE
-
Constructor Summary
Constructors Constructor Description GroovyShell()
GroovyShell(Binding binding)
GroovyShell(Binding binding, CompilerConfiguration config)
GroovyShell(GroovyShell shell)
Creates a child shell using a new ClassLoader which uses the parent shell's class loader as its parentGroovyShell(ClassLoader parent)
GroovyShell(ClassLoader parent, Binding binding)
GroovyShell(ClassLoader parent, Binding binding, CompilerConfiguration config)
GroovyShell(ClassLoader parent, CompilerConfiguration config)
GroovyShell(CompilerConfiguration config)
-
Method Summary
Modifier and Type Method Description Object
evaluate(GroovyCodeSource codeSource)
Evaluates some script against the current Binding and returns the resultObject
evaluate(File file)
Evaluates some script against the current Binding and returns the resultObject
evaluate(Reader in)
Evaluates some script against the current Binding and returns the resultObject
evaluate(Reader in, String fileName)
Evaluates some script against the current Binding and returns the resultObject
evaluate(String scriptText)
Evaluates some script against the current Binding and returns the resultObject
evaluate(String scriptText, String fileName)
Evaluates some script against the current Binding and returns the resultObject
evaluate(String scriptText, String fileName, String codeBase)
Evaluates some script against the current Binding and returns the result.Object
evaluate(URI uri)
Evaluates some script against the current Binding and returns the resultprotected String
generateScriptName()
GroovyClassLoader
getClassLoader()
Binding
getContext()
Object
getProperty(String property)
Retrieves a property value.Object
getVariable(String name)
static void
main(String[] args)
Script
parse(GroovyCodeSource codeSource)
Parses the given script and returns it ready to be run.Script
parse(File file)
Parses the given script and returns it ready to be runScript
parse(Reader in)
Parses the given script and returns it ready to be runScript
parse(Reader reader, String fileName)
Parses the given script and returns it ready to be runScript
parse(String scriptText)
Parses the given script and returns it ready to be runScript
parse(String scriptText, String fileName)
Script
parse(URI uri)
Parses the given script and returns it ready to be runvoid
removeVariable(String name)
void
resetLoadedClasses()
Object
run(GroovyCodeSource source, String[] args)
Runs the given script source with command line argumentsObject
run(GroovyCodeSource source, List<String> args)
Runs the given script source with command line argumentsObject
run(File scriptFile, String[] args)
Runs the given script file name with the given command line argumentsObject
run(File scriptFile, List<String> list)
A helper method which runs the given script file with the given command line argumentsObject
run(Reader in, String fileName, String[] args)
Runs the given script with command line argumentsObject
run(Reader in, String fileName, List<String> list)
Runs the given script with command line argumentsObject
run(String scriptText, String fileName, String[] args)
Runs the given script text with command line argumentsObject
run(String scriptText, String fileName, List<String> list)
A helper method which runs the given cl script with the given command line argumentsObject
run(URI source, String[] args)
Runs the given script source with command line argumentsObject
run(URI source, List<String> args)
Runs the given script source with command line argumentsvoid
setProperty(String property, Object newValue)
Sets the given property to the new value.void
setVariable(String name, Object value)
Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, setMetaClass
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface groovy.lang.GroovyObject
invokeMethod
-
Field Details
-
DEFAULT_CODE_BASE
- See Also:
- Constant Field Values
-
-
Constructor Details
-
GroovyShell
public GroovyShell() -
GroovyShell
-
GroovyShell
-
GroovyShell
-
GroovyShell
-
GroovyShell
-
GroovyShell
-
GroovyShell
-
GroovyShell
Creates a child shell using a new ClassLoader which uses the parent shell's class loader as its parent- Parameters:
shell
- is the parent shell used for the variable bindings and the parent class loader
-
-
Method Details
-
main
-
resetLoadedClasses
public void resetLoadedClasses() -
getContext
-
getClassLoader
-
getProperty
Description copied from interface:GroovyObject
Retrieves a property value.- Parameters:
property
- the name of the property of interest- Returns:
- the given property
-
setProperty
Description copied from interface:GroovyObject
Sets the given property to the new value.- Parameters:
property
- the name of the property of interestnewValue
- the new value for the property
-
run
public Object run(File scriptFile, List<String> list) throws CompilationFailedException, IOExceptionA helper method which runs the given script file with the given command line arguments- Parameters:
scriptFile
- the file of the script to runlist
- the command line arguments to pass in- Throws:
CompilationFailedException
IOException
-
run
public Object run(String scriptText, String fileName, List<String> list) throws CompilationFailedExceptionA helper method which runs the given cl script with the given command line arguments- Parameters:
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 in- Throws:
CompilationFailedException
-
run
Runs the given script file name with the given command line arguments- Parameters:
scriptFile
- the file name of the script to runargs
- the command line arguments to pass in- Throws:
CompilationFailedException
IOException
-
run
public Object run(String scriptText, String fileName, String[] args) throws CompilationFailedExceptionRuns the given script text with command line arguments- Parameters:
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 in- Throws:
CompilationFailedException
-
run
Runs the given script source with command line arguments- Parameters:
source
- is the source content of the scriptargs
- the command line arguments to pass in- Throws:
CompilationFailedException
-
run
Runs the given script source with command line arguments- Parameters:
source
- is the source content of the scriptargs
- the command line arguments to pass in- Throws:
CompilationFailedException
-
run
Runs the given script source with command line arguments- Parameters:
source
- is the source content of the scriptargs
- the command line arguments to pass in- Throws:
CompilationFailedException
IOException
-
run
Runs the given script source with command line arguments- Parameters:
source
- is the source content of the scriptargs
- the command line arguments to pass in- Throws:
CompilationFailedException
IOException
-
run
Runs the given script with command line arguments- Parameters:
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 in- Throws:
CompilationFailedException
-
run
Runs the given script with command line arguments- Parameters:
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 in- Throws:
CompilationFailedException
-
getVariable
-
setVariable
-
removeVariable
-
evaluate
Evaluates some script against the current Binding and returns the result- Parameters:
codeSource
-- Throws:
CompilationFailedException
-
evaluate
Evaluates some script against the current Binding and returns the result- Parameters:
scriptText
- the text of the script- Throws:
CompilationFailedException
-
evaluate
Evaluates some script against the current Binding and returns the result- Parameters:
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)- Throws:
CompilationFailedException
-
evaluate
public Object evaluate(String scriptText, String fileName, String codeBase) throws CompilationFailedExceptionEvaluates some script against the current Binding and returns the result. The .class file created from the script is given the supplied codeBase- Throws:
CompilationFailedException
-
evaluate
Evaluates some script against the current Binding and returns the result- Parameters:
file
- is the file of the script (which is used to create the class name of the script)- Throws:
CompilationFailedException
IOException
-
evaluate
Evaluates some script against the current Binding and returns the result- Parameters:
uri
- is the URI of the script (which is used to create the class name of the script)- Throws:
CompilationFailedException
IOException
-
evaluate
Evaluates some script against the current Binding and returns the result- Parameters:
in
- the stream reading the script- Throws:
CompilationFailedException
-
evaluate
Evaluates some script against the current Binding and returns the result- Parameters:
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)- Throws:
CompilationFailedException
-
parse
Parses the given script and returns it ready to be run- Parameters:
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)- Returns:
- the parsed script which is ready to be run via
Script.run()
- Throws:
CompilationFailedException
-
parse
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.- Parameters:
codeSource
-- Returns:
- ready to run script
- Throws:
CompilationFailedException
-
parse
Parses the given script and returns it ready to be run- Parameters:
file
- is the file of the script (which is used to create the class name of the script)- Throws:
CompilationFailedException
IOException
-
parse
Parses the given script and returns it ready to be run- Parameters:
uri
- is the URI of the script (which is used to create the class name of the script)- Throws:
CompilationFailedException
IOException
-
parse
Parses the given script and returns it ready to be run- Parameters:
scriptText
- the text of the script- Throws:
CompilationFailedException
-
parse
- Throws:
CompilationFailedException
-
parse
Parses the given script and returns it ready to be run- Parameters:
in
- the stream reading the script- Throws:
CompilationFailedException
-
generateScriptName
-