public class EvalScriptEngine extends Object
Modifier and Type | Field and Description |
---|---|
protected ClassLoader |
classLoader |
protected ClassDirectory |
directory |
protected Properties |
properties |
protected groovy.lang.GroovyShell |
shell |
Constructor and Description |
---|
EvalScriptEngine()
Construct a new script engine.
|
EvalScriptEngine(ClassLoader loader)
Construct a new script engine.
|
EvalScriptEngine(ClassLoader loader,
Properties props)
Construct a new script engine.
|
Modifier and Type | Method and Description |
---|---|
EvalProject |
createProject()
Create a new eval project.
|
<T> Class<? extends org.apache.commons.lang3.builder.Builder> |
getBuilderForType(Class<T> type)
Get a command for a type.
|
protected void |
loadExternalMethods()
Register a default set of external methods.
|
EvalProject |
loadProject(File file)
Load a set of evaluations from a script file.
|
Object |
loadProject(Reader in)
Load a set of evaluations from an input stream.
|
Class<? extends org.apache.commons.lang3.builder.Builder> |
lookupBuilder(String name)
Find a builder with a particular name if it exists.
|
Class<?> |
lookupMethod(String name)
Look up a registered method of any type.
|
Class<? extends EvalTask> |
lookupTask(String name)
Find a task with a particular name if it exists.
|
<T> void |
registerCommand(Class<T> type,
Class<? extends org.apache.commons.lang3.builder.Builder> command)
Register a builder class for a type.
|
Object |
runScript(EvalScript script,
EvalProject project)
Run an evaluation config script and get the evaluations it produces.
|
Object |
runScript(File file,
EvalProject project)
Run a script from a file.
|
Object |
runScript(Reader in,
EvalProject project)
Run a script from a reader.
|
protected ClassLoader classLoader
protected ClassDirectory directory
protected groovy.lang.GroovyShell shell
@Nullable protected final Properties properties
public EvalScriptEngine()
public EvalScriptEngine(ClassLoader loader)
loader
- The class loader to use.public EvalScriptEngine(ClassLoader loader, @Nullable Properties props)
loader
- The class loader to use.props
- Additional properties to use when creating new projects.EvalProject.EvalProject(java.util.Properties)
public EvalProject createProject()
public Object runScript(File file, EvalProject project) throws IOException, TaskExecutionException
file
- The file to run.project
- The project to run the script against.IOException
- if the file cannot be read.TaskExecutionException
public Object runScript(Reader in, EvalProject project) throws IOException
in
- The reader to read.project
- The project to run the script against.IOException
@Nullable public Object runScript(EvalScript script, EvalProject project) throws TaskExecutionException
script
- The script to run (as loaded by Groovy)project
- The project to run the script on.TaskExecutionException
- if the script is invalid or produces an error.public EvalProject loadProject(File file) throws TaskExecutionException, IOException
file
- A Groovy script to configure the evaluator.TaskExecutionException
- if there is a configuration errorIOException
- if there is an error reading the filepublic Object loadProject(Reader in) throws TaskExecutionException, IOException
in
- The input streamTaskExecutionException
- if there is a configuration errorIOException
public Class<?> lookupMethod(@Nonnull String name)
name
- The method name.null
if it the method is not found.@CheckForNull @Nullable public Class<? extends EvalTask> lookupTask(@Nonnull String name)
name
- The name of the commandnull
if no such factory exists.@CheckForNull @Nullable public Class<? extends org.apache.commons.lang3.builder.Builder> lookupBuilder(@Nonnull String name)
name
- The name of the commandnull
if no such factory exists.public <T> Class<? extends org.apache.commons.lang3.builder.Builder> getBuilderForType(Class<T> type)
BuiltBy
annotation.type
- A type that needs to be built.type
, or null
if none can be found.registerCommand(java.lang.Class<T>, java.lang.Class<? extends org.apache.commons.lang3.builder.Builder>)
public <T> void registerCommand(Class<T> type, Class<? extends org.apache.commons.lang3.builder.Builder> command)
BuiltBy
annotation.T
- The type to build (type parameter).type
- The type to build.command
- A class that can build instances of type
.protected void loadExternalMethods()