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.
| Modifier and Type | Field and Description |
|---|---|
| protected Hashtable | |
| protected File | |
| protected File | |
| protected Hashtable | |
| private boolean | |
| protected boolean | |
| protected File | |
| protected Hashtable | |
| protected Vector | |
| protected FileUtils | |
| private final Vector | |
| protected boolean | |
| private final Vector | |
| protected boolean | |
| private boolean | |
| protected boolean | |
| private long | |
| protected boolean | |
| private String | |
| pack-priv static final String | LINE_SEPARATOR
Deprecated
|
| protected Mapper | |
| private static final String | |
| pack-priv static final File | |
| private String | |
| protected boolean | |
| private boolean | |
| protected Vector | |
| private Resource | |
| protected int |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| private static void | |
| private static void | |
| public void | |
| protected void | buildMap(final File
the source directory. fromDir, final File the destination directory. toDir, final String[] a list of filenames. names, final FileNameMapper a mapper, final Hashtable<String, String[]> FileNameMapper value.a map of source file to array of destination files. map)Add to a map of files/directories to copy. |
| protected Map | Returns: a map of source resource to array of destination files.The source resources. fromResources, final File the destination directory. toDir, final FileNameMapper a mapper)FileNameMapper value.Create a map of resources to copy. |
| private void | |
| public FilterChain | |
| public FilterSet | |
| public Mapper | Returns: a mapper to be configured.Define the mapper to map source to destination files. |
| protected void | |
| protected void | doResourceOperations(final Map<Resource, String[]>
a map of source resource to array of destination files. map)Actually does the resource copies. |
| public void | |
| private String | |
| public String | Returns: the character encoding,null if not set.Get the character encoding to be used. |
| protected FileUtils | |
| protected Vector | Returns: a vector of FilterChain objects.Get the filterchains being applied to this operation. |
| protected Vector | Returns: a vector of FilterSet objects.Get the filtersets being applied to this operation. |
| public boolean | |
| private static File | |
| private FileNameMapper | |
| private String | Returns: ex.getMessage() if ex.getMessage() is not null otherwise return ex.toString()the exception to handle ex)Handle getMessage() for exceptions. |
| public String | Returns: the character encoding for output files,null if not set.Get the character encoding for output files. |
| public boolean | Returns: the whether destination files will inherit the modification times of the corresponding source files.Get whether to give the copied files the same last modified time as the original files. |
| public boolean | Returns: true if multiple mapping is enabled; false otherwise.Get whether multiple mapping is enabled. |
| private void | |
| protected void | |
| protected Map | |
| public void | setEnableMultipleMappings(final boolean
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. enableMultipleMappings)Set method of handling mappers that return multiple mappings for a given source path. |
| public void | |
| public void | setFailOnError(final boolean
true or false. failonerror)Set whether to fail when errors are encountered. |
| public void | |
| public void | |
| public void | setFlatten(final boolean
if true flatten the destination directory. Default
is false. flatten)Set whether files copied from directory trees will be "flattened" into a single directory. |
| public void | |
| public void | setGranularity(final long
the granularity used to decide if a target is out of
date. granularity)Set the number of milliseconds leeway to give before deciding a target is out of date. |
| public void | setIncludeEmptyDirs(final boolean
if true copy empty directories. Default is true. includeEmpty)Set whether to copy empty directories. |
| public void | setOutputEncoding(final String
the output character encoding. encoding)Set the character encoding for output files. |
| public void | setOverwrite(final boolean
if true force overwriting of destination file(s)
even if the destination file(s) are younger than
the corresponding source file. Default is false. overwrite)Set overwrite mode regarding existing destination file(s). |
| public void | setPreserveLastModified(final String
a boolean string. preserve)
Deprecated
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.
|
| public void | setPreserveLastModified(final boolean
if true preserve the modified time; default is false. preserve)Give the copied files the same last modified time as the original files. |
| public void | setQuiet(final boolean
whether or not to display error messages when a file or
directory does not exist. Default is false. quiet)Set quiet mode. |
| public void | |
| public void | |
| public void | setVerbose(final boolean
whether to output the names of copied files.
Default is false. verbose)Set verbose mode. |
| protected boolean | Returns: true if this task supports non file resources.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. |
| completeDirMap | back to summary |
|---|---|
| protected Hashtable<File, File> completeDirMap | |
| destDir | back to summary |
|---|---|
| protected File destDir | |
| destFile | back to summary |
|---|---|
| protected File destFile | |
| dirCopyMap | back to summary |
|---|---|
| protected Hashtable<String, String[]> dirCopyMap | |
| enableMultipleMappings | back to summary |
|---|---|
| private boolean enableMultipleMappings | |
| failonerror | back to summary |
|---|---|
| protected boolean failonerror | |
| file | back to summary |
|---|---|
| protected File file | |
| fileCopyMap | back to summary |
|---|---|
| protected Hashtable<String, String[]> fileCopyMap | |
| filesets | back to summary |
|---|---|
| protected Vector<ResourceCollection> filesets | |
| fileUtils | back to summary |
|---|---|
| protected FileUtils fileUtils | |
| filterChains | back to summary |
|---|---|
| private final Vector<FilterChain> filterChains | |
| filtering | back to summary |
|---|---|
| protected boolean filtering | |
| filterSets | back to summary |
|---|---|
| private final Vector<FilterSet> filterSets | |
| flatten | back to summary |
|---|---|
| protected boolean flatten | |
| force | back to summary |
|---|---|
| private boolean force | |
| forceOverwrite | back to summary |
|---|---|
| protected boolean forceOverwrite | |
| granularity | back to summary |
|---|---|
| private long granularity | |
| includeEmpty | back to summary |
|---|---|
| protected boolean includeEmpty | |
| inputEncoding | back to summary |
|---|---|
| private String inputEncoding | |
| LINE_SEPARATOR | back to summary |
|---|---|
| pack-priv static final String LINE_SEPARATOR
Deprecated
| |
| mapperElement | back to summary |
|---|---|
| protected Mapper mapperElement | |
| MSG_WHEN_COPYING_EMPTY_RC_TO_FILE | back to summary |
|---|---|
| private static final String MSG_WHEN_COPYING_EMPTY_RC_TO_FILE | |
| NULL_FILE_PLACEHOLDER | back to summary |
|---|---|
| pack-priv static final File NULL_FILE_PLACEHOLDER | |
| outputEncoding | back to summary |
|---|---|
| private String outputEncoding | |
| preserveLastModified | back to summary |
|---|---|
| protected boolean preserveLastModified | |
| quiet | back to summary |
|---|---|
| private boolean quiet | |
| rcs | back to summary |
|---|---|
| protected Vector<ResourceCollection> rcs | |
| singleResource | back to summary |
|---|---|
| private Resource singleResource | |
| verbosity | back to summary |
|---|---|
| protected int verbosity | |
| Copy | back to summary |
|---|---|
| public Copy() Copy task constructor. | |
| add | back to summary |
|---|---|
| public void add(final ResourceCollection res) Add a collection of files to copy.
| |
| add | back to summary |
|---|---|
| public void add(final FileNameMapper fileNameMapper) Add a nested filenamemapper.
| |
| add | back to summary |
|---|---|
| private static void add(File baseDir, final String[] names, final Map<File, List<String>> m) Adds the given strings to a list contained in the given map. The file is the key into the map. | |
| add | back to summary |
|---|---|
| private static void add(final File baseDir, final String name, final Map<File, List<String>> m) Adds the given string to a list contained in the given map. The file is the key into the map. | |
| addFileset | back to summary |
|---|---|
| public void addFileset(final FileSet set) Add a set of files to copy.
| |
| buildMap | back to summary |
|---|---|
| protected void buildMap(final File fromDir, final File toDir, final String[] names, final FileNameMapper mapper, final Hashtable<String, String[]> map) Add to a map of files/directories to copy. | |
| buildMap | back to summary |
|---|---|
| protected Map Create a map of resources to copy. | |
| copySingleFile | back to summary |
|---|---|
| private void copySingleFile() protected and private methods | |
| createFilterChain | back to summary |
|---|---|
| public FilterChain createFilterChain() Add a FilterChain.
| |
| createFilterSet | back to summary |
|---|---|
| public FilterSet createFilterSet() Add a filterset.
| |
| createMapper | back to summary |
|---|---|
| public Mapper createMapper() throws BuildException Define the mapper to map source to destination files.
| |
| doFileOperations | back to summary |
|---|---|
| protected void doFileOperations() Actually does the file (and possibly empty directory) copies. This is a good method for subclasses to override. | |
| doResourceOperations | back to summary |
|---|---|
| protected void doResourceOperations(final Map<Resource, String[]> map) Actually does the resource copies. This is a good method for subclasses to override. | |
| execute | back to summary |
|---|---|
| public void execute() throws BuildException Overrides org. Perform the copy operation.
| |
| getDueTo | back to summary |
|---|---|
| private String getDueTo(final Exception ex) Returns a reason for failure based on the exception thrown. If the exception is not IOException output the class name, output the message if the exception is MalformedInput add a little note. | |
| getEncoding | back to summary |
|---|---|
| public String getEncoding() Get the character encoding to be used.
| |
| getFileUtils | back to summary |
|---|---|
| protected FileUtils getFileUtils() Get the FileUtils for this task.
| |
| getFilterChains | back to summary |
|---|---|
| protected Vector Get the filterchains being applied to this operation.
| |
| getFilterSets | back to summary |
|---|---|
| protected Vector Get the filtersets being applied to this operation. | |
| getForce | back to summary |
|---|---|
| public boolean getForce() Whether read-only destinations will be overwritten.
| |
| getKeyFile | back to summary |
|---|---|
| private static File getKeyFile(final File f) Either returns its argument or a placeholder if the argument is null. | |
| getMapper | back to summary |
|---|---|
| private FileNameMapper getMapper() returns the mapper to use based on nested elements or the flatten attribute. | |
| getMessage | back to summary |
|---|---|
| private String getMessage(final Exception ex) Handle getMessage() for exceptions. | |
| getOutputEncoding | back to summary |
|---|---|
| public String getOutputEncoding() Get the character encoding for output files.
| |
| getPreserveLastModified | back to summary |
|---|---|
| public boolean getPreserveLastModified() Get whether to give the copied files the same last modified time as the original files.
| |
| isEnableMultipleMapping | back to summary |
|---|---|
| public boolean isEnableMultipleMapping() Get whether multiple mapping is enabled.
| |
| iterateOverBaseDirs | back to summary |
|---|---|
| private void iterateOverBaseDirs(final Set<File> baseDirs, final Map<File, List<String>> dirsByBasedir, final Map<File, List<String>> filesByBasedir) | |
| scan | back to summary |
|---|---|
| protected void scan(final File fromDir, final File toDir, final String[] files, final String[] dirs) Compares source files to destination files to see if they should be copied. | |
| scan | back to summary |
|---|---|
| protected Map Compares source resources to destination files to see if they should be copied. | |
| setEnableMultipleMappings | back to summary |
|---|---|
| public void setEnableMultipleMappings(final boolean enableMultipleMappings) Set method of handling mappers that return multiple mappings for a given source path.
| |
| setEncoding | back to summary |
|---|---|
| public void setEncoding(final String encoding) Set the character encoding.
| |
| setFailOnError | back to summary |
|---|---|
| public void setFailOnError(final boolean failonerror) Set whether to fail when errors are encountered. If false, note errors to the output but keep going. Default is true.
| |
| setFile | back to summary |
|---|---|
| public void setFile(final File file) Set a single source file to copy.
| |
| setFiltering | back to summary |
|---|---|
| public void setFiltering(final boolean filtering) Set filtering mode.
| |
| setFlatten | back to summary |
|---|---|
| public void setFlatten(final 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.
| |
| setForce | back to summary |
|---|---|
| public void setForce(final boolean f) Whether read-only destinations will be overwritten. Defaults to false
| |
| setGranularity | back to summary |
|---|---|
| public void setGranularity(final 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.
| |
| setIncludeEmptyDirs | back to summary |
|---|---|
| public void setIncludeEmptyDirs(final boolean includeEmpty) Set whether to copy empty directories.
| |
| setOutputEncoding | back to summary |
|---|---|
| public void setOutputEncoding(final String encoding) Set the character encoding for output files.
| |
| setOverwrite | back to summary |
|---|---|
| public void setOverwrite(final boolean overwrite) Set overwrite mode regarding existing destination file(s).
| |
| setPreserveLastModified | back to summary |
|---|---|
| public void setPreserveLastModified(final String preserve)
Deprecated 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.
| |
| setPreserveLastModified | back to summary |
|---|---|
| public void setPreserveLastModified(final boolean preserve) Give the copied files the same last modified time as the original files.
| |
| setQuiet | back to summary |
|---|---|
| public void setQuiet(final boolean quiet) Set quiet mode. Used to hide messages when a file or directory to be copied does not exist.
| |
| setTodir | back to summary |
|---|---|
| public void setTodir(final File destDir) Set the destination directory.
| |
| setTofile | back to summary |
|---|---|
| public void setTofile(final File destFile) Set the destination file.
| |
| setVerbose | back to summary |
|---|---|
| public void setVerbose(final boolean verbose) Set verbose mode. Used to force listing of all names of copied files.
| |
| supportsNonFileResources | back to summary |
|---|---|
| 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.
| |
| validateAttributes | back to summary |
|---|---|
| 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.
| |