[Java] Class GroovyScriptEngine

  • groovy.util.GroovyScriptEngine
All Implemented Interfaces and Traits:
ResourceConnector
public class GroovyScriptEngine
extends Object

Specific script engine able to reload modified scripts as well as dealing properly with dependent scripts.

Authors:
sam
Marc Palmer
Guillaume Laforge
Jochen Theodorou
Mattias Reichel

Methods Summary

Methods
Type Params Return Type Name and description
def GroovyScriptEngine(URL[] roots)
def GroovyScriptEngine(URL[] roots, ClassLoader parentClassLoader)
def GroovyScriptEngine(String[] urls)
def GroovyScriptEngine(String[] urls, ClassLoader parentClassLoader)
def GroovyScriptEngine(String url)
def GroovyScriptEngine(String url, ClassLoader parentClassLoader)
def GroovyScriptEngine(ResourceConnector rc)
def GroovyScriptEngine(ResourceConnector rc, ClassLoader parentClassLoader)
Script createScript(String scriptName, Binding binding)
Creates a Script with a given scriptName and binding.
CompilerConfiguration getConfig()
@return a non null compiler configuration
protected long getCurrentTime()
GroovyClassLoader getGroovyClassLoader()
Returns the GroovyClassLoader associated with this script engine instance.
ClassLoader getParentClassLoader()
Get the ClassLoader that will serve as the parent ClassLoader of the GroovyClassLoader in which scripts will be executed.
URLConnection getResourceConnection(String resourceName)
Get a resource connection as a URLConnection to retrieve a script from the ResourceConnector.
protected boolean isSourceNewer(GroovyScriptEngine.ScriptCacheEntry entry)
Class loadScriptByName(String scriptName)
Get the class of the scriptName in question, so that you can instantiate Groovy objects with caching and reloading.
static void main(String[] urls)
Simple testing harness for the GSE.
String run(String scriptName, String argument)
Run a script identified by name with a single argument.
Object run(String scriptName, Binding binding)
Run a script identified by name with a given binding.
void setConfig(CompilerConfiguration config)
sets a compiler configuration

Inherited Methods Summary

Inherited Methods
Methods inherited from class Name
class Object wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll

Method Detail

public def GroovyScriptEngine(URL[] roots)

public def GroovyScriptEngine(URL[] roots, ClassLoader parentClassLoader)

public def GroovyScriptEngine(String[] urls)

public def GroovyScriptEngine(String[] urls, ClassLoader parentClassLoader)

public def GroovyScriptEngine(String url)

public def GroovyScriptEngine(String url, ClassLoader parentClassLoader)

public def GroovyScriptEngine(ResourceConnector rc)

public def GroovyScriptEngine(ResourceConnector rc, ClassLoader parentClassLoader)

public Script createScript(String scriptName, Binding binding)

Creates a Script with a given scriptName and binding.

throws:
ResourceException if there is a problem accessing the script
throws:
ScriptException if there is a problem parsing the script
Parameters:
scriptName - name of the script to run
binding - the binding to pass to the script
Returns:
the script object

public CompilerConfiguration getConfig()

Returns:
a non null compiler configuration

protected long getCurrentTime()

public GroovyClassLoader getGroovyClassLoader()

Returns the GroovyClassLoader associated with this script engine instance. Useful if you need to pass the class loader to another library.

Returns:
the GroovyClassLoader

public ClassLoader getParentClassLoader()

Get the ClassLoader that will serve as the parent ClassLoader of the GroovyClassLoader in which scripts will be executed. By default, this is the ClassLoader that loaded the GroovyScriptEngine class.

Returns:
the parent classloader used to load scripts

public URLConnection getResourceConnection(String resourceName)

Get a resource connection as a URLConnection to retrieve a script from the ResourceConnector.

throws:
ResourceException
Parameters:
resourceName - name of the resource to be retrieved
Returns:
a URLConnection to the resource

protected boolean isSourceNewer(GroovyScriptEngine.ScriptCacheEntry entry)

public Class loadScriptByName(String scriptName)

Get the class of the scriptName in question, so that you can instantiate Groovy objects with caching and reloading.

throws:
ResourceException if there is a problem accessing the script
throws:
ScriptException if there is a problem parsing the script
Parameters:
scriptName - resource name pointing to the script
Returns:
the loaded scriptName as a compiled class

public static void main(String[] urls)

Simple testing harness for the GSE. Enter script roots as arguments and then input script names to run them.

throws:
Exception if something goes wrong
Parameters:
urls - an array of URLs

public String run(String scriptName, String argument)

Run a script identified by name with a single argument.

throws:
ResourceException if there is a problem accessing the script
throws:
ScriptException if there is a problem parsing the script
Parameters:
scriptName - name of the script to run
argument - a single argument passed as a variable named arg in the binding
Returns:
a toString() representation of the result of the execution of the script

public Object run(String scriptName, Binding binding)

Run a script identified by name with a given binding.

throws:
ResourceException if there is a problem accessing the script
throws:
ScriptException if there is a problem parsing the script
Parameters:
scriptName - name of the script to run
binding - the binding to pass to the script
Returns:
an object

public void setConfig(CompilerConfiguration config)

sets a compiler configuration

throws:
NullPointerException if config is null
Parameters:
config - - the compiler configuration

© 2003-2020 The Apache Software Foundation
Licensed under the Apache license.
https://docs.groovy-lang.org/2.4.21/html/gapi/groovy/util/GroovyScriptEngine.html