Class TexenTask

java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.velocity.texen.ant.TexenTask
All Implemented Interfaces:
Cloneable

public class TexenTask extends org.apache.tools.ant.Task
An ant task for generating output by using Velocity
Version:
$Id: TexenTask.java 463298 2006-10-12 16:10:32Z henning $
Author:
Jason van Zyl, Robert Burrell Donkin
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.apache.commons.collections.ExtendedProperties
    These are properties that are fed into the initial context from a properties file.
    protected String
    This is the control template that governs the output.
    protected String
    This is the encoding for the input file(s) (templates).
    protected String
    The LogFile (incl.
    protected String
    This is where texen will place all the output that is a product of the generation process.
    protected String
    This is the encoding for the output file(s).
    protected String
    This is the file where the generated text will be placed.
    protected String
     
    protected String
    This is where Velocity will look for templates using the file template loader.
    protected boolean
    Property which controls whether the classpath will be used when trying to locate templates.
    protected String
    Property which controls whether the resource loader will be told to cache.

    Fields inherited from class org.apache.tools.ant.Task

    target, taskName, taskType, wrapper

    Fields inherited from class org.apache.tools.ant.ProjectComponent

    description, location, project
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    A hook method called at the end of execute() which can be overridden to perform any necessary cleanup activities (such as the release of database connections, etc.).
    void
    Execute the input script with Velocity
    org.apache.commons.collections.ExtendedProperties
    Get the context properties that will be fed into the initial context be the generating process starts.
    Get the control template for the generating process.
    Gets the log file.
    Get the output directory.
    Get the output file for the generation process.
    Get the path where Velocity will look for templates using the file template loader.
    Creates a VelocityContext.
    protected void
    Place useful objects into the initial context.
    void
    Set the context properties that will be fed into the initial context be the generating process starts.
    void
    setControlTemplate(String controlTemplate)
    [REQUIRED] Set the control template for the generating process.
    void
    setInputEncoding(String inputEncoding)
    Set the input (template) encoding.
    void
    Sets the log file.
    void
    setOutputDirectory(File outputDirectory)
    [REQUIRED] Set the output directory.
    void
    setOutputEncoding(String outputEncoding)
    Set the output encoding.
    void
    setOutputFile(String outputFile)
    [REQUIRED] Set the output file for the generation process.
    void
    setResourceLoaderModificationCheckInterval(String resourceLoaderModificationCheckInterval)
     
    void
    setTemplatePath(String templatePath)
    [REQUIRED] Set the path where Velocity will look for templates using the file template loader.
    void
    setUseClasspath(boolean useClasspath)
    Set the use of the classpath in locating templates
    void
    setUseResourceLoaderCache(String useResourceLoaderCache)
     

    Methods inherited from class org.apache.tools.ant.Task

    bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType

    Methods inherited from class org.apache.tools.ant.ProjectComponent

    clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • controlTemplate

      protected String controlTemplate
      This is the control template that governs the output. It may or may not invoke the services of worker templates.
    • templatePath

      protected String templatePath
      This is where Velocity will look for templates using the file template loader.
    • outputDirectory

      protected String outputDirectory
      This is where texen will place all the output that is a product of the generation process.
    • outputFile

      protected String outputFile
      This is the file where the generated text will be placed.
    • outputEncoding

      protected String outputEncoding
      This is the encoding for the output file(s).
    • inputEncoding

      protected String inputEncoding
      This is the encoding for the input file(s) (templates).
    • contextProperties

      protected org.apache.commons.collections.ExtendedProperties contextProperties

      These are properties that are fed into the initial context from a properties file. This is simply a convenient way to set some values that you wish to make available in the context.

      These values are not critical, like the template path or output path, but allow a convenient way to set a value that may be specific to a particular generation task.

      For example, if you are generating scripts to allow user to automatically create a database, then you might want the $databaseName to be placed in the initial context so that it is available in a script that might look something like the following:

       #!bin/sh
      
       echo y | mysqladmin create $databaseName
       
      The value of $databaseName isn't critical to output, and you obviously don't want to change the ant task to simply take a database name. So initial context values can be set with properties file.
    • useClasspath

      protected boolean useClasspath
      Property which controls whether the classpath will be used when trying to locate templates.
    • logFile

      protected String logFile
      The LogFile (incl. path) to log to.
    • useResourceLoaderCache

      protected String useResourceLoaderCache
      Property which controls whether the resource loader will be told to cache. Default false
    • resourceLoaderModificationCheckInterval

      protected String resourceLoaderModificationCheckInterval
  • Constructor Details

    • TexenTask

      public TexenTask()
  • Method Details

    • setControlTemplate

      public void setControlTemplate(String controlTemplate)
      [REQUIRED] Set the control template for the generating process.
      Parameters:
      controlTemplate -
    • getControlTemplate

      public String getControlTemplate()
      Get the control template for the generating process.
      Returns:
      The current control template.
    • setTemplatePath

      public void setTemplatePath(String templatePath) throws Exception
      [REQUIRED] Set the path where Velocity will look for templates using the file template loader.
      Parameters:
      templatePath -
      Throws:
      Exception
    • getTemplatePath

      public String getTemplatePath()
      Get the path where Velocity will look for templates using the file template loader.
      Returns:
      The template path.
    • setOutputDirectory

      public void setOutputDirectory(File outputDirectory)
      [REQUIRED] Set the output directory. It will be created if it doesn't exist.
      Parameters:
      outputDirectory -
    • getOutputDirectory

      public String getOutputDirectory()
      Get the output directory.
      Returns:
      The output directory.
    • setOutputFile

      public void setOutputFile(String outputFile)
      [REQUIRED] Set the output file for the generation process.
      Parameters:
      outputFile -
    • setOutputEncoding

      public void setOutputEncoding(String outputEncoding)
      Set the output encoding.
      Parameters:
      outputEncoding -
    • setInputEncoding

      public void setInputEncoding(String inputEncoding)
      Set the input (template) encoding.
      Parameters:
      inputEncoding -
    • getOutputFile

      public String getOutputFile()
      Get the output file for the generation process.
      Returns:
      The output file.
    • setLogFile

      public void setLogFile(String log)
      Sets the log file.
      Parameters:
      log -
    • getLogFile

      public String getLogFile()
      Gets the log file.
      Returns:
      The log file.
    • setContextProperties

      public void setContextProperties(String file)
      Set the context properties that will be fed into the initial context be the generating process starts.
      Parameters:
      file -
    • getContextProperties

      public org.apache.commons.collections.ExtendedProperties getContextProperties()
      Get the context properties that will be fed into the initial context be the generating process starts.
      Returns:
      The current context properties.
    • setUseClasspath

      public void setUseClasspath(boolean useClasspath)
      Set the use of the classpath in locating templates
      Parameters:
      useClasspath - true means the classpath will be used.
    • setUseResourceLoaderCache

      public void setUseResourceLoaderCache(String useResourceLoaderCache)
      Parameters:
      useResourceLoaderCache -
    • setResourceLoaderModificationCheckInterval

      public void setResourceLoaderModificationCheckInterval(String resourceLoaderModificationCheckInterval)
      Parameters:
      resourceLoaderModificationCheckInterval -
    • initControlContext

      public Context initControlContext() throws Exception
      Creates a VelocityContext.
      Returns:
      new Context
      Throws:
      Exception - the execute method will catch and rethrow as a BuildException
    • execute

      public void execute() throws org.apache.tools.ant.BuildException
      Execute the input script with Velocity
      Overrides:
      execute in class org.apache.tools.ant.Task
      Throws:
      org.apache.tools.ant.BuildException - BuildExceptions are thrown when required attributes are missing. Exceptions thrown by Velocity are rethrown as BuildExceptions.
    • populateInitialContext

      protected void populateInitialContext(Context context) throws Exception

      Place useful objects into the initial context.

      TexenTask places Date().toString() into the context as $now. Subclasses who want to vary the objects in the context should override this method.

      $generator is not put into the context in this method.

      Parameters:
      context - The context to populate, as retrieved from initControlContext().
      Throws:
      Exception - Error while populating context. The execute() method will catch and rethrow as a BuildException.
    • cleanup

      protected void cleanup() throws Exception
      A hook method called at the end of execute() which can be overridden to perform any necessary cleanup activities (such as the release of database connections, etc.). By default, does nothing.
      Throws:
      Exception - Problem cleaning up.