Top Description Fields Constructors Methods
org.apache.tools.ant.util

public abstract Class ScriptRunnerBase

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.tools.ant.util.optional.JavaxScriptRunner
Imports
java.io.BufferedReader, .File, .IOException, .InputStream, .InputStreamReader, .Reader, java.nio.charset.Charset, java.nio.file.Files, java.util.HashMap, .Map, org.apache.tools.ant.BuildException, .Project, .ProjectComponent, org.apache.tools.ant.types.Resource, .ResourceCollection, org.apache.tools.ant.types.resources.PropertyResource, .StringResource

This is a common abstract base case for script runners. These classes need to implement executeScript, evaluateScript and supportsLanguage.
Since
Ant 1.7.0

Field Summary

Modifier and TypeField and Description
private final Map<String, Object>
beans

Beans to be provided to the script

private boolean
compiled

Enable script compilation.

private String
private boolean
keepEngine

Whether to keep the engine between calls to execute/eval

private String
language

Script language

private Project
project

Project this runner is used in

private String
script

Script content

private ClassLoader
scriptLoader

Classloader to be used when running the script.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addBean(String
the name in the context this object is to stored under.
key
,
Object
the object to be stored in the script context.
bean
)

Add a single object into the script context.

public void
addBeans(Map<String, ?>
a map of objects to be placed into the script context indexed by String names.
dictionary
)

Add a list of named objects to the list to be exported to the script

public void
addText(String
a component of the script text to be added.
text
)

Set the script text.

public void
bindToComponent(ProjectComponent
to become self
component
)

Bind the runner to a project component.

public void
bindToComponentMinimum(ProjectComponent
to become self
component
)

Bind the runner to a project component.

protected void
checkLanguage()

Check if the language attribute is set.

public void
clearScript()

Clear the current script text content.

public abstract Object

Returns:

the result of evaluating the script.
evaluateScript
(String
the name that will be passed to the scripting engine for this script execution.
execName
)

Evaluate the script.

public abstract void
executeScript(String
the name that will be passed to BSF for this script execution.
execName
)

Do the work.

protected Map<String, Object>

Returns:

the map of beans.
getBeans
()

Get the beans used for the script.

public final boolean

Returns:

the attribute.
getCompiled
()

Get the compiled attribute.

public boolean

Returns:

the attribute.
getKeepEngine
()

Get the keep engine attribute.

public String

Returns:

the script language
getLanguage
()

Get the script language

public abstract String

Returns:

the prefix string.
getManagerName
()

Get the name of the manager prefix used for this scriptrunner.

public Project

Returns:

the project.
getProject
()

Get the project for this runner.

public String

Returns:

the script text.
getScript
()

Get the current script text content.

protected ClassLoader

Returns:

the classloader.
getScriptClassLoader
()

Get the classloader used to load the script engine.

public void
loadResource(Resource
the resource to load
sourceResource
)

Add a resource to the source list.

public void
loadResources(ResourceCollection
the resource to load
collection
)

Add all resources in a resource collection to the source list.

private void
readSource(InputStream
the input stream to pass into a buffered reader.
in
,
String
the name to use in error messages
name
,
Charset
the encoding for the reader, may be null.
charset
)

Read some source in from the given reader

protected ClassLoader

Returns:

the current context classloader.
replaceContextLoader
()

Replace the current context classloader with the script context classloader.

protected void
restoreContextLoader(ClassLoader
the original context classloader.
origLoader
)

Restore the context loader with the original context classloader.

public final void
setCompiled(boolean
if true, compile the script if possible.
compiled
)

Whether to use script compilation if available.

public void
setEncoding(String
encoding of the external file containing the script source.
encoding
)

Set encoding of the script from an external file; optional.

public void
setKeepEngine(boolean
if true, keep the engine.
keepEngine
)

Whether to keep the script engine between calls.

public void
setLanguage(String
the scripting language name for the script.
language
)

Defines the language (required).

public void
setProject(Project
the project.
project
)

Set the project for this runner.

public void
setScriptClassLoader(ClassLoader
the classloader to use.
classLoader
)

Set the script classloader.

public void
setSrc(File
the file containing the script source.
file
)

Load the script from an external file; optional.

public abstract boolean

Returns:

true if a script engine can be created, false otherwise.
supportsLanguage
()

Check if a script engine can be created for this language.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beansback to summary
private final Map<String, Object> beans

Beans to be provided to the script

compiledback to summary
private boolean compiled

Enable script compilation.

encodingback to summary
private String encoding
keepEngineback to summary
private boolean keepEngine

Whether to keep the engine between calls to execute/eval

languageback to summary
private String language

Script language

projectback to summary
private Project project

Project this runner is used in

scriptback to summary
private String script

Script content

scriptLoaderback to summary
private ClassLoader scriptLoader

Classloader to be used when running the script.

Constructor Detail

ScriptRunnerBaseback to summary
public ScriptRunnerBase()

Method Detail

addBeanback to summary
public void addBean(String key, Object bean)

Add a single object into the script context.

Parameters
key:String

the name in the context this object is to stored under.

bean:Object

the object to be stored in the script context.

addBeansback to summary
public void addBeans(Map<String, ?> dictionary)

Add a list of named objects to the list to be exported to the script

Parameters
dictionary:Map<String, ?>

a map of objects to be placed into the script context indexed by String names.

addTextback to summary
public void addText(String text)

Set the script text. Properties in the text are not expanded!

Parameters
text:String

a component of the script text to be added.

bindToComponentback to summary
public void bindToComponent(ProjectComponent component)

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:ProjectComponent

to become self

bindToComponentMinimumback to summary
public void bindToComponentMinimum(ProjectComponent component)

Bind the runner to a project component. The project and self are the only beans set.

Parameters
component:ProjectComponent

to become self

checkLanguageback to summary
protected void checkLanguage()

Check if the language attribute is set.

Exceptions
BuildException:
if it is not.
clearScriptback to summary
public void clearScript()

Clear the current script text content.

evaluateScriptback to summary
public abstract Object evaluateScript(String execName)

Evaluate the script.

Parameters
execName:String

the name that will be passed to the scripting engine for this script execution.

Returns:Object

the result of evaluating the script.

executeScriptback to summary
public abstract void executeScript(String execName)

Do the work.

Parameters
execName:String

the name that will be passed to BSF for this script execution.

getBeansback to summary
protected Map<String, Object> getBeans()

Get the beans used for the script.

Returns:Map<String, Object>

the map of beans.

getCompiledback to summary
public final boolean getCompiled()

Get the compiled attribute.

Returns:boolean

the attribute.

Since
Ant 1.10.2
getKeepEngineback to summary
public boolean getKeepEngine()

Get the keep engine attribute.

Returns:boolean

the attribute.

getLanguageback to summary
public String getLanguage()

Get the script language

Returns:String

the script language

getManagerNameback to summary
public abstract String getManagerName()

Get the name of the manager prefix used for this scriptrunner.

Returns:String

the prefix string.

getProjectback to summary
public Project getProject()

Get the project for this runner.

Returns:Project

the project.

getScriptback to summary
public String getScript()

Get the current script text content.

Returns:String

the script text.

getScriptClassLoaderback to summary
protected ClassLoader getScriptClassLoader()

Get the classloader used to load the script engine.

Returns:ClassLoader

the classloader.

loadResourceback to summary
public void loadResource(Resource sourceResource)

Add a resource to the source list.

Parameters
sourceResource:Resource

the resource to load

Exceptions
BuildException:
if the resource cannot be read
Since
Ant 1.7.1
loadResourcesback to summary
public void loadResources(ResourceCollection collection)

Add all resources in a resource collection to the source list.

Parameters
collection:ResourceCollection

the resource to load

Exceptions
BuildException:
if a resource cannot be read
Since
Ant 1.7.1
readSourceback to summary
private void readSource(InputStream in, String name, Charset charset)

Read some source in from the given reader

Parameters
in:InputStream

the input stream to pass into a buffered reader.

name:String

the name to use in error messages

charset:Charset

the encoding for the reader, may be null.

replaceContextLoaderback to summary
protected ClassLoader replaceContextLoader()

Replace the current context classloader with the script context classloader.

Returns:ClassLoader

the current context classloader.

restoreContextLoaderback to summary
protected void restoreContextLoader(ClassLoader origLoader)

Restore the context loader with the original context classloader. script context loader.

Parameters
origLoader:ClassLoader

the original context classloader.

setCompiledback to summary
public final void setCompiled(boolean compiled)

Whether to use script compilation if available.

Parameters
compiled:boolean

if true, compile the script if possible.

Since
Ant 1.10.2
setEncodingback to summary
public void setEncoding(String encoding)

Set encoding of the script from an external file; optional.

Parameters
encoding:String

encoding of the external file containing the script source.

Since
Ant 1.10.2
setKeepEngineback to summary
public void setKeepEngine(boolean keepEngine)

Whether to keep the script engine between calls.

Parameters
keepEngine:boolean

if true, keep the engine.

setLanguageback to summary
public void setLanguage(String language)

Defines the language (required).

Parameters
language:String

the scripting language name for the script.

setProjectback to summary
public void setProject(Project project)

Set the project for this runner.

Parameters
project:Project

the project.

setScriptClassLoaderback to summary
public void setScriptClassLoader(ClassLoader classLoader)

Set the script classloader.

Parameters
classLoader:ClassLoader

the classloader to use.

setSrcback to summary
public void setSrc(File file)

Load the script from an external file; optional.

Parameters
file:File

the file containing the script source.

supportsLanguageback to summary
public abstract boolean supportsLanguage()

Check if a script engine can be created for this language.

Returns:boolean

true if a script engine can be created, false otherwise.