|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
net.uworks.andariel.Process
Task definition for an ANT task that process files, parsing established directives.
It will take all the parameters defined by the Ant Copy task (manual information), except for "filterset" and "filterchain".
The difference between the Process task and other pre-processing utilities for Java is that this task has been designed to be able to hide from the compiler, so, if used properly, it's still possible to compile the original source tree with whatever compiler we're using, and generate any necessary versions using this task. This can be useful when developing in a IDE, or also when it's absolutely necessary to remove certain code, which can be useful in, for instance, J2ME.
Each processing directive is defined inside a comment, followed by the escape sequence. The type of comment and the escape sequence to be used is defined in the call of the task. Currently, the available types are:
| Code | Sample |
| slash-asterisk | /* [...] */ |
| slash-slash | // [...] [EOL] |
| xml | <!-- [...] --> |
| hash | # [...] [EOL] |
| bracket | { [...] } |
| quote | ' [...] [EOL] |
| rem | rem [...] [EOL] |
| at | @ [...] [EOL] |
The escape sequence is "#" by default, so, when using the default settings, a directive would look like:
/*#echo propertyName */
The available directives are:
| Code | Argument | Description |
| echo | Property name (mandatory) | The specified Ant property is written into the processed file |
| include | File name (mandatory) | The specified file is inserted into the processed file |
| define | Property name (mandatory), equal sign and property value (optional) | Defines a new Ant property. If no value is specifed, the property will be initalized to empty string |
| comment | Comment type (optional) | The lines between this directive and the next "endcomment" directive are commented using the specified comment type, which take one of the values of the last table. If no type is defined, it will use the current task type |
| endcomment | None | End the comment process |
| uncomment | Comment type (optional) | The lines between this directive and the next "endcomment" directive are uncommented using the specified comment type, which take one of the values of the last table. If no type is defined, it will use the current task type |
| enduncomment | None | End the uncomment process |
| if | Logical expression | Defines a condition. Works like a regular logical expression, where the variables are the Ant properties. Ends with the "endif" directive. Multiple "if" directives can be nested. |
| elseif | Logical expression | Must be defined after a "if" directive. It will recheck the logical expression in case the original directive failed. Any number of "elseif" directive can be present for each "if". |
| else | None | In the case that "if" and "elseif" directives cannot validate the condition, the processing will continue from here. |
| endif | None | Ends the conditional processing flow. |
Usage: Task declaration in the project:<taskdef name="process" classname="net.uworks.andariel.Process" />Task calling syntax:<process file="originalFile" toFile="destinationFile" [processType="type"] [escapeSequence="sequence"] />Attributes: file -> The filename we want to process toFile -> The destination filename of the processed file processType -> One of the process types specified above. By default is "slash-asterisk" escapeSequence -> A String containing the sequence we want to use to define a process directive. By default is "#" selfProcessing -> Defines if it's allowed to overwrite itself. Must be used with "overwrite" to true to have any effect. By default is false Note: Any attribute of the "Copy" task can be used, except for "filterset" and "filterchain". Crude Example:<process file="toprocess.xml" toFile="processed.xml" processType="xml" escapeSequence="#" />
| Field Summary | |
protected java.util.Hashtable |
completeDirMap
|
protected java.io.File |
destDir
|
protected java.io.File |
destFile
|
protected java.util.Hashtable |
dirProcessMap
|
protected boolean |
failonerror
|
protected java.io.File |
file
|
protected java.util.Hashtable |
fileProcessMap
|
protected java.util.Vector |
filesets
|
protected org.apache.tools.ant.util.FileUtils |
fileUtils
|
protected boolean |
flatten
|
protected boolean |
forceOverwrite
|
protected boolean |
includeEmpty
|
protected org.apache.tools.ant.types.Mapper |
mapperElement
|
protected boolean |
preserveLastModified
|
protected int |
verbosity
|
| Fields inherited from class org.apache.tools.ant.Task |
description, location, target, taskName, taskType, wrapper |
| Fields inherited from class org.apache.tools.ant.ProjectComponent |
project |
| Constructor Summary | |
Process()
Process task constructor. |
|
| Method Summary | |
void |
add(org.apache.tools.ant.util.FileNameMapper fileNameMapper)
A nested filenamemapper |
void |
addFileset(org.apache.tools.ant.types.FileSet set)
Adds a set of files to process. |
protected void |
buildMap(java.io.File fromDir,
java.io.File toDir,
java.lang.String[] names,
org.apache.tools.ant.util.FileNameMapper mapper,
java.util.Hashtable map)
Add to a map of files/directories to process |
org.apache.tools.ant.types.Mapper |
createMapper()
Defines the mapper to map source to destination files. |
protected void |
doFileOperations()
Actually does the file (and possibly empty directory) copies. |
void |
execute()
Performs the process operation. |
java.lang.String |
getEncoding()
|
protected org.apache.tools.ant.util.FileUtils |
getFileUtils()
|
java.lang.String |
getOutputEncoding()
|
boolean |
getPreserveLastModified()
Whether to give the copied files the same last modified time as the original files. |
boolean |
isEnableMultipleMapping()
|
protected void |
scan(java.io.File fromDir,
java.io.File toDir,
java.lang.String[] files,
java.lang.String[] dirs)
Compares source files to destination files to see if they should be copied. |
void |
setEnableMultipleMappings(boolean enableMultipleMappings)
Attribute to handle mappers that return multiple mappings for a given source path. |
void |
setEncoding(java.lang.String encoding)
Sets the character encoding |
void |
setEscapeSequence(java.lang.String sequence)
The escape sequence that will be used to distinguish between normal comments and processing comments. |
void |
setFailOnError(boolean failonerror)
If false, note errors to the output but keep going. |
void |
setFile(java.io.File file)
Sets a single source file to process. |
void |
setFlatten(boolean flatten)
When processing directory trees, the files can be "flattened" into a single directory. |
void |
setGranularity(long granularity)
The number of milliseconds leeway to give before deciding a target is out of date. |
void |
setIncludeEmptyDirs(boolean includeEmpty)
Used to process empty directories. |
void |
setOutputEncoding(java.lang.String encoding)
Sets the character encoding for output files. |
void |
setOverwrite(boolean overwrite)
Overwrite any existing destination file(s). |
void |
setPreserveLastModified(boolean preserve)
Give the copied files the same last modified time as the original files. |
void |
setPreserveLastModified(java.lang.String preserve)
Deprecated. setPreserveLastModified(String) has been deprecated and replaced with setPreserveLastModified(boolean) to consistently let the Introspection mechanism work. |
void |
setProcessType(java.lang.String type)
The type of processing instructions. |
void |
setSelfProcessing(boolean selfProcessing)
Defines if we can overwrite the file that is being processed. |
void |
setTodir(java.io.File destDir)
Sets the destination directory. |
void |
setTofile(java.io.File destFile)
Sets the destination file. |
void |
setVerbose(boolean verbose)
Used to force listing of all names of copied files. |
protected void |
validateAttributes()
Ensure we have a consistent and legal set of attributes, and set any internal flags necessary based on different combinations of attributes. |
| Methods inherited from class org.apache.tools.ant.Task |
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType |
| Methods inherited from class org.apache.tools.ant.ProjectComponent |
getProject, setProject |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected java.io.File file
protected java.io.File destFile
protected java.io.File destDir
protected java.util.Vector filesets
protected boolean preserveLastModified
protected boolean forceOverwrite
protected boolean flatten
protected int verbosity
protected boolean includeEmpty
protected boolean failonerror
protected java.util.Hashtable fileProcessMap
protected java.util.Hashtable dirProcessMap
protected java.util.Hashtable completeDirMap
protected org.apache.tools.ant.types.Mapper mapperElement
protected org.apache.tools.ant.util.FileUtils fileUtils
| Constructor Detail |
public Process()
| Method Detail |
protected org.apache.tools.ant.util.FileUtils getFileUtils()
public void setFile(java.io.File file)
file - the file to processpublic void setTofile(java.io.File destFile)
destFile - the file to process topublic void setTodir(java.io.File destDir)
destDir - the destination directorypublic void setPreserveLastModified(java.lang.String preserve)
preserve - a boolean stringpublic void setPreserveLastModified(boolean preserve)
preserve - if true perverse the modified time, default is falsepublic boolean getPreserveLastModified()
public void setOverwrite(boolean overwrite)
overwrite - if true force overwriting of destination file(s)
even if the destination file(s) are younger than
the corresponding source file. Default is false.public void setFlatten(boolean flatten)
flatten - if true flatten the destination directory. Default
is false.public void setVerbose(boolean verbose)
verbose - output the names of copied files. Default is false.public void setIncludeEmptyDirs(boolean includeEmpty)
includeEmpty - if true process empty directories. Default is true.public void setEnableMultipleMappings(boolean enableMultipleMappings)
enableMultipleMappings - If true the task will
process to all the mappings for a given source path, if
false, only the first file or directory is
processed.
By default, this setting is false to provide backward
compatibility with earlier releases.public boolean isEnableMultipleMapping()
public void setFailOnError(boolean failonerror)
failonerror - true or falsepublic void addFileset(org.apache.tools.ant.types.FileSet set)
set - a set of files to process
public org.apache.tools.ant.types.Mapper createMapper()
throws org.apache.tools.ant.BuildException
org.apache.tools.ant.BuildException - if more than one mapper is definedpublic void add(org.apache.tools.ant.util.FileNameMapper fileNameMapper)
fileNameMapper - the mapper to addpublic void setEncoding(java.lang.String encoding)
encoding - the character encodingpublic java.lang.String getEncoding()
null if not set.public void setOutputEncoding(java.lang.String encoding)
encoding - the character encodingpublic java.lang.String getOutputEncoding()
null if not set.public void setGranularity(long granularity)
Default is 0 milliseconds, or 2 seconds on DOS systems.
public void setProcessType(java.lang.String type)
type - the type of processing instructions.public void setEscapeSequence(java.lang.String sequence)
sequence - the escape sequence .public void setSelfProcessing(boolean selfProcessing)
selfProcessing - the new value.
public void execute()
throws org.apache.tools.ant.BuildException
org.apache.tools.ant.BuildException - if an error occurs
protected void validateAttributes()
throws org.apache.tools.ant.BuildException
org.apache.tools.ant.BuildException - if an error occurs
protected void scan(java.io.File fromDir,
java.io.File toDir,
java.lang.String[] files,
java.lang.String[] dirs)
fromDir - The source directorytoDir - The destination directoryfiles - A list of files to processdirs - A list of directories to process
protected void buildMap(java.io.File fromDir,
java.io.File toDir,
java.lang.String[] names,
org.apache.tools.ant.util.FileNameMapper mapper,
java.util.Hashtable map)
fromDir - the source directorytoDir - the destination directorynames - a list of filenamesmapper - a FileNameMapper valuemap - a map of source file to array of destination filesprotected void doFileOperations()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||