Class Move
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.tools.ant.taskdefs.Copy
org.apache.tools.ant.taskdefs.Move
- All Implemented Interfaces:
Cloneable
Moves a file or directory to a new file or directory.
By default, the
destination file is overwritten if it already exists.
When overwrite is
turned off, then files are only moved if the source file is
newer than the destination file, or when the destination file does
not exist.
Source files and directories are only deleted when the file or directory has been copied to the destination successfully. Filtering also works.
This implementation is based on Arnout Kuiper's initial design document, the following mailing list discussions, and the copyfile/copydir tasks.
- Since:
- Ant 1.2
-
Field Summary
Fields inherited from class Copy
completeDirMap, destDir, destFile, dirCopyMap, failonerror, file, fileCopyMap, filesets, fileUtils, filtering, flatten, forceOverwrite, includeEmpty, mapperElement, preserveLastModified, rcs, verbosityModifier and TypeFieldDescriptionprotected Fileprotected Fileprotected booleanprotected Fileprotected Vector<ResourceCollection> protected FileUtilsprotected booleanprotected booleanprotected booleanprotected booleanprotected Mapperprotected booleanprotected Vector<ResourceCollection> protected intFields inherited from class ProjectComponent
description, location, project -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidGo and delete the directory tree.protected voidGo and delete the directory tree.protected voidOverride copy's doFileOperations to move the files instead of copying them.protected booleanokToDelete(File d) Its only ok to delete a directory tree if there are no files in it.protected booleanrenameFile(File sourceFile, File destFile, boolean filtering, boolean overwrite) Attempts to rename a file from a source to a destination.voidsetPerformGcOnFailedDelete(boolean b) Whether to perform a garbage collection before retrying a failed delete.protected voidEnsure we have a consistent and legal set of attributes, and set any internal flags necessary based on different combinations of attributes.Methods inherited from class Copy
add, add, addFileset, buildMap, buildMap, createFilterChain, createFilterSet, createMapper, doResourceOperations, execute, getEncoding, getFileUtils, getFilterChains, getFilterSets, getForce, getOutputEncoding, getPreserveLastModified, isEnableMultipleMapping, scan, scan, setEnableMultipleMappings, setEncoding, setFailOnError, setFile, setFiltering, setFlatten, setForce, setGranularity, setIncludeEmptyDirs, setOutputEncoding, setOverwrite, setPreserveLastModified, setPreserveLastModified, setQuiet, setTodir, setTofile, setVerbose, supportsNonFileResourcesModifier and TypeMethodDescriptionvoidadd(ResourceCollection res) Add a collection of files to copy.voidadd(FileNameMapper fileNameMapper) Add a nested filenamemapper.voidaddFileset(FileSet set) Add a set of files to copy.protected voidbuildMap(File fromDir, File toDir, String[] names, FileNameMapper mapper, Hashtable<String, String[]> map) Add to a map of files/directories to copy.buildMap(Resource[] fromResources, File toDir, FileNameMapper mapper) Create a map of resources to copy.Add a FilterChain.Add a filterset.Define the mapper to map source to destination files.protected voiddoResourceOperations(Map<Resource, String[]> map) Actually does the resource copies.voidexecute()Perform the copy operation.Get the character encoding to be used.protected FileUtilsGet the FileUtils for this task.protected Vector<FilterChain> Get the filterchains being applied to this operation.Get the filtersets being applied to this operation.booleangetForce()Whether read-only destinations will be overwritten.Get the character encoding for output files.booleanGet whether to give the copied files the same last modified time as the original files.booleanGet whether multiple mapping is enabled.protected voidCompares source files to destination files to see if they should be copied.Compares source resources to destination files to see if they should be copied.voidsetEnableMultipleMappings(boolean enableMultipleMappings) Set method of handling mappers that return multiple mappings for a given source path.voidsetEncoding(String encoding) Set the character encoding.voidsetFailOnError(boolean failonerror) Set whether to fail when errors are encountered.voidSet a single source file to copy.voidsetFiltering(boolean filtering) Set filtering mode.voidsetFlatten(boolean flatten) Set whether files copied from directory trees will be "flattened" into a single directory.voidsetForce(boolean f) Whether read-only destinations will be overwritten.voidsetGranularity(long granularity) Set the number of milliseconds leeway to give before deciding a target is out of date.voidsetIncludeEmptyDirs(boolean includeEmpty) Set whether to copy empty directories.voidsetOutputEncoding(String encoding) Set the character encoding for output files.voidsetOverwrite(boolean overwrite) Set overwrite mode regarding existing destination file(s).voidsetPreserveLastModified(boolean preserve) Give the copied files the same last modified time as the original files.voidsetPreserveLastModified(String preserve) Deprecated.since 1.5.x.voidsetQuiet(boolean quiet) Set quiet mode.voidSet the destination directory.voidSet the destination file.voidsetVerbose(boolean verbose) Set verbose mode.protected booleanWhether this task can deal with non-file resources.Methods inherited from class Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskTypeModifier and TypeMethodDescriptionfinal voidbindToOwner(Task owner) Bind a task to another; use this when configuring a newly created task to do work on behalf of another.Returns the container target of this task.Returns the wrapper used for runtime configuration.Returns the name to use in logging messages.Return the type of task.protected RuntimeConfigurableReturn the runtime configurable structure for this task.protected voidhandleErrorFlush(String output) Handles an error line by logging it with the WARN priority.protected voidhandleErrorOutput(String output) Handles an error output by logging it with the WARN priority.protected voidhandleFlush(String output) Handles output by logging it with the INFO priority.protected inthandleInput(byte[] buffer, int offset, int length) Handle an input request by this task.protected voidhandleOutput(String output) Handles output by logging it with the INFO priority.voidinit()Called by the project to let the task initialize properly.protected final booleanHas this task been marked invalid?voidLogs a message with the default (INFO) priority.voidLogs a message with the given priority.voidLogs a message with the given priority.voidLogs a message with the given priority.voidConfigures this task - if it hasn't been done already.final voidperform()Performs this task if it's still valid, or gets a replacement version and performs that otherwise.voidForce the task to be reconfigured from its RuntimeConfigurable.voidsetOwningTarget(Target target) Sets the target container of this task.voidSets the wrapper to be used for runtime configuration.voidsetTaskName(String name) Sets the name to use in logging messages.voidsetTaskType(String type) Sets the name with which the task has been invoked.Methods inherited from class ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProjectModifier and TypeMethodDescriptionclone()Returns the description of the current action.Returns the file/location where this task was defined.Returns the project to which this component belongs.voidsetDescription(String desc) Sets a description of the current action.voidsetLocation(Location location) Sets the file/location where this task was defined.voidsetProject(Project project) Sets the project object of this component.
-
Constructor Details
-
Move
public Move()Constructor of object. This sets the forceOverwrite attribute of the Copy parent class to true.
-
-
Method Details
-
setPerformGcOnFailedDelete
public void setPerformGcOnFailedDelete(boolean b) Whether to perform a garbage collection before retrying a failed delete.This may be required on Windows (where it is set to true by default) but also on other operating systems, for example when deleting directories from an NFS share.
- Parameters:
b- boolean- Since:
- Ant 1.8.3
-
validateAttributes
Ensure we have a consistent and legal set of attributes, and set any internal flags necessary based on different combinations of attributes..- Overrides:
validateAttributesin classCopy- Throws:
BuildException- if an error occurs.
-
doFileOperations
protected void doFileOperations()Override copy's doFileOperations to move the files instead of copying them.- Overrides:
doFileOperationsin classCopy
-
okToDelete
Its only ok to delete a directory tree if there are no files in it.- Parameters:
d- the directory to check- Returns:
- true if a deletion can go ahead
-
deleteDir
Go and delete the directory tree.- Parameters:
d- the directory to delete
-
deleteDir
Go and delete the directory tree.- Parameters:
d- the directory to deletedeleteFiles- whether to delete files
-
renameFile
protected boolean renameFile(File sourceFile, File destFile, boolean filtering, boolean overwrite) throws IOException, BuildException Attempts to rename a file from a source to a destination. If overwrite is set to true, this method overwrites existing file even if the destination file is newer. Otherwise, the source file is renamed only if the destination file is older than it. Method then checks if token filtering is used. If it is, this method returns false assuming it is the responsibility to the copyFile method.- Parameters:
sourceFile- the file to renamedestFile- the destination filefiltering- if true, filtering is in operation, file will be copied/deleted instead of renamedoverwrite- if true force overwrite even if destination file is newer than source file- Returns:
- true if the file was renamed
- Throws:
IOException- if an error occursBuildException- if an error occurs
-