org.cesta.taskdefs
Class TransformationTask

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by org.cesta.taskdefs.TransformationTask
All Implemented Interfaces:
java.lang.Cloneable

public class TransformationTask
extends org.apache.tools.ant.Task

TransformationTask ANT task. It provides simple interface for executing transformations. Core ANT types can be used (FileSet, Mapper, Path, Parameter) to easily configure transformations.

Author:
Tobias Smolka

Field Summary
 
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
TransformationTask()
           
 
Method Summary
 void add(org.apache.tools.ant.util.FileNameMapper fileNameMapper)
          Add a nested filenamemapper.
 void add(org.apache.tools.ant.types.ResourceCollection rc)
          Add resource collection
 void addConfiguredParam(Parameter param)
          Add a Parameter.
protected  void addMappedFile(java.io.File file)
          Simplyfied method for adding file without base directory
protected  void addMappedFile(java.io.File file, java.io.File baseDir)
          Protected method for simplyfied addinng of mapped files
 org.apache.tools.ant.types.Path createClasspath()
          The classpath to use when looking up a resource.
 org.apache.tools.ant.types.Mapper createMapper()
          Define the mapper to map source to destination files.
 void execute()
          Main entry point for this task.
 java.lang.String getClassname()
          Returns classname of transformation (simple or full classname)
 org.apache.tools.ant.types.Path getClasspath()
          Get the classpath used when looking up a resource.
 java.io.File getDestDir()
          Returns destination directory
 java.io.File getDestFile()
          Returns single destination file
 java.util.List<MappedFile> getMappedFiles()
          Returns list of mapped files, that should be transformed.
 java.io.File getSrcDir()
          Returns source directory
 java.io.File getSrcFile()
          Returns source file
 void init()
          Initialization of the task.
protected  void initClassloader()
          Initializes default class loader.
 boolean isFailonerror()
          Returns current value of failOnError flag.
protected  void restoreClassloader()
          Restores default class loader.
 void setClassname(java.lang.String classname)
          Sets classname of transformation (simple or full classname)
 void setClasspath(org.apache.tools.ant.types.Path classpath)
          The classpath to use when looking up a resource.
 void setClasspathRef(org.apache.tools.ant.types.Reference r)
          the classpath to use when looking up a resource, given as reference to a <path> defined elsewhere
 void setDestDir(java.io.File destDir)
          Sets destination directory
 void setDestFile(java.io.File destFile)
          Sets destination file
 void setFailonerror(boolean failOnError)
          Boolean to control whether failure to execute should throw a BuildException or just print an error.
 void setSrcDir(java.io.File srcDir)
          Sets source directory
 void setSrcFile(java.io.File srcFile)
          Sets source file
 
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, 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
 

Constructor Detail

TransformationTask

public TransformationTask()
Method Detail

addConfiguredParam

public void addConfiguredParam(Parameter param)
Add a Parameter.

Parameters:
param - a Parameter value

add

public void add(org.apache.tools.ant.types.ResourceCollection rc)
Add resource collection

Parameters:
rc - resource collection to add

setClasspath

public void setClasspath(org.apache.tools.ant.types.Path classpath)
The classpath to use when looking up a resource.

Parameters:
classpath - to add to any existing classpath

createClasspath

public org.apache.tools.ant.types.Path createClasspath()
The classpath to use when looking up a resource.

Returns:
a path to be configured

setClasspathRef

public void setClasspathRef(org.apache.tools.ant.types.Reference r)
the classpath to use when looking up a resource, given as reference to a <path> defined elsewhere

Parameters:
r - a reference to a classpath

getClasspath

public org.apache.tools.ant.types.Path getClasspath()
Get the classpath used when looking up a resource. Default classpath is base dir from project

Returns:
the classpath

createMapper

public org.apache.tools.ant.types.Mapper createMapper()
                                               throws org.apache.tools.ant.BuildException
Define the mapper to map source to destination files.

Returns:
a mapper to be configured.
Throws:
org.apache.tools.ant.BuildException - if more than one mapper is defined.

add

public void add(org.apache.tools.ant.util.FileNameMapper fileNameMapper)
Add a nested filenamemapper.

Parameters:
fileNameMapper - the mapper to add.

setFailonerror

public void setFailonerror(boolean failOnError)
Boolean to control whether failure to execute should throw a BuildException or just print an error.

Parameters:
failOnError -

isFailonerror

public boolean isFailonerror()
Returns current value of failOnError flag.

Returns:
failOnError flag

getDestDir

public java.io.File getDestDir()
Returns destination directory

Returns:
the destDir

setDestDir

public void setDestDir(java.io.File destDir)
Sets destination directory

Parameters:
destDir - the destDir to set

getDestFile

public java.io.File getDestFile()
Returns single destination file

Returns:
the destFile

setDestFile

public void setDestFile(java.io.File destFile)
Sets destination file

Parameters:
destFile - the destFile to set

getSrcDir

public java.io.File getSrcDir()
Returns source directory

Returns:
the srcDir

setSrcDir

public void setSrcDir(java.io.File srcDir)
Sets source directory

Parameters:
srcDir - the srcDir to set

getSrcFile

public java.io.File getSrcFile()
Returns source file

Returns:
the srcFile

setSrcFile

public void setSrcFile(java.io.File srcFile)
Sets source file

Parameters:
srcFile - the srcFile to set

getClassname

public java.lang.String getClassname()
Returns classname of transformation (simple or full classname)

Returns:
the classname

setClassname

public void setClassname(java.lang.String classname)
Sets classname of transformation (simple or full classname)

Parameters:
classname - the classname to set

initClassloader

protected void initClassloader()
Initializes default class loader. It inherits from classloader, which was used to load this task, therefore build-in classes and resources are loaded automatically. Notice: task's classpath has priority over default classpath, therefore we are able to easily override resources (templates)


restoreClassloader

protected void restoreClassloader()
Restores default class loader.


addMappedFile

protected void addMappedFile(java.io.File file,
                             java.io.File baseDir)
Protected method for simplyfied addinng of mapped files

Parameters:
file - file to add
baseDir - base directory for file

addMappedFile

protected void addMappedFile(java.io.File file)
Simplyfied method for adding file without base directory

Parameters:
file - file to add

getMappedFiles

public java.util.List<MappedFile> getMappedFiles()
Returns list of mapped files, that should be transformed. Files can by specified via attributes (srcFile, srcDir) or resources (FileSet, FileList, DirSet, etc). Mapped file represents input and output file for transformation.

Returns:
list of mapped files

init

public void init()
          throws org.apache.tools.ant.BuildException
Initialization of the task.

Overrides:
init in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException - in case an error occured

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Main entry point for this task. It creates transformation specified by classname attribute, passes all parameters and executes it.

Overrides:
execute in class org.apache.tools.ant.Task
Throws:
org.apache.tools.ant.BuildException - if an error occured