|
|||||||||||
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
org.apache.tools.ant.taskdefs.Copy
org.enhydra.barracuda.taskdefs.CopyAndReplace
A consolidated copy and replace task that extends the basic Ant Copy taskdef.
In addition, once files have been copied, a replace function is also run on them. This replace will only affect the files that actually get copied; it will not affect any other files in the directory.
The replace occurs using a simply properties file, rather than specifying replace parameters via the xml. The format of this file looks something like this:
As you can see, the format is flexible. Tokens are identified with "token=" and values are identified by "value=". The actual token/value delimiters are taken to be the first character following the = sign. This could be a double quote, single quote, or any other character (ie. if the text you wish to replace contains both double and single quotes, you might want to use a ~ delimiter or something like that).
Note also that this taskdef support SSI replacement, which can be quite useful. By default, the copied files are NOT processed for SSIs; if you want to use this, turn is on using the 'ssi=true' attribute. SSI replacement occurs BEFORE the token replacement (ensuring that the text contained in the SSI gets processed for tokens as well).
Nested Class Summary | |
static class |
CopyAndReplace.BooleanAttribute
|
Field Summary | |
protected File |
mappingsFile
|
protected boolean |
ssi
|
Fields inherited from class org.apache.tools.ant.taskdefs.Copy |
completeDirMap, destDir, destFile, dirCopyMap, file, fileCopyMap, filesets, filtering, flatten, forceOverwrite, includeEmpty, mapperElement, preserveLastModified, 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 | |
CopyAndReplace()
|
Method Summary | |
protected void |
doFileOperations()
Actually does the file (and possibly empty directory) copies. |
byte[] |
getFile(File targetFile,
File fromDir)
|
protected void |
processReplace(String fromFile,
String toFile,
List tokenList,
List valueList)
perform the token-value based replacement. |
protected void |
processSSI(String fromFile,
String toFile)
processSSI is the result of a code refactoring due to changes in Ant 1.5 to Ant 1.6 Ant 1.6 supports multiple target file, therefore processSSI might be called n-times |
void |
setMappings(File mappingsFile)
Sets the mappings file. |
void |
setSsi(CopyAndReplace.BooleanAttribute issi)
Process files copied for ssi |
Methods inherited from class org.apache.tools.ant.taskdefs.Copy |
addFileset, buildMap, createFilterChain, createFilterSet, createMapper, execute, getEncoding, getFileUtils, getFilterChains, getFilterSets, getOutputEncoding, getPreserveLastModified, isEnableMultipleMapping, scan, setEnableMultipleMappings, setEncoding, setFailOnError, setFile, setFiltering, setFlatten, setIncludeEmptyDirs, setOutputEncoding, setOverwrite, setPreserveLastModified, setPreserveLastModified, setTodir, setTofile, setVerbose, validateAttributes |
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 File mappingsFile
protected boolean ssi
Constructor Detail |
public CopyAndReplace()
Method Detail |
public void setMappings(File mappingsFile)
public void setSsi(CopyAndReplace.BooleanAttribute issi)
issi
- set "true" to process copied files for ssiprotected void processSSI(String fromFile, String toFile)
fromFile
- toFile
- protected void processReplace(String fromFile, String toFile, List tokenList, List valueList)
fromFile
- toFile
- tokenList
- valueList
- protected void doFileOperations()
Actually does the file (and possibly empty directory) copies. This is a good method for subclasses to override.
Note that all the copy functionality occurs by simply deferring to the superclass implementation. The replace functionality follows:
first we make sure there is a mappings file
next we parse it to determine all token/value mapings
finally we iterate through the list of files that actually got copied and we create Replace task for each of them. This task contains all the various token/value mappings, and gets executed for each file, effectively making all the necessary text substitutions
public byte[] getFile(File targetFile, File fromDir)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |