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 SummaryFields Modifier and Type Field Description static java.lang.StringDEFAULT_CODE_BASE
- 
Constructor SummaryConstructors 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(java.lang.ClassLoader parent)GroovyShell(java.lang.ClassLoader parent, Binding binding)GroovyShell(java.lang.ClassLoader parent, Binding binding, CompilerConfiguration config)GroovyShell(java.lang.ClassLoader parent, CompilerConfiguration config)GroovyShell(CompilerConfiguration config)
- 
Method SummaryModifier and Type Method Description java.lang.Objectevaluate(GroovyCodeSource codeSource)Evaluates some script against the current Binding and returns the resultjava.lang.Objectevaluate(java.io.File file)Evaluates some script against the current Binding and returns the resultjava.lang.Objectevaluate(java.io.Reader in)Evaluates some script against the current Binding and returns the resultjava.lang.Objectevaluate(java.io.Reader in, java.lang.String fileName)Evaluates some script against the current Binding and returns the resultjava.lang.Objectevaluate(java.lang.String scriptText)Evaluates some script against the current Binding and returns the resultjava.lang.Objectevaluate(java.lang.String scriptText, java.lang.String fileName)Evaluates some script against the current Binding and returns the resultjava.lang.Objectevaluate(java.lang.String scriptText, java.lang.String fileName, java.lang.String codeBase)Evaluates some script against the current Binding and returns the result.java.lang.Objectevaluate(java.net.URI uri)Evaluates some script against the current Binding and returns the resultprotected java.lang.StringgenerateScriptName()GroovyClassLoadergetClassLoader()BindinggetContext()java.lang.ObjectgetProperty(java.lang.String property)Retrieves a property value.java.lang.ObjectgetVariable(java.lang.String name)static voidmain(java.lang.String[] args)Scriptparse(GroovyCodeSource codeSource)Parses the given script and returns it ready to be run.Scriptparse(java.io.File file)Parses the given script and returns it ready to be runScriptparse(java.io.Reader in)Parses the given script and returns it ready to be runScriptparse(java.io.Reader reader, java.lang.String fileName)Parses the given script and returns it ready to be runScriptparse(java.lang.String scriptText)Parses the given script and returns it ready to be runScriptparse(java.lang.String scriptText, java.lang.String fileName)Scriptparse(java.net.URI uri)Parses the given script and returns it ready to be runvoidremoveVariable(java.lang.String name)voidresetLoadedClasses()java.lang.Objectrun(GroovyCodeSource source, java.lang.String[] args)Runs the given script source with command line argumentsjava.lang.Objectrun(GroovyCodeSource source, java.util.List<java.lang.String> args)Runs the given script source with command line argumentsjava.lang.Objectrun(java.io.File scriptFile, java.lang.String[] args)Runs the given script file name with the given command line argumentsjava.lang.Objectrun(java.io.File scriptFile, java.util.List<java.lang.String> list)A helper method which runs the given script file with the given command line argumentsjava.lang.Objectrun(java.io.Reader in, java.lang.String fileName, java.lang.String[] args)Runs the given script with command line argumentsjava.lang.Objectrun(java.io.Reader in, java.lang.String fileName, java.util.List<java.lang.String> list)Runs the given script with command line argumentsjava.lang.Objectrun(java.lang.String scriptText, java.lang.String fileName, java.lang.String[] args)Runs the given script text with command line argumentsjava.lang.Objectrun(java.lang.String scriptText, java.lang.String fileName, java.util.List<java.lang.String> list)A helper method which runs the given cl script with the given command line argumentsjava.lang.Objectrun(java.net.URI source, java.lang.String[] args)Runs the given script source with command line argumentsjava.lang.Objectrun(java.net.URI source, java.util.List<java.lang.String> args)Runs the given script source with command line argumentsvoidsetProperty(java.lang.String property, java.lang.Object newValue)Sets the given property to the new value.voidsetVariable(java.lang.String name, java.lang.Object value)Methods inherited from class groovy.lang.GroovyObjectSupportgetMetaClass, setMetaClassMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface groovy.lang.GroovyObjectinvokeMethod
- 
Field Details- 
DEFAULT_CODE_BASEpublic static final java.lang.String DEFAULT_CODE_BASE- See Also:
- Constant Field Values
 
 
- 
- 
Constructor Details- 
GroovyShellpublic GroovyShell()
- 
GroovyShell
- 
GroovyShell
- 
GroovyShell
- 
GroovyShell
- 
GroovyShell
- 
GroovyShellpublic GroovyShell(java.lang.ClassLoader parent)
- 
GroovyShell
- 
GroovyShellCreates 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- 
mainpublic static void main(java.lang.String[] args)
- 
resetLoadedClassespublic void resetLoadedClasses()
- 
getContext
- 
getClassLoader
- 
getPropertypublic java.lang.Object getProperty(java.lang.String property)Description copied from interface:GroovyObjectRetrieves a property value.- Parameters:
- property- the name of the property of interest
- Returns:
- the given property
 
- 
setPropertypublic void setProperty(java.lang.String property, java.lang.Object newValue)Description copied from interface:GroovyObjectSets the given property to the new value.- Parameters:
- property- the name of the property of interest
- newValue- the new value for the property
 
- 
runpublic java.lang.Object run(java.io.File scriptFile, java.util.List<java.lang.String> list) throws CompilationFailedException, java.io.IOExceptionA helper method which runs the given script file with the given command line arguments- Parameters:
- scriptFile- the file of the script to run
- list- the command line arguments to pass in
- Throws:
- CompilationFailedException
- java.io.IOException
 
- 
runpublic java.lang.Object run(java.lang.String scriptText, java.lang.String fileName, java.util.List<java.lang.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 script
- fileName- 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
 
- 
runpublic java.lang.Object run(java.io.File scriptFile, java.lang.String[] args) throws CompilationFailedException, java.io.IOExceptionRuns the given script file name with the given command line arguments- Parameters:
- scriptFile- the file name of the script to run
- args- the command line arguments to pass in
- Throws:
- CompilationFailedException
- java.io.IOException
 
- 
runpublic java.lang.Object run(java.lang.String scriptText, java.lang.String fileName, java.lang.String[] args) throws CompilationFailedExceptionRuns the given script text with command line arguments- Parameters:
- scriptText- is the text content of the script
- fileName- 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
 
- 
runpublic java.lang.Object run(GroovyCodeSource source, java.util.List<java.lang.String> args) throws CompilationFailedExceptionRuns the given script source with command line arguments- Parameters:
- source- is the source content of the script
- args- the command line arguments to pass in
- Throws:
- CompilationFailedException
 
- 
runpublic java.lang.Object run(GroovyCodeSource source, java.lang.String[] args) throws CompilationFailedExceptionRuns the given script source with command line arguments- Parameters:
- source- is the source content of the script
- args- the command line arguments to pass in
- Throws:
- CompilationFailedException
 
- 
runpublic java.lang.Object run(java.net.URI source, java.util.List<java.lang.String> args) throws CompilationFailedException, java.io.IOExceptionRuns the given script source with command line arguments- Parameters:
- source- is the source content of the script
- args- the command line arguments to pass in
- Throws:
- CompilationFailedException
- java.io.IOException
 
- 
runpublic java.lang.Object run(java.net.URI source, java.lang.String[] args) throws CompilationFailedException, java.io.IOExceptionRuns the given script source with command line arguments- Parameters:
- source- is the source content of the script
- args- the command line arguments to pass in
- Throws:
- CompilationFailedException
- java.io.IOException
 
- 
runpublic java.lang.Object run(java.io.Reader in, java.lang.String fileName, java.util.List<java.lang.String> list) throws CompilationFailedExceptionRuns the given script with command line arguments- Parameters:
- in- the stream reading the script
- fileName- 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
 
- 
runpublic java.lang.Object run(java.io.Reader in, java.lang.String fileName, java.lang.String[] args) throws CompilationFailedExceptionRuns the given script with command line arguments- Parameters:
- in- the stream reading the script
- fileName- 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
 
- 
getVariablepublic java.lang.Object getVariable(java.lang.String name)
- 
setVariablepublic void setVariable(java.lang.String name, java.lang.Object value)
- 
removeVariablepublic void removeVariable(java.lang.String name)
- 
evaluateEvaluates some script against the current Binding and returns the result- Parameters:
- codeSource-
- Throws:
- CompilationFailedException
 
- 
evaluateEvaluates some script against the current Binding and returns the result- Parameters:
- scriptText- the text of the script
- Throws:
- CompilationFailedException
 
- 
evaluatepublic java.lang.Object evaluate(java.lang.String scriptText, java.lang.String fileName) throws CompilationFailedExceptionEvaluates some script against the current Binding and returns the result- Parameters:
- scriptText- the text of the script
- fileName- is the logical file name of the script (which is used to create the class name of the script)
- Throws:
- CompilationFailedException
 
- 
evaluatepublic java.lang.Object evaluate(java.lang.String scriptText, java.lang.String fileName, java.lang.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
 
- 
evaluatepublic java.lang.Object evaluate(java.io.File file) throws CompilationFailedException, java.io.IOExceptionEvaluates 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
- java.io.IOException
 
- 
evaluatepublic java.lang.Object evaluate(java.net.URI uri) throws CompilationFailedException, java.io.IOExceptionEvaluates 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
- java.io.IOException
 
- 
evaluateEvaluates some script against the current Binding and returns the result- Parameters:
- in- the stream reading the script
- Throws:
- CompilationFailedException
 
- 
evaluatepublic java.lang.Object evaluate(java.io.Reader in, java.lang.String fileName) throws CompilationFailedExceptionEvaluates some script against the current Binding and returns the result- Parameters:
- in- the stream reading the script
- fileName- is the logical file name of the script (which is used to create the class name of the script)
- Throws:
- CompilationFailedException
 
- 
parsepublic Script parse(java.io.Reader reader, java.lang.String fileName) throws CompilationFailedExceptionParses the given script and returns it ready to be run- Parameters:
- reader- the stream reading the script
- fileName- 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
 
- 
parseParses 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
 
- 
parseParses 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
- java.io.IOException
 
- 
parseParses 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
- java.io.IOException
 
- 
parseParses the given script and returns it ready to be run- Parameters:
- scriptText- the text of the script
- Throws:
- CompilationFailedException
 
- 
parsepublic Script parse(java.lang.String scriptText, java.lang.String fileName) throws CompilationFailedException- Throws:
- CompilationFailedException
 
- 
parseParses the given script and returns it ready to be run- Parameters:
- in- the stream reading the script
- Throws:
- CompilationFailedException
 
- 
generateScriptNameprotected java.lang.String generateScriptName()
 
-