Methods Summary |
---|
public void | addBean(java.lang.String key, java.lang.Object bean)Add a single object into the script context.
boolean isValid = key.length() > 0
&& Character.isJavaIdentifierStart(key.charAt(0));
for (int i = 1; isValid && i < key.length(); i++) {
isValid = Character.isJavaIdentifierPart(key.charAt(i));
}
if (isValid) {
beans.put(key, bean);
}
|
public void | addBeans(java.util.Map dictionary)Add a list of named objects to the list to be exported to the script
for (Iterator i = dictionary.keySet().iterator(); i.hasNext();) {
String key = (String) i.next();
try {
Object val = dictionary.get(key);
addBean(key, val);
} catch (BuildException ex) {
// The key is in the dictionary but cannot be retrieved
// This is usually due references that refer to tasks
// that have not been taskdefed in the current run.
// Ignore
}
}
|
public void | addText(java.lang.String text)Set the script text.
this.script += text;
|
public void | bindToComponent(org.apache.tools.ant.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.
project = component.getProject();
addBeans(project.getProperties());
addBeans(project.getUserProperties());
addBeans(project.getTargets());
addBeans(project.getReferences());
addBean("project", project);
addBean("self", component);
|
public void | bindToComponentMinimum(org.apache.tools.ant.ProjectComponent component)Bind the runner to a project component.
The project and self are the only beans set.
project = component.getProject();
addBean("project", project);
addBean("self", component);
|
protected void | checkLanguage()Check if the language attribute is set.
if (language == null) {
throw new BuildException(
"script language must be specified");
}
|
public void | clearScript()Clear the current script text content.
this.script = "";
|
public abstract java.lang.Object | evaluateScript(java.lang.String execName)Evalulate the script.
|
public abstract void | executeScript(java.lang.String execName)Do the work.
|
protected java.util.Map | getBeans()Get the beans used for the script.
return beans;
|
public boolean | getKeepEngine()Get the keep engine attribute.
return keepEngine;
|
public java.lang.String | getLanguage()Get the script language
return language;
|
public abstract java.lang.String | getManagerName()Get the name of the manager prefix used for this
scriptrunner.
|
public org.apache.tools.ant.Project | getProject()Get the project for this runner.
return project;
|
public java.lang.String | getScript()Get the current script text content.
return script;
|
protected java.lang.ClassLoader | getScriptClassLoader()Get the classloader used to load the script engine.
return scriptLoader;
|
protected java.lang.ClassLoader | replaceContextLoader()Replace the current context classloader with the
script context classloader.
ClassLoader origContextClassLoader =
Thread.currentThread().getContextClassLoader();
if (getScriptClassLoader() == null) {
setScriptClassLoader(getClass().getClassLoader());
}
Thread.currentThread().setContextClassLoader(getScriptClassLoader());
return origContextClassLoader;
|
protected void | restoreContextLoader(java.lang.ClassLoader origLoader)Restore the context loader with the original context classloader.
script context loader.
Thread.currentThread().setContextClassLoader(
origLoader);
|
public void | setKeepEngine(boolean keepEngine)Whether to keep the script engine between calls.
this.keepEngine = keepEngine;
|
public void | setLanguage(java.lang.String language)Defines the language (required).
this.language = language;
|
public void | setProject(org.apache.tools.ant.Project project)Set the project for this runner.
this.project = project;
|
public void | setScriptClassLoader(java.lang.ClassLoader classLoader)Set the script classloader.
this.scriptLoader = classLoader;
|
public void | setSrc(java.io.File file)Load the script from an external file; optional.
if (!file.exists()) {
throw new BuildException("file " + file.getPath() + " not found.");
}
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(file));
script += FileUtils.readFully(in);
} catch (IOException ex) {
throw new BuildException(ex);
} finally {
FileUtils.close(in);
}
|
public abstract boolean | supportsLanguage()Check if a script engine can be created for
this language.
|