Package org.apache.tools.ant.util
Class ScriptRunnerBase
java.lang.Object
org.apache.tools.ant.util.ScriptRunnerBase
- Direct Known Subclasses:
JavaxScriptRunner,ScriptRunner
This is a common abstract base case for script runners.
These classes need to implement executeScript, evaluateScript
and supportsLanguage.
- Since:
- Ant 1.7.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a single object into the script context.voidAdd a list of named objects to the list to be exported to the scriptvoidSet the script text.voidbindToComponent(ProjectComponent component) Bind the runner to a project component.voidbindToComponentMinimum(ProjectComponent component) Bind the runner to a project component.protected voidCheck if the language attribute is set.voidClear the current script text content.abstract ObjectevaluateScript(String execName) Evaluate the script.abstract voidexecuteScript(String execName) Do the work.getBeans()Get the beans used for the script.final booleanGet the compiled attribute.booleanGet the keep engine attribute.Get the script languageabstract StringGet the name of the manager prefix used for this scriptrunner.Get the project for this runner.Get the current script text content.protected ClassLoaderGet the classloader used to load the script engine.voidloadResource(Resource sourceResource) Add a resource to the source list.voidloadResources(ResourceCollection collection) Add all resources in a resource collection to the source list.protected ClassLoaderReplace the current context classloader with the script context classloader.protected voidrestoreContextLoader(ClassLoader origLoader) Restore the context loader with the original context classloader.final voidsetCompiled(boolean compiled) Whether to use script compilation if available.voidsetEncoding(String encoding) Set encoding of the script from an external file; optional.voidsetKeepEngine(boolean keepEngine) Whether to keep the script engine between calls.voidsetLanguage(String language) Defines the language (required).voidsetProject(Project project) Set the project for this runner.voidsetScriptClassLoader(ClassLoader classLoader) Set the script classloader.voidLoad the script from an external file; optional.abstract booleanCheck if a script engine can be created for this language.
-
Constructor Details
-
ScriptRunnerBase
public ScriptRunnerBase()
-
-
Method Details
-
addBeans
Add a list of named objects to the list to be exported to the script- Parameters:
dictionary- a map of objects to be placed into the script context indexed by String names.
-
addBean
Add a single object into the script context.- Parameters:
key- the name in the context this object is to stored under.bean- the object to be stored in the script context.
-
getBeans
Get the beans used for the script.- Returns:
- the map of beans.
-
executeScript
Do the work.- Parameters:
execName- the name that will be passed to BSF for this script execution.
-
evaluateScript
Evaluate the script.- Parameters:
execName- the name that will be passed to the scripting engine for this script execution.- Returns:
- the result of evaluating the script.
-
supportsLanguage
public abstract boolean supportsLanguage()Check if a script engine can be created for this language.- Returns:
- true if a script engine can be created, false otherwise.
-
getManagerName
Get the name of the manager prefix used for this scriptrunner.- Returns:
- the prefix string.
-
setLanguage
Defines the language (required).- Parameters:
language- the scripting language name for the script.
-
getLanguage
Get the script language- Returns:
- the script language
-
setScriptClassLoader
Set the script classloader.- Parameters:
classLoader- the classloader to use.
-
getScriptClassLoader
Get the classloader used to load the script engine.- Returns:
- the classloader.
-
setKeepEngine
public void setKeepEngine(boolean keepEngine) Whether to keep the script engine between calls.- Parameters:
keepEngine- if true, keep the engine.
-
getKeepEngine
public boolean getKeepEngine()Get the keep engine attribute.- Returns:
- the attribute.
-
setCompiled
public final void setCompiled(boolean compiled) Whether to use script compilation if available.- Parameters:
compiled- if true, compile the script if possible.- Since:
- Ant 1.10.2
-
getCompiled
public final boolean getCompiled()Get the compiled attribute.- Returns:
- the attribute.
- Since:
- Ant 1.10.2
-
setEncoding
Set encoding of the script from an external file; optional.- Parameters:
encoding- encoding of the external file containing the script source.- Since:
- Ant 1.10.2
-
setSrc
Load the script from an external file; optional.- Parameters:
file- the file containing the script source.
-
loadResource
Add a resource to the source list.- Parameters:
sourceResource- the resource to load- Throws:
BuildException- if the resource cannot be read- Since:
- Ant 1.7.1
-
loadResources
Add all resources in a resource collection to the source list.- Parameters:
collection- the resource to load- Throws:
BuildException- if a resource cannot be read- Since:
- Ant 1.7.1
-
addText
Set the script text. Properties in the text are not expanded!- Parameters:
text- a component of the script text to be added.
-
getScript
Get the current script text content.- Returns:
- the script text.
-
clearScript
public void clearScript()Clear the current script text content. -
setProject
Set the project for this runner.- Parameters:
project- the project.
-
getProject
Get the project for this runner.- Returns:
- the project.
-
bindToComponent
Bind the runner to a project component. Properties, targets and references are all added as beans; project is bound to project, and self to the component.- Parameters:
component- to becomeself
-
bindToComponentMinimum
Bind the runner to a project component. The project and self are the only beans set.- Parameters:
component- to becomeself
-
checkLanguage
protected void checkLanguage()Check if the language attribute is set.- Throws:
BuildException- if it is not.
-
replaceContextLoader
Replace the current context classloader with the script context classloader.- Returns:
- the current context classloader.
-
restoreContextLoader
Restore the context loader with the original context classloader. script context loader.- Parameters:
origLoader- the original context classloader.
-