public class Copy extends Task
This implementation is based on Arnout Kuiper's initial design document, the following mailing list discussions, and the copyfile/copydir tasks.
Modifier and Type | Field and Description |
---|---|
protected java.util.Hashtable |
completeDirMap |
protected java.io.File |
destDir |
protected java.io.File |
destFile |
protected java.util.Hashtable |
dirCopyMap |
protected boolean |
failonerror |
protected java.io.File |
file |
protected java.util.Hashtable |
fileCopyMap |
protected java.util.Vector |
filesets |
protected FileUtils |
fileUtils |
protected boolean |
filtering |
protected boolean |
flatten |
protected boolean |
forceOverwrite |
protected boolean |
includeEmpty |
protected Mapper |
mapperElement |
protected boolean |
preserveLastModified |
protected java.util.Vector |
rcs |
protected int |
verbosity |
description, location, project
Constructor and Description |
---|
Copy()
Copy task constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(FileNameMapper fileNameMapper)
Add a nested filenamemapper.
|
void |
add(ResourceCollection res)
Add a collection of files to copy.
|
void |
addFileset(FileSet set)
Add a set of files to copy.
|
protected void |
buildMap(java.io.File fromDir,
java.io.File toDir,
java.lang.String[] names,
FileNameMapper mapper,
java.util.Hashtable map)
Add to a map of files/directories to copy.
|
protected java.util.Map |
buildMap(Resource[] fromResources,
java.io.File toDir,
FileNameMapper mapper)
Create a map of resources to copy.
|
FilterChain |
createFilterChain()
Add a FilterChain.
|
FilterSet |
createFilterSet()
Add a filterset.
|
Mapper |
createMapper()
Define the mapper to map source to destination files.
|
protected void |
doFileOperations()
Actually does the file (and possibly empty directory) copies.
|
protected void |
doResourceOperations(java.util.Map map)
Actually does the resource copies.
|
void |
execute()
Perform the copy operation.
|
java.lang.String |
getEncoding()
Get the character encoding to be used.
|
protected FileUtils |
getFileUtils()
Get the FileUtils for this task.
|
protected java.util.Vector |
getFilterChains()
Get the filterchains being applied to this operation.
|
protected java.util.Vector |
getFilterSets()
Get the filtersets being applied to this operation.
|
boolean |
getForce()
Whether read-only destinations will be overwritten.
|
java.lang.String |
getOutputEncoding()
Get the character encoding for output files.
|
boolean |
getPreserveLastModified()
Get whether to give the copied files the same last modified time as
the original files.
|
boolean |
isEnableMultipleMapping()
Get whether multiple mapping is enabled.
|
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.
|
protected java.util.Map |
scan(Resource[] fromResources,
java.io.File toDir)
Compares source resources to destination files to see if they
should be copied.
|
void |
setEnableMultipleMappings(boolean enableMultipleMappings)
Set method of handling mappers that return multiple
mappings for a given source path.
|
void |
setEncoding(java.lang.String encoding)
Set the character encoding.
|
void |
setFailOnError(boolean failonerror)
Set whether to fail when errors are encountered.
|
void |
setFile(java.io.File file)
Set a single source file to copy.
|
void |
setFiltering(boolean filtering)
Set filtering mode.
|
void |
setFlatten(boolean flatten)
Set whether files copied from directory trees will be "flattened"
into a single directory.
|
void |
setForce(boolean f)
Whether read-only destinations will be overwritten.
|
void |
setGranularity(long granularity)
Set the number of milliseconds leeway to give before deciding a
target is out of date.
|
void |
setIncludeEmptyDirs(boolean includeEmpty)
Set whether to copy empty directories.
|
void |
setOutputEncoding(java.lang.String encoding)
Set the character encoding for output files.
|
void |
setOverwrite(boolean overwrite)
Set overwrite mode regarding 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.
since 1.5.x.
setPreserveLastModified(String) has been deprecated and
replaced with setPreserveLastModified(boolean) to
consistently let the Introspection mechanism work.
|
void |
setQuiet(boolean quiet)
Set quiet mode.
|
void |
setTodir(java.io.File destDir)
Set the destination directory.
|
void |
setTofile(java.io.File destFile)
Set the destination file.
|
void |
setVerbose(boolean verbose)
Set verbose mode.
|
protected boolean |
supportsNonFileResources()
Whether this task can deal with non-file resources.
|
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.
|
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
protected java.io.File file
protected java.io.File destFile
protected java.io.File destDir
protected java.util.Vector rcs
protected java.util.Vector filesets
protected boolean filtering
protected boolean preserveLastModified
protected boolean forceOverwrite
protected boolean flatten
protected int verbosity
protected boolean includeEmpty
protected boolean failonerror
protected java.util.Hashtable fileCopyMap
protected java.util.Hashtable dirCopyMap
protected java.util.Hashtable completeDirMap
protected Mapper mapperElement
protected FileUtils fileUtils
protected FileUtils getFileUtils()
public void setFile(java.io.File file)
file
- the file to copy.public void setTofile(java.io.File destFile)
destFile
- the file to copy to.public void setTodir(java.io.File destDir)
destDir
- the destination directory.public FilterChain createFilterChain()
public FilterSet createFilterSet()
public void setPreserveLastModified(java.lang.String preserve)
preserve
- a boolean string.public void setPreserveLastModified(boolean preserve)
preserve
- if true preserve the modified time; default is false.public boolean getPreserveLastModified()
protected java.util.Vector getFilterSets()
protected java.util.Vector getFilterChains()
public void setFiltering(boolean filtering)
filtering
- if true enable filtering; default is false.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 setForce(boolean f)
Defaults to false
public boolean getForce()
public void setFlatten(boolean flatten)
flatten
- if true flatten the destination directory. Default
is false.public void setVerbose(boolean verbose)
verbose
- whether to output the names of copied files.
Default is false.public void setIncludeEmptyDirs(boolean includeEmpty)
includeEmpty
- if true copy empty directories. Default is true.public void setQuiet(boolean quiet)
quiet
- whether or not to display error messages when a file or
directory does not exist. Default is false.public void setEnableMultipleMappings(boolean enableMultipleMappings)
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.public boolean isEnableMultipleMapping()
public void setFailOnError(boolean failonerror)
failonerror
- true or false.public void addFileset(FileSet set)
set
- a set of files to copy.public void add(ResourceCollection res)
res
- a resource collection to copy.public Mapper createMapper() throws BuildException
BuildException
- if more than one mapper is defined.public void add(FileNameMapper fileNameMapper)
fileNameMapper
- the mapper to add.public void setEncoding(java.lang.String encoding)
encoding
- the character encoding.public java.lang.String getEncoding()
null
if not set.public void setOutputEncoding(java.lang.String encoding)
encoding
- the output character encoding.public java.lang.String getOutputEncoding()
null
if not set.public void setGranularity(long granularity)
Default is 1 second, or 2 seconds on DOS systems.
granularity
- the granularity used to decide if a target is out of
date.public void execute() throws BuildException
execute
in class Task
BuildException
- if an error occurs.protected void validateAttributes() throws BuildException
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 directory.toDir
- The destination directory.files
- A list of files to copy.dirs
- A list of directories to copy.protected java.util.Map scan(Resource[] fromResources, java.io.File toDir)
fromResources
- The source resources.toDir
- The destination directory.protected void buildMap(java.io.File fromDir, java.io.File toDir, java.lang.String[] names, FileNameMapper mapper, java.util.Hashtable map)
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.protected java.util.Map buildMap(Resource[] fromResources, java.io.File toDir, FileNameMapper mapper)
fromResources
- The source resources.toDir
- the destination directory.mapper
- a FileNameMapper
value.protected void doFileOperations()
protected void doResourceOperations(java.util.Map map)
map
- a map of source resource to array of destination files.protected boolean supportsNonFileResources()
<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.