Class TexenTask
- All Implemented Interfaces:
Cloneable
- Version:
- $Id: TexenTask.java 463298 2006-10-12 16:10:32Z henning $
- Author:
- Jason van Zyl, Robert Burrell Donkin
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.commons.collections.ExtendedPropertiesThese are properties that are fed into the initial context from a properties file.protected StringThis is the control template that governs the output.protected StringThis is the encoding for the input file(s) (templates).protected StringThe LogFile (incl.protected StringThis is where texen will place all the output that is a product of the generation process.protected StringThis is the encoding for the output file(s).protected StringThis is the file where the generated text will be placed.protected Stringprotected StringThis is where Velocity will look for templates using the file template loader.protected booleanProperty which controls whether the classpath will be used when trying to locate templates.protected StringProperty which controls whether the resource loader will be told to cache.Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapperFields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcleanup()A hook method called at the end ofexecute()which can be overridden to perform any necessary cleanup activities (such as the release of database connections, etc.).voidexecute()Execute the input script with Velocityorg.apache.commons.collections.ExtendedPropertiesGet 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 voidpopulateInitialContext(Context context) Place useful objects into the initial context.voidsetContextProperties(String file) Set the context properties that will be fed into the initial context be the generating process starts.voidsetControlTemplate(String controlTemplate) [REQUIRED] Set the control template for the generating process.voidsetInputEncoding(String inputEncoding) Set the input (template) encoding.voidsetLogFile(String log) Sets the log file.voidsetOutputDirectory(File outputDirectory) [REQUIRED] Set the output directory.voidsetOutputEncoding(String outputEncoding) Set the output encoding.voidsetOutputFile(String outputFile) [REQUIRED] Set the output file for the generation process.voidsetResourceLoaderModificationCheckInterval(String resourceLoaderModificationCheckInterval) voidsetTemplatePath(String templatePath) [REQUIRED] Set the path where Velocity will look for templates using the file template loader.voidsetUseClasspath(boolean useClasspath) Set the use of the classpath in locating templatesvoidsetUseResourceLoaderCache(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, setTaskTypeMethods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
-
Field Details
-
controlTemplate
This is the control template that governs the output. It may or may not invoke the services of worker templates. -
templatePath
This is where Velocity will look for templates using the file template loader. -
outputDirectory
This is where texen will place all the output that is a product of the generation process. -
outputFile
This is the file where the generated text will be placed. -
outputEncoding
This is the encoding for the output file(s). -
inputEncoding
This is the encoding for the input file(s) (templates). -
contextProperties
protected org.apache.commons.collections.ExtendedProperties contextPropertiesThese 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
$databaseNameto be placed in the initial context so that it is available in a script that might look something like the following:The value of#!bin/sh echo y | mysqladmin create $databaseName
$databaseNameisn'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 useClasspathProperty which controls whether the classpath will be used when trying to locate templates. -
logFile
The LogFile (incl. path) to log to. -
useResourceLoaderCache
Property which controls whether the resource loader will be told to cache. Default false -
resourceLoaderModificationCheckInterval
-
-
Constructor Details
-
TexenTask
public TexenTask()
-
-
Method Details
-
setControlTemplate
[REQUIRED] Set the control template for the generating process.- Parameters:
controlTemplate-
-
getControlTemplate
Get the control template for the generating process.- Returns:
- The current control template.
-
setTemplatePath
[REQUIRED] Set the path where Velocity will look for templates using the file template loader.- Parameters:
templatePath-- Throws:
Exception
-
getTemplatePath
Get the path where Velocity will look for templates using the file template loader.- Returns:
- The template path.
-
setOutputDirectory
[REQUIRED] Set the output directory. It will be created if it doesn't exist.- Parameters:
outputDirectory-
-
getOutputDirectory
Get the output directory.- Returns:
- The output directory.
-
setOutputFile
[REQUIRED] Set the output file for the generation process.- Parameters:
outputFile-
-
setOutputEncoding
Set the output encoding.- Parameters:
outputEncoding-
-
setInputEncoding
Set the input (template) encoding.- Parameters:
inputEncoding-
-
getOutputFile
Get the output file for the generation process.- Returns:
- The output file.
-
setLogFile
Sets the log file.- Parameters:
log-
-
getLogFile
Gets the log file.- Returns:
- The log file.
-
setContextProperties
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
- Parameters:
useResourceLoaderCache-
-
setResourceLoaderModificationCheckInterval
public void setResourceLoaderModificationCheckInterval(String resourceLoaderModificationCheckInterval) - Parameters:
resourceLoaderModificationCheckInterval-
-
initControlContext
Creates a VelocityContext.- Returns:
- new Context
- Throws:
Exception- the execute method will catch and rethrow as aBuildException
-
execute
public void execute() throws org.apache.tools.ant.BuildExceptionExecute the input script with Velocity- Overrides:
executein classorg.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
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.$generatoris not put into the context in this method.- Parameters:
context- The context to populate, as retrieved frominitControlContext().- Throws:
Exception- Error while populating context. Theexecute()method will catch and rethrow as aBuildException.
-
cleanup
A hook method called at the end ofexecute()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.
-