Copies a file or directory to a new file
or directory. Files are only copied if the source file is newer
than the destination file, or when the destination file does not
exist. It is possible to explicitly overwrite existing files.
This implementation is based on Arnout Kuiper's initial design
document, the following mailing list discussions, and the
copyfile/copydir tasks.
completeDirMap
protected Hashtable completeDirMap
destDir
protected File destDir
destFile
protected File destFile
dirCopyMap
protected Hashtable dirCopyMap
failonerror
protected boolean failonerror
fileCopyMap
protected Hashtable fileCopyMap
filesets
protected Vector filesets
filtering
protected boolean filtering
flatten
protected boolean flatten
forceOverwrite
protected boolean forceOverwrite
includeEmpty
protected boolean includeEmpty
mapperElement
protected Mapper mapperElement
preserveLastModified
protected boolean preserveLastModified
verbosity
protected int verbosity
add
public void add(FileNameMapper fileNameMapper)
A nested filenamemapper
fileNameMapper
- the mapper to add
addFileset
public void addFileset(FileSet set)
Adds a set of files to copy.
set
- a set of files to copy
buildMap
protected void buildMap(File fromDir,
File toDir,
String[] names,
FileNameMapper mapper,
Hashtable map)
Add to a map of files/directories to copy
fromDir
- the source directorytoDir
- the destination directorynames
- a list of filenamesmapper
- a FileNameMapper
valuemap
- a map of source file to array of destination files
createFilterChain
public FilterChain createFilterChain()
Adds a FilterChain.
createFilterSet
public FilterSet createFilterSet()
Adds a filterset.
createMapper
public Mapper createMapper()
throws BuildException
Defines the mapper to map source to destination files.
- a mapper to be configured
doFileOperations
protected void doFileOperations()
Actually does the file (and possibly empty directory) copies.
This is a good method for subclasses to override.
getEncoding
public String getEncoding()
- the character encoding,
null
if not set.
getFileUtils
protected FileUtils getFileUtils()
getFilterChains
protected Vector getFilterChains()
Get the filterchains being applied to this operation.
- a vector of FilterChain objects
getFilterSets
protected Vector getFilterSets()
Get the filtersets being applied to this operation.
- a vector of FilterSet objects
getOutputEncoding
public String getOutputEncoding()
- the character encoding for output files,
null
if not set.
getPreserveLastModified
public boolean getPreserveLastModified()
Whether to give the copied files the same last modified time as
the original files.
- the preserveLastModified attribute
isEnableMultipleMapping
public boolean isEnableMultipleMapping()
- the value of the enableMultipleMapping attribute
scan
protected void scan(File fromDir,
File toDir,
String[] files,
String[] dirs)
Compares source files to destination files to see if they should be
copied.
fromDir
- The source directorytoDir
- The destination directoryfiles
- A list of files to copydirs
- A list of directories to copy
setEnableMultipleMappings
public void setEnableMultipleMappings(boolean enableMultipleMappings)
Attribute to handle mappers that return multiple
mappings for a given source path.
enableMultipleMappings
- If true the task will
copy 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.
setEncoding
public void setEncoding(String encoding)
Sets the character encoding
encoding
- the character encoding
setFailOnError
public void setFailOnError(boolean failonerror)
If false, note errors to the output but keep going.
failonerror
- true or false
setFile
public void setFile(File file)
Sets a single source file to copy.
setFiltering
public void setFiltering(boolean filtering)
If true, enables filtering.
filtering
- if true enable filtering, default is false
setFlatten
public void setFlatten(boolean flatten)
When copying directory trees, the files can be "flattened"
into a single directory. If there are multiple files with
the same name in the source directory tree, only the first
file will be copied into the "flattened" directory, unless
the forceoverwrite attribute is true.
flatten
- if true flatten the destination directory. Default
is false.
setGranularity
public void setGranularity(long granularity)
The number of milliseconds leeway to give before deciding a
target is out of date.
Default is 0 milliseconds, or 2 seconds on DOS systems.
setIncludeEmptyDirs
public void setIncludeEmptyDirs(boolean includeEmpty)
Used to copy empty directories.
includeEmpty
- if true copy empty directories. Default is true.
setOutputEncoding
public void setOutputEncoding(String encoding)
Sets the character encoding for output files.
encoding
- the character encoding
setOverwrite
public void setOverwrite(boolean overwrite)
Overwrite any existing destination file(s).
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.
setPreserveLastModified
public void setPreserveLastModified(String preserve)
setPreserveLastModified(String) has been deprecated and
replaced with setPreserveLastModified(boolean) to
consistently let the Introspection mechanism work.
Give the copied files the same last modified time as the original files.
preserve
- a boolean string
setPreserveLastModified
public void setPreserveLastModified(boolean preserve)
Give the copied files the same last modified time as the original files.
preserve
- if true perverse the modified time, default is false
setTodir
public void setTodir(File destDir)
Sets the destination directory.
destDir
- the destination directory
setTofile
public void setTofile(File destFile)
Sets the destination file.
destFile
- the file to copy to
setVerbose
public void setVerbose(boolean verbose)
Used to force listing of all names of copied files.
verbose
- output the names of copied files. Default is false.
validateAttributes
protected void validateAttributes()
throws BuildException
Ensure we have a consistent and legal set of attributes, and set
any internal flags necessary based on different combinations
of attributes.