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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a single object into the script context.void
Add a list of named objects to the list to be exported to the scriptvoid
Set the script text.void
bindToComponent
(ProjectComponent component) Bind the runner to a project component.void
bindToComponentMinimum
(ProjectComponent component) Bind the runner to a project component.protected void
Check if the language attribute is set.void
Clear the current script text content.abstract Object
evaluateScript
(String execName) Evaluate the script.abstract void
executeScript
(String execName) Do the work.getBeans()
Get the beans used for the script.final boolean
Get the compiled attribute.boolean
Get the keep engine attribute.Get the script languageabstract String
Get the name of the manager prefix used for this scriptrunner.Get the project for this runner.Get the current script text content.protected ClassLoader
Get the classloader used to load the script engine.void
loadResource
(Resource sourceResource) Add a resource to the source list.void
loadResources
(ResourceCollection collection) Add all resources in a resource collection to the source list.protected ClassLoader
Replace the current context classloader with the script context classloader.protected void
restoreContextLoader
(ClassLoader origLoader) Restore the context loader with the original context classloader.final void
setCompiled
(boolean compiled) Whether to use script compilation if available.void
setEncoding
(String encoding) Set encoding of the script from an external file; optional.void
setKeepEngine
(boolean keepEngine) Whether to keep the script engine between calls.void
setLanguage
(String language) Defines the language (required).void
setProject
(Project project) Set the project for this runner.void
setScriptClassLoader
(ClassLoader classLoader) Set the script classloader.void
Load the script from an external file; optional.abstract boolean
Check if a script engine can be created for this language.
-
Constructor Details
-
ScriptRunnerBase
public ScriptRunnerBase()
-
-
Method Details
-
addBeans
-
addBean
-
getBeans
-
executeScript
Do the work.- Parameters:
execName
- the name that will be passed to BSF for this script execution.
-
evaluateScript
-
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
-
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
-
clearScript
public void clearScript()Clear the current script text content. -
setProject
Set the project for this runner.- Parameters:
project
- the project.
-
getProject
-
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.
-