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
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(ResourceCollection res)
Add a collection of files to copy.
res
- a resource collection to copy.
add
public void add(FileNameMapper fileNameMapper)
Add a nested filenamemapper.
fileNameMapper
- the mapper to add.
addFileset
public void addFileset(FileSet set)
Add 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 directory.toDir
- the destination directory.names
- a list of filenames.mapper
- a FileNameMapper
value.map
- a map of source file to array of destination files.
buildMap
protected Map buildMap(Resource[] fromResources,
File toDir,
FileNameMapper mapper)
Create a map of resources to copy.
fromResources
- The source resources.toDir
- the destination directory.mapper
- a FileNameMapper
value.
- a map of source resource to array of destination files.
createFilterChain
public FilterChain createFilterChain()
Add a FilterChain.
createFilterSet
public FilterSet createFilterSet()
Add a filterset.
createMapper
public Mapper createMapper()
throws BuildException
Define 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.
doResourceOperations
protected void doResourceOperations(Map map)
Actually does the resource copies.
This is a good method for subclasses to override.
map
- a map of source resource to array of destination files.
getEncoding
public String getEncoding()
Get the character encoding to be used.
- the character encoding,
null
if not set.
getFileUtils
protected FileUtils getFileUtils()
Get the FileUtils for this task.
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()
Get the character encoding for output files.
- the character encoding for output files,
null
if not set.
getPreserveLastModified
public boolean getPreserveLastModified()
Get whether to give the copied files the same last modified time as
the original files.
- the whether destination files will inherit the modification
times of the corresponding source files.
isEnableMultipleMapping
public boolean isEnableMultipleMapping()
Get whether multiple mapping is enabled.
- true if multiple mapping is enabled; false otherwise.
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 directory.toDir
- The destination directory.files
- A list of files to copy.dirs
- A list of directories to copy.
scan
protected Map scan(Resource[] fromResources,
File toDir)
Compares source resources to destination files to see if they
should be copied.
fromResources
- The source resources.toDir
- The destination directory.
- a Map with the out-of-date resources as keys and an
array of target file names as values.
setEnableMultipleMappings
public void setEnableMultipleMappings(boolean enableMultipleMappings)
Set method of handling 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)
Set the character encoding.
encoding
- the character encoding.
setFailOnError
public void setFailOnError(boolean failonerror)
Set whether to fail when errors are encountered. If false, note errors
to the output but keep going. Default is true.
failonerror
- true or false.
setFile
public void setFile(File file)
Set a single source file to copy.
setFiltering
public void setFiltering(boolean filtering)
Set filtering mode.
filtering
- if true enable filtering; default is false.
setFlatten
public void setFlatten(boolean flatten)
Set whether files copied from directory trees will 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)
Set the number of milliseconds leeway to give before deciding a
target is out of date.
Default is 1 second, or 2 seconds on DOS systems.
granularity
- the granularity used to decide if a target is out of
date.
setIncludeEmptyDirs
public void setIncludeEmptyDirs(boolean includeEmpty)
Set whether to copy empty directories.
includeEmpty
- if true copy empty directories. Default is true.
setOutputEncoding
public void setOutputEncoding(String encoding)
Set the character encoding for output files.
encoding
- the output character encoding.
setOverwrite
public void setOverwrite(boolean overwrite)
Set overwrite mode regarding 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)
since 1.5.x.
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 preserve the modified time; default is false.
setTodir
public void setTodir(File destDir)
Set the destination directory.
destDir
- the destination directory.
setTofile
public void setTofile(File destFile)
Set the destination file.
destFile
- the file to copy to.
setVerbose
public void setVerbose(boolean verbose)
Set verbose mode. Used to force listing of all names of copied files.
verbose
- whether to output the names of copied files.
Default is false.
supportsNonFileResources
protected boolean supportsNonFileResources()
Whether this task can deal with non-file resources.
<copy> can while <move> can't since we don't
know how to remove non-file resources.
This implementation returns true only if this task is
<copy>. Any subclass of this class that also wants to
support non-file resources needs to override this method. We
need to do so for backwards compatibility reasons since we
can't expect subclasses to support resources.
- true if this task supports non file resources.
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.