FileDocCategorySizeDatePackage
ScriptRunnerHelper.javaAPI DocApache Ant 1.705496Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.util

ScriptRunnerHelper

public class ScriptRunnerHelper extends Object
A class to help in creating, setting and getting script runners.

Fields Summary
private ClasspathUtils.Delegate
cpDelegate
private File
srcFile
private String
manager
private String
language
private String
text
private boolean
setBeans
private org.apache.tools.ant.ProjectComponent
projectComponent
private ClassLoader
scriptLoader
Constructors Summary
Methods Summary
public voidaddText(java.lang.String text)
The script text.

param
text a component of the script text to be added.

        this.text = text;
    
public org.apache.tools.ant.types.PathcreateClasspath()
Classpath to be used when searching for classes and resources.

return
an empty Path instance to be configured by Ant.

        return getClassPathDelegate().createClasspath();
    
private java.lang.ClassLoadergenerateClassLoader()

        if (scriptLoader != null) {
            return scriptLoader;
        }
        if (cpDelegate == null) {
            scriptLoader = getClass().getClassLoader();
            return scriptLoader;
        }

        scriptLoader = cpDelegate.getClassLoader();
        return scriptLoader;
    
private ClasspathUtils.DelegategetClassPathDelegate()

        if (cpDelegate == null) {
            cpDelegate = ClasspathUtils.getDelegate(projectComponent);
        }
        return cpDelegate;
    
public java.lang.StringgetLanguage()
Get the language.

return
the scripting language.

        return language;
    
private ScriptRunnerBasegetRunner()
Get a script runner.

        return new ScriptRunnerCreator(
            projectComponent.getProject()).createRunner(
                manager, language, generateClassLoader());
    
public ScriptRunnerBasegetScriptRunner()
Create and set text on a script.

return
the created or reused script runner.

        ScriptRunnerBase runner = getRunner();
        if (srcFile != null) {
            runner.setSrc(srcFile);
        }
        if (text != null) {
            runner.addText(text);
        }
        if (setBeans) {
            runner.bindToComponent(projectComponent);
        } else {
            runner.bindToComponentMinimum(projectComponent);
        }
        return runner;
    
public voidsetClassLoader(java.lang.ClassLoader loader)
Used when called by scriptdef.

param
loader the loader used by scriptdef.

        scriptLoader = loader;
    
public voidsetClasspath(org.apache.tools.ant.types.Path classpath)
Set the classpath to be used when searching for classes and resources.

param
classpath an Ant Path object containing the search path.

        getClassPathDelegate().setClasspath(classpath);
    
public voidsetClasspathRef(org.apache.tools.ant.types.Reference r)
Set the classpath by reference.

param
r a Reference to a Path instance to be used as the classpath value.

        getClassPathDelegate().setClasspathref(r);
    
public voidsetLanguage(java.lang.String language)
Defines the language (required).

param
language the scripting language name for the script.

        this.language = language;
    
public voidsetManager(java.lang.String manager)
Defines the script manager - defaults to "auto".

param
manager the scripting manager - "bsf" or "javax" or "auto"

        this.manager = manager;
    
public voidsetProjectComponent(org.apache.tools.ant.ProjectComponent component)
Set the project component associated with this helper.

param
component the project component that owns this helper.


                          
        
        this.projectComponent = component;
    
public voidsetSetBeans(boolean setBeans)
Set the setbeans attribute. If this is true, <script> will create variables in the script instance for all properties, targets and references of the current project. It this is false, only the project and self variables will be set. The default is true.

param
setBeans the value to set.

        this.setBeans = setBeans;
    
public voidsetSrc(java.io.File file)
Load the script from an external file ; optional.

param
file the file containing the script source.

        this.srcFile = file;