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

Version:
  $Revision: 21030 $
Author:
  James Strachan, Guillaume Laforge, Paul King

### Field Summary

Fields
`static String` `DEFAULT_CODE_BASE`
`static String[]` `EMPTY_ARGS` Deprecated.

### Constructor Summary

Constructors
Constructor and Description
`GroovyShell()`
`GroovyShell(Binding binding)`
`GroovyShell(Binding binding, CompilerConfiguration config)`
`GroovyShell(ClassLoader parent)`
`GroovyShell(ClassLoader parent, Binding binding)`
`GroovyShell(ClassLoader parent, Binding binding, CompilerConfiguration config)`
`GroovyShell(CompilerConfiguration config)`
`GroovyShell(GroovyShell shell)` Creates a child shell using a new ClassLoader which uses the parent shell's class loader as its parent

### Method Summary

Methods
`Object` `evaluate(File file)` Evaluates some script against the current Binding and returns the result
`Object` `evaluate(GroovyCodeSource codeSource)` Evaluates some script against the current Binding and returns the result
`Object` `evaluate(InputStream in)` Deprecated. Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.
`Object` `evaluate(InputStream in, String fileName)` Deprecated. Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.
`Object` `evaluate(Reader in)` Evaluates some script against the current Binding and returns the result
`Object` `evaluate(Reader in, String fileName)` Evaluates some script against the current Binding and returns the result
`Object` `evaluate(String scriptText)` Evaluates some script against the current Binding and returns the result
`Object` `evaluate(String scriptText, String fileName)` Evaluates some script against the current Binding and returns the result
`Object` `evaluate(String scriptText, String fileName, String codeBase)` Evaluates some script against the current Binding and returns the result.
`protected String` `generateScriptName()`
`GroovyClassLoader` `getClassLoader()`
`Binding` `getContext()`
`Object` `getProperty(String property)` Retrieves a property value.
`Object` `getVariable(String name)`
`void` `initializeBinding()` Deprecated.
`static void` `main(String[] args)`
`Script` `parse(File file)` Parses the given script and returns it ready to be run
`Script` `parse(GroovyCodeSource codeSource)` Parses the given script and returns it ready to be run.
`Script` `parse(InputStream in)` Deprecated. Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.
`Script` `parse(InputStream in, String fileName)` Deprecated. Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.
`Script` `parse(Reader in)` Parses the given script and returns it ready to be run
`Script` `parse(Reader reader, String fileName)` Parses the given script and returns it ready to be run
`Script` `parse(String scriptText)` Parses the given script and returns it ready to be run
`Script` `parse(String scriptText, String fileName)`
`void` `resetLoadedClasses()`
`Object` `run(File scriptFile, List list)` A helper method which runs the given script file with the given command line arguments
`Object` `run(File scriptFile, String[] args)` Runs the given script file name with the given command line arguments
`Object` `run(InputStream in, String fileName, String[] args)` Deprecated. Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.
`Object` `run(Reader in, String fileName, String[] args)` Runs the given script with command line arguments
`Object` `run(String scriptText, String fileName, List list)` A helper method which runs the given cl script with the given command line arguments
`Object` `run(String scriptText, String fileName, String[] args)` Runs the given script text with command line arguments
`void` `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, invokeMethod, setMetaClass`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### DEFAULT_CODE_BASE

    public static final String DEFAULT_CODE_BASE

See Also:
  Constant Field Values

#### EMPTY_ARGS

    @Deprecated
    public static final String[] EMPTY_ARGS

Deprecated.

### Constructor Detail

#### GroovyShell

    public GroovyShell()

#### GroovyShell

    public GroovyShell(Binding binding)

#### GroovyShell

    public GroovyShell(CompilerConfiguration config)

#### GroovyShell

    public GroovyShell(Binding binding,
               CompilerConfiguration config)

#### GroovyShell

    public GroovyShell(ClassLoader parent,
               Binding binding)

#### GroovyShell

    public GroovyShell(ClassLoader parent)

#### GroovyShell

    public GroovyShell(ClassLoader parent,
               Binding binding,
               CompilerConfiguration config)

#### GroovyShell

    public GroovyShell(GroovyShell shell)

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 Detail

#### main

    public static void main(String[] args)

#### initializeBinding

    @Deprecated
    public void initializeBinding()

Deprecated.

#### resetLoadedClasses

    public void resetLoadedClasses()

#### getContext

    public Binding getContext()

#### getClassLoader

    public GroovyClassLoader getClassLoader()

#### getProperty

    public Object getProperty(String property)

Description copied from interface: `GroovyObject`
Retrieves a property value.

Specified by:
  `getProperty` in interface `GroovyObject`
Overrides:
  `getProperty` in class `GroovyObjectSupport`
Parameters:
  `property` - the name of the property of interest
Returns:
  the given property

#### setProperty

    public void setProperty(String property,
                   Object newValue)

Description copied from interface: `GroovyObject`
Sets the given property to the new value.

Specified by:
  `setProperty` in interface `GroovyObject`
Overrides:
  `setProperty` in class `GroovyObjectSupport`
Parameters:
  `property` - the name of the property of interest
  `newValue` - the new value for the property

#### run

    public Object run(File scriptFile,
             List list)
               throws CompilationFailedException,
                      IOException

A 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`
  `IOException`

#### run

    public Object run(String scriptText,
             String fileName,
             List list)
               throws CompilationFailedException

A 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`

#### run

    public Object run(File scriptFile,
             String[] args)
               throws CompilationFailedException,
                      IOException

Runs 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`
  `IOException`

#### run

    public Object run(String scriptText,
             String fileName,
             String[] args)
               throws CompilationFailedException

Runs 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`

#### run

    public Object run(Reader in,
             String fileName,
             String[] args)
               throws CompilationFailedException

Runs 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`

#### run

    public Object run(InputStream in,
             String fileName,
             String[] args)
               throws CompilationFailedException

Deprecated. Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.
Runs 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`

#### getVariable

    public Object getVariable(String name)

#### setVariable

    public void setVariable(String name,
                   Object value)

#### evaluate

    public Object evaluate(GroovyCodeSource codeSource)
                    throws CompilationFailedException

Evaluates some script against the current Binding and returns the result

Parameters:
  `codeSource` -
Throws:
  `CompilationFailedException`

#### evaluate

    public Object evaluate(String scriptText)
                    throws CompilationFailedException

Evaluates some script against the current Binding and returns the result

Parameters:
  `scriptText` - the text of the script
Throws:
  `CompilationFailedException`

#### evaluate

    public Object evaluate(String scriptText,
                  String fileName)
                    throws CompilationFailedException

Evaluates 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`

#### evaluate

    public Object evaluate(String scriptText,
                  String fileName,
                  String codeBase)
                    throws CompilationFailedException

Evaluates 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

    public Object evaluate(File file)
                    throws CompilationFailedException,
                           IOException

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

    public Object evaluate(Reader in)
                    throws CompilationFailedException

Evaluates some script against the current Binding and returns the result

Parameters:
  `in` - the stream reading the script
Throws:
  `CompilationFailedException`

#### evaluate

    public Object evaluate(Reader in,
                  String fileName)
                    throws CompilationFailedException

Evaluates 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`

#### evaluate

    public Object evaluate(InputStream in)
                    throws CompilationFailedException

Deprecated. Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.
Evaluates some script against the current Binding and returns the result

Parameters:
  `in` - the stream reading the script
Throws:
  `CompilationFailedException`

#### evaluate

    public Object evaluate(InputStream in,
                  String fileName)
                    throws CompilationFailedException

Deprecated. Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.
Evaluates 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`

#### parse

    public Script parse(Reader reader,
               String fileName)
                 throws CompilationFailedException

Parses 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 @link Script.run()
Throws:
  `CompilationFailedException`

#### parse

    public Script parse(InputStream in,
               String fileName)
                 throws CompilationFailedException

Deprecated. Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.
Parses the given script and returns it ready to be run

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)
Returns:
  the parsed script which is ready to be run via @link Script.run()
Throws:
  `CompilationFailedException`

#### parse

    public Script parse(GroovyCodeSource codeSource)
                 throws CompilationFailedException

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

    public Script parse(File file)
                 throws CompilationFailedException,
                        IOException

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

    public Script parse(String scriptText)
                 throws CompilationFailedException

Parses the given script and returns it ready to be run

Parameters:
  `scriptText` - the text of the script
Throws:
  `CompilationFailedException`

#### parse

    public Script parse(String scriptText,
               String fileName)
                 throws CompilationFailedException

Throws:
  `CompilationFailedException`

#### parse

    public Script parse(Reader in)
                 throws CompilationFailedException

Parses the given script and returns it ready to be run

Parameters:
  `in` - the stream reading the script
Throws:
  `CompilationFailedException`

#### parse

    public Script parse(InputStream in)
                 throws CompilationFailedException

Deprecated. Prefer using methods taking a Reader rather than an InputStream to avoid wrong encoding issues.
Parses the given script and returns it ready to be run

Parameters:
  `in` - the stream reading the script
Throws:
  `CompilationFailedException`

#### generateScriptName

    protected String generateScriptName()