Home » apache-ant-1.8.1 » org.apache.tools » ant » taskdefs » [javadoc | source]
public class: Copy [javadoc | source]

All Implemented Interfaces:

Direct Known Subclasses:
    Move, MyCopy

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.

Field Summary
static final  File NULL_FILE_PLACEHOLDER     
static final  String LINE_SEPARATOR     
protected  File file     
protected  File destFile     
protected  File destDir     
protected  Vector rcs     
protected  Vector filesets     
protected  boolean filtering     
protected  boolean preserveLastModified     
protected  boolean forceOverwrite     
protected  boolean flatten     
protected  int verbosity     
protected  boolean includeEmpty     
protected  boolean failonerror     
protected  Hashtable fileCopyMap     
protected  Hashtable dirCopyMap     
protected  Hashtable completeDirMap     
protected  Mapper mapperElement     
protected  FileUtils fileUtils     
Fields inherited from org.apache.tools.ant.Task:
target,  taskName,  taskType,  wrapper
Fields inherited from org.apache.tools.ant.ProjectComponent:
project,  location,  description
 public Copy() 
Method from org.apache.tools.ant.taskdefs.Copy Summary:
add,   add,   addFileset,   buildMap,   buildMap,   createFilterChain,   createFilterSet,   createMapper,   doFileOperations,   doResourceOperations,   execute,   getEncoding,   getFileUtils,   getFilterChains,   getFilterSets,   getOutputEncoding,   getPreserveLastModified,   isEnableMultipleMapping,   scan,   scan,   setEnableMultipleMappings,   setEncoding,   setFailOnError,   setFile,   setFiltering,   setFlatten,   setGranularity,   setIncludeEmptyDirs,   setOutputEncoding,   setOverwrite,   setPreserveLastModified,   setPreserveLastModified,   setTodir,   setTofile,   setVerbose,   supportsNonFileResources,   validateAttributes
Methods from org.apache.tools.ant.Task:
bindToOwner,   execute,   getOwningTarget,   getRuntimeConfigurableWrapper,   getTaskName,   getTaskType,   getWrapper,   handleErrorFlush,   handleErrorOutput,   handleFlush,   handleInput,   handleOutput,   init,   isInvalid,   log,   log,   log,   log,   markInvalid,   maybeConfigure,   perform,   reconfigure,   setOwningTarget,   setRuntimeConfigurableWrapper,   setTaskName,   setTaskType
Methods from org.apache.tools.ant.ProjectComponent:
clone,   getDescription,   getLocation,   getProject,   log,   log,   setDescription,   setLocation,   setProject
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.tools.ant.taskdefs.Copy Detail:
 public  void add(ResourceCollection res) 
    Add a collection of files to copy.
 public  void add(FileNameMapper fileNameMapper) 
    Add a nested filenamemapper.
 public  void addFileset(FileSet set) 
    Add a set of files to copy.
 protected Map buildMap(Resource[] fromResources,
    File toDir,
    FileNameMapper mapper) 
    Create a map of resources to copy.
 protected  void buildMap(File fromDir,
    File toDir,
    String[] names,
    FileNameMapper mapper,
    Hashtable map) 
    Add to a map of files/directories to copy.
 public FilterChain createFilterChain() 
    Add a FilterChain.
 public FilterSet createFilterSet() 
    Add a filterset.
 public Mapper createMapper() throws BuildException 
    Define the mapper to map source to destination files.
 protected  void doFileOperations() 
    Actually does the file (and possibly empty directory) copies. This is a good method for subclasses to override.
 protected  void doResourceOperations(Map map) 
    Actually does the resource copies. This is a good method for subclasses to override.
 public  void execute() throws BuildException 
    Perform the copy operation.
 public String getEncoding() 
    Get the character encoding to be used.
 protected FileUtils getFileUtils() 
    Get the FileUtils for this task.
 protected Vector getFilterChains() 
    Get the filterchains being applied to this operation.
 protected Vector getFilterSets() 
    Get the filtersets being applied to this operation.
 public String getOutputEncoding() 
    Get the character encoding for output files.
 public boolean getPreserveLastModified() 
    Get whether to give the copied files the same last modified time as the original files.
 public boolean isEnableMultipleMapping() 
    Get whether multiple mapping is enabled.
 protected Map scan(Resource[] fromResources,
    File toDir) 
    Compares source resources to destination files to see if they should be copied.
 protected  void scan(File fromDir,
    File toDir,
    String[] files,
    String[] dirs) 
    Compares source files to destination files to see if they should be copied.
 public  void setEnableMultipleMappings(boolean enableMultipleMappings) 
    Set method of handling mappers that return multiple mappings for a given source path.
 public  void setEncoding(String encoding) 
    Set the character encoding.
 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.
 public  void setFile(File file) 
    Set a single source file to copy.
 public  void setFiltering(boolean filtering) 
    Set filtering mode.
 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.
 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.

 public  void setIncludeEmptyDirs(boolean includeEmpty) 
    Set whether to copy empty directories.
 public  void setOutputEncoding(String encoding) 
    Set the character encoding for output files.
 public  void setOverwrite(boolean overwrite) 
    Set overwrite mode regarding existing destination file(s).
 public  void setPreserveLastModified(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(boolean preserve) 
    Give the copied files the same last modified time as the original files.
 public  void setTodir(File destDir) 
    Set the destination directory.
 public  void setTofile(File destFile) 
    Set the destination file.
 public  void setVerbose(boolean verbose) 
    Set verbose mode. Used to force listing of all names of copied files.
 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.

 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.