Package groovy.lang
Class Script
java.lang.Object
groovy.lang.GroovyObjectSupport
groovy.lang.Script
- All Implemented Interfaces:
GroovyObject
- Direct Known Subclasses:
DelegatingScript
,GroovyTypeCheckingExtensionSupport.TypeCheckingDSL
This object represents a Groovy script
- Author:
- James Strachan, Guillaume Laforge
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionA helper method to allow the dynamic evaluation of groovy expressions using this scripts binding as the variable scopeA helper method to allow the dynamic evaluation of groovy expressions using this scripts binding as the variable scopegetProperty
(String property) Retrieves a property value.invokeMethod
(String name, Object args) Invoke a method (or closure in the binding) defined.void
Prints the value to the current 'out' variable which should be a PrintWriter or at least have a print() method defined on it.void
Prints a formatted string using the specified format string and argument.void
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
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 currentBinding
instance.void
A helper method to allow scripts to be run taking command line argumentsvoid
setBinding
(Binding binding) void
setProperty
(String property, Object newValue) Sets the given property to the new value.Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, setMetaClass
-
Constructor Details
-
Script
protected Script() -
Script
-
-
Method Details
-
getBinding
-
setBinding
-
getProperty
Description copied from interface:GroovyObject
Retrieves a property value.- Specified by:
getProperty
in interfaceGroovyObject
- Overrides:
getProperty
in classGroovyObjectSupport
- 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.- Specified by:
setProperty
in interfaceGroovyObject
- Overrides:
setProperty
in classGroovyObjectSupport
- Parameters:
property
- the name of the property of interestnewValue
- the new value for the property
-
invokeMethod
Invoke a method (or closure in the binding) defined.- Specified by:
invokeMethod
in interfaceGroovyObject
- Overrides:
invokeMethod
in classGroovyObjectSupport
- Parameters:
name
- method to callargs
- arguments to pass to the method- Returns:
- value
-
run
The main instance method of a script which has variables in scope as defined by the currentBinding
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
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
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
Prints a formatted string using the specified format string and argument.- Parameters:
format
- the format to followvalue
- the value to be formatted
-
printf
Prints a formatted string using the specified format string and arguments.- Parameters:
format
- the format to followvalues
- an array of values to be formatted
-
evaluate
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
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
A helper method to allow scripts to be run taking command line arguments
-