Package groovy.lang

# Class Script

java.lang.Object
groovy.lang.GroovyObjectSupport
groovy.lang.Script

All Implemented Interfaces:
  `GroovyObject`

Direct Known Subclasses:
  `DelegatingScript`, `GroovyTypeCheckingExtensionSupport.TypeCheckingDSL`

public abstract class Script extends GroovyObjectSupport
This object represents a Groovy script

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `Script()`
  Creates a script with a fresh `Binding`.
  `protected`
  `Script(Binding binding)`
  Creates a script backed by the supplied binding.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Object`
  `evaluate(File file)`
  A helper method to allow the dynamic evaluation of groovy expressions using this scripts binding as the variable scope
  `Object`
  `evaluate(String expression)`
  A helper method to allow the dynamic evaluation of groovy expressions using this scripts binding as the variable scope
  `Binding`
  `getBinding()`
  Returns the binding used to resolve script variables.
  `Object`
  `getProperty(String property)`
  Retrieves a property value.
  `Object`
  `invokeMethod(String name, Object args)`
  Invoke a method (or closure in the binding) defined.
  `void`
  `print(Object value)`
  Prints the value to the current 'out' variable which should be a PrintWriter or at least have a print() method defined on it.
  `void`
  `printf(String format, Object value)`
  Prints a formatted string using the specified format string and argument.
  `void`
  `printf(String format, Object[] values)`
  Prints a formatted string using the specified format string and arguments.
  `void`
  `println()`
  Prints a newline to the current 'out' variable which should be a PrintWriter or at least have a println() method defined on it.
  `void`
  `println(Object value)`
  Prints the value and a newline to the current 'out' variable which should be a PrintWriter or at least have a println() method defined on it.
  `abstract Object`
  `run()`
  The main instance method of a script which has variables in scope as defined by the current `Binding` instance.
  `void`
  `run(File file, String[] arguments)`
  A helper method to allow scripts to be run taking command line arguments
  `void`
  `setBinding(Binding binding)`
  Replaces the binding used to resolve script variables.
  `void`
  `setProperty(String property, Object newValue)`
  Sets the given property to the new 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`

- ## Constructor Details

  - ### Script

    protected Script()
    Creates a script with a fresh `Binding`.

  - ### Script

    protected Script(Binding binding)
    Creates a script backed by the supplied binding.
    Parameters:
      `binding` - the binding that supplies script variables

- ## Method Details

  - ### getBinding

    public Binding getBinding()
    Returns the binding used to resolve script variables.
    Returns:
      the script binding

  - ### setBinding

    public void setBinding(Binding binding)
    Replaces the binding used to resolve script variables.
    Parameters:
      `binding` - the new script binding

  - ### getProperty

    public Object getProperty(String property)
    Retrieves a property value.
    Parameters:
      `property` - the name of the property of interest
    Returns:
      the given property

  - ### setProperty

    public void setProperty(String property, Object newValue)
    Sets the given property to the new value.
    Parameters:
      `property` - the name of the property of interest
      `newValue` - the new value for the property

  - ### invokeMethod

    public Object invokeMethod(String name, Object args)
    Invoke a method (or closure in the binding) defined.
    Parameters:
      `name` - method to call
      `args` - arguments to pass to the method
    Returns:
      value

  - ### run

    public abstract Object run()
    The main instance method of a script which has variables in scope as defined by the current `Binding` instance.

  - ### println

    public void println()
    Prints a newline to the current 'out' variable which should be a PrintWriter or at least have a println() method defined on it. If there is no 'out' property then print to standard out.

  - ### print

    public void print(Object value)
    Prints the value to the current 'out' variable which should be a PrintWriter or at least have a print() method defined on it. If there is no 'out' property then print to standard out.

  - ### println

    public void println(Object value)
    Prints the value and a newline to the current 'out' variable which should be a PrintWriter or at least have a println() method defined on it. If there is no 'out' property then print to standard out.

  - ### printf

    public void printf(String format, Object value)
    Prints a formatted string using the specified format string and argument.
    Parameters:
      `format` - the format to follow
      `value` - the value to be formatted

  - ### printf

    public void printf(String format, Object[] values)
    Prints a formatted string using the specified format string and arguments.
    Parameters:
      `format` - the format to follow
      `values` - an array of values to be formatted

  - ### evaluate

    public Object evaluate(String expression) throws CompilationFailedException
    A helper method to allow the dynamic evaluation of groovy expressions using this scripts binding as the variable scope
    Parameters:
      `expression` - is the Groovy script expression to evaluate
    Throws:
      `CompilationFailedException`

  - ### evaluate

    public Object evaluate(File file) throws CompilationFailedException, IOException
    A helper method to allow the dynamic evaluation of groovy expressions using this scripts binding as the variable scope
    Parameters:
      `file` - is the Groovy script to evaluate
    Throws:
      `CompilationFailedException`
      `IOException`

  - ### run

    public void run(File file, String[] arguments) throws CompilationFailedException, IOException
    A helper method to allow scripts to be run taking command line arguments
    Throws:
      `CompilationFailedException`
      `IOException`