Package groovy.util
Class GroovyScriptEngine
java.lang.Object
groovy.util.GroovyScriptEngine
- All Implemented Interfaces:
- ResourceConnector
Specific script engine able to reload modified scripts as well as dealing properly
 with dependent scripts.
- 
Constructor SummaryConstructorsConstructorDescriptionGroovyScriptEngine(ResourceConnector rc, ClassLoader parentClassLoader) GroovyScriptEngine(String url) GroovyScriptEngine(String[] urls) GroovyScriptEngine(String[] urls, ClassLoader parentClassLoader) GroovyScriptEngine(String url, ClassLoader parentClassLoader) GroovyScriptEngine(URL[] roots) GroovyScriptEngine(URL[] roots, ClassLoader parentClassLoader) 
- 
Method SummaryModifier and TypeMethodDescriptioncreateScript(String scriptName, Binding binding) Creates a Script with a given scriptName and binding.protected longReturns the GroovyClassLoader associated with this script engine instance.Get theClassLoaderthat will serve as the parent ClassLoader of theGroovyClassLoaderin which scripts will be executed.getResourceConnection(String resourceName) Get a resource connection as aURLConnectionto retrieve a script from theResourceConnector.protected booleanisSourceNewer(groovy.util.GroovyScriptEngine.ScriptCacheEntry entry) loadScriptByName(String scriptName) Get the class of the scriptName in question, so that you can instantiate Groovy objects with caching and reloading.static voidSimple testing harness for the GSE.Run a script identified by name with a given binding.Run a script identified by name with a single argument.voidsetConfig(CompilerConfiguration config) sets a compiler configuration
- 
Constructor Details- 
GroovyScriptEngine
- 
GroovyScriptEngine
- 
GroovyScriptEngine- Throws:
- IOException
 
- 
GroovyScriptEngine- Throws:
- IOException
 
- 
GroovyScriptEngine- Throws:
- IOException
 
- 
GroovyScriptEngine- Throws:
- IOException
 
- 
GroovyScriptEngine
- 
GroovyScriptEngine
 
- 
- 
Method Details- 
mainSimple testing harness for the GSE. Enter script roots as arguments and then input script names to run them.- Parameters:
- urls- an array of URLs
- Throws:
- Exception- if something goes wrong
 
- 
getResourceConnectionGet a resource connection as aURLConnectionto retrieve a script from theResourceConnector.- Specified by:
- getResourceConnectionin interface- ResourceConnector
- Parameters:
- resourceName- name of the resource to be retrieved
- Returns:
- a URLConnection to the resource
- Throws:
- ResourceException
 
- 
getParentClassLoaderGet theClassLoaderthat will serve as the parent ClassLoader of theGroovyClassLoaderin which scripts will be executed. By default, this is the ClassLoader that loaded theGroovyScriptEngineclass.- Returns:
- the parent classloader used to load scripts
 
- 
loadScriptByNameGet the class of the scriptName in question, so that you can instantiate Groovy objects with caching and reloading.- Parameters:
- scriptName- resource name pointing to the script
- Returns:
- the loaded scriptName as a compiled class
- Throws:
- ResourceException- if there is a problem accessing the script
- ScriptException- if there is a problem parsing the script
 
- 
runRun a script identified by name with a single argument.- Parameters:
- scriptName- name of the script to run
- argument- a single argument passed as a variable named- argin the binding
- Returns:
- a toString()representation of the result of the execution of the script
- Throws:
- ResourceException- if there is a problem accessing the script
- ScriptException- if there is a problem parsing the script
 
- 
runRun a script identified by name with a given binding.- Parameters:
- scriptName- name of the script to run
- binding- the binding to pass to the script
- Returns:
- an object
- Throws:
- ResourceException- if there is a problem accessing the script
- ScriptException- if there is a problem parsing the script
 
- 
createScriptpublic Script createScript(String scriptName, Binding binding) throws ResourceException, ScriptException Creates a Script with a given scriptName and binding.- Parameters:
- scriptName- name of the script to run
- binding- the binding to pass to the script
- Returns:
- the script object
- Throws:
- ResourceException- if there is a problem accessing the script
- ScriptException- if there is a problem parsing the script
 
- 
isSourceNewerprotected boolean isSourceNewer(groovy.util.GroovyScriptEngine.ScriptCacheEntry entry) 
- 
getGroovyClassLoaderReturns the GroovyClassLoader associated with this script engine instance. Useful if you need to pass the class loader to another library.- Returns:
- the GroovyClassLoader
 
- 
getConfig- Returns:
- a non null compiler configuration
 
- 
setConfigsets a compiler configuration- Parameters:
- config- - the compiler configuration
- Throws:
- NullPointerException- if config is null
 
- 
getCurrentTimeprotected long getCurrentTime()
 
-