|
||||||||||
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.barracudamvc.taskdefs.CopyAndReplace
public class 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 supports 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).
If SSI replacement is turned on, you can also exclude blocks of code using #exclude_start
and #exclude_end tags (as many as you want in the template). This allows you to drop code
from the mockups when you copy across. For example:
blah blah blah
will result in this after copying:
As a final note, doing SSI replacement on a hierarchy of directories can easily cause
broken link references (ie. if your SSI is in the root directory, and it refers to images/foo.gif,
then when you suck that SSI into a file several directories deep (eg. /foo/bar/blah.html), then
that ssi reference really needs to get changed to ../../images/foo.gif. You can do this by specifying
a relative dir constant in your options.mappings file:
token=^"images/^ value=^"@REL_PATH@images/^
Nested Class Summary | |
---|---|
static class |
CopyAndReplace.BooleanAttribute
|
Field Summary | |
---|---|
protected File |
mappingsFile
|
static String |
REL_PATH_TOKEN
|
protected boolean |
ssi
|
Fields inherited from class org.apache.tools.ant.taskdefs.Copy |
---|
completeDirMap, destDir, destFile, dirCopyMap, failonerror, file, fileCopyMap, filesets, fileUtils, 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 |
---|
add, addFileset, buildMap, createFilterChain, createFilterSet, createMapper, execute, getEncoding, getFileUtils, getFilterChains, getFilterSets, getOutputEncoding, getPreserveLastModified, isEnableMultipleMapping, scan, setEnableMultipleMappings, setEncoding, setFailOnError, setFile, setFiltering, setFlatten, setGranularity, 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 |
---|
public static final String REL_PATH_TOKEN
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
doFileOperations
in class org.apache.tools.ant.taskdefs.Copy
public byte[] getFile(File targetFile, File fromDir)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |