Class ScriptRunnerBase

java.lang.Object
org.apache.tools.ant.util.ScriptRunnerBase
Direct Known Subclasses:
JavaxScriptRunner, ScriptRunner

public abstract class ScriptRunnerBase
extends java.lang.Object
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 
    Constructor Description
    ScriptRunnerBase()  
  • Method Summary

    Modifier and Type Method Description
    void addBean​(java.lang.String key, java.lang.Object bean)
    Add a single object into the script context.
    void addBeans​(java.util.Map<java.lang.String,​?> dictionary)
    Add a list of named objects to the list to be exported to the script
    void addText​(java.lang.String text)
    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 checkLanguage()
    Check if the language attribute is set.
    void clearScript()
    Clear the current script text content.
    abstract java.lang.Object evaluateScript​(java.lang.String execName)
    Evaluate the script.
    abstract void executeScript​(java.lang.String execName)
    Do the work.
    protected java.util.Map<java.lang.String,​java.lang.Object> getBeans()
    Get the beans used for the script.
    boolean getCompiled()
    Get the compiled attribute.
    boolean getKeepEngine()
    Get the keep engine attribute.
    java.lang.String getLanguage()
    Get the script language
    abstract java.lang.String getManagerName()
    Get the name of the manager prefix used for this scriptrunner.
    Project getProject()
    Get the project for this runner.
    java.lang.String getScript()
    Get the current script text content.
    protected java.lang.ClassLoader getScriptClassLoader()
    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 java.lang.ClassLoader replaceContextLoader()
    Replace the current context classloader with the script context classloader.
    protected void restoreContextLoader​(java.lang.ClassLoader origLoader)
    Restore the context loader with the original context classloader.
    void setCompiled​(boolean compiled)
    Whether to use script compilation if available.
    void setEncoding​(java.lang.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​(java.lang.String language)
    Defines the language (required).
    void setProject​(Project project)
    Set the project for this runner.
    void setScriptClassLoader​(java.lang.ClassLoader classLoader)
    Set the script classloader.
    void setSrc​(java.io.File file)
    Load the script from an external file; optional.
    abstract boolean supportsLanguage()
    Check if a script engine can be created for this language.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • addBeans

      public void addBeans​(java.util.Map<java.lang.String,​?> dictionary)
      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

      public void addBean​(java.lang.String key, java.lang.Object bean)
      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

      protected java.util.Map<java.lang.String,​java.lang.Object> getBeans()
      Get the beans used for the script.
      Returns:
      the map of beans.
    • executeScript

      public abstract void executeScript​(java.lang.String execName)
      Do the work.
      Parameters:
      execName - the name that will be passed to BSF for this script execution.
    • evaluateScript

      public abstract java.lang.Object evaluateScript​(java.lang.String execName)
      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

      public abstract java.lang.String getManagerName()
      Get the name of the manager prefix used for this scriptrunner.
      Returns:
      the prefix string.
    • setLanguage

      public void setLanguage​(java.lang.String language)
      Defines the language (required).
      Parameters:
      language - the scripting language name for the script.
    • getLanguage

      public java.lang.String getLanguage()
      Get the script language
      Returns:
      the script language
    • setScriptClassLoader

      public void setScriptClassLoader​(java.lang.ClassLoader classLoader)
      Set the script classloader.
      Parameters:
      classLoader - the classloader to use.
    • getScriptClassLoader

      protected java.lang.ClassLoader 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

      public void setEncoding​(java.lang.String encoding)
      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

      public void setSrc​(java.io.File file)
      Load the script from an external file; optional.
      Parameters:
      file - the file containing the script source.
    • loadResource

      public void loadResource​(Resource sourceResource)
      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

      public void loadResources​(ResourceCollection collection)
      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

      public void addText​(java.lang.String text)
      Set the script text. Properties in the text are not expanded!
      Parameters:
      text - a component of the script text to be added.
    • getScript

      public java.lang.String getScript()
      Get the current script text content.
      Returns:
      the script text.
    • clearScript

      public void clearScript()
      Clear the current script text content.
    • setProject

      public void setProject​(Project project)
      Set the project for this runner.
      Parameters:
      project - the project.
    • getProject

      public Project getProject()
      Get the project for this runner.
      Returns:
      the project.
    • bindToComponent

      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 - to become self
    • bindToComponentMinimum

      public void bindToComponentMinimum​(ProjectComponent component)
      Bind the runner to a project component. The project and self are the only beans set.
      Parameters:
      component - to become self
    • checkLanguage

      protected void checkLanguage()
      Check if the language attribute is set.
      Throws:
      BuildException - if it is not.
    • replaceContextLoader

      protected java.lang.ClassLoader replaceContextLoader()
      Replace the current context classloader with the script context classloader.
      Returns:
      the current context classloader.
    • restoreContextLoader

      protected void restoreContextLoader​(java.lang.ClassLoader origLoader)
      Restore the context loader with the original context classloader. script context loader.
      Parameters:
      origLoader - the original context classloader.