Top Description Fields Constructors Methods
org.apache.tools.ant.taskdefs

public Class Move

extends Copy
Class Inheritance
Imports
java.io.File, .IOException, java.util.Map, org.apache.tools.ant.BuildException, .DirectoryScanner, .Project, org.apache.tools.ant.taskdefs.condition.Os, org.apache.tools.ant.types.FileSet, .FilterSetCollection

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

Modifier and TypeField and Description
private boolean
Inherited from org.apache.tools.ant.taskdefs.Copy:
completeDirMapdestDirdestFiledirCopyMapfailonerrorfilefileCopyMapfilesetsfileUtilsfilteringflattenforceOverwriteincludeEmptyLINE_SEPARATORmapperElementNULL_FILE_PLACEHOLDERpreserveLastModifiedrcsverbosity

Constructor Summary

AccessConstructor and Description
public
Move()

Constructor of object.

Method Summary

Modifier and TypeMethod and Description
private void
copyFile(File
File
fromFile
,
File
File
toFile
,
boolean
boolean
filtering
,
boolean
boolean
overwrite
)

Copy fromFile to toFile.

protected void
deleteDir(File
the directory to delete
d
)

Go and delete the directory tree.

protected void
deleteDir(File
the directory to delete
d
,
boolean
whether to delete files
deleteFiles
)

Go and delete the directory tree.

protected void
doFileOperations()

Overrides org.apache.tools.ant.taskdefs.Copy.doFileOperations.

Override copy's doFileOperations to move the files instead of copying them.
private void
moveFile(File fromFile, File toFile, boolean filtering, boolean overwrite)

Try to move the file via a rename, but if this fails or filtering is enabled, copy the file then delete the sourceFile.

protected boolean

Returns:

true if a deletion can go ahead
okToDelete
(File
the directory to check
d
)

Its only ok to delete a directory tree if there are no files in it.

protected boolean

Returns:

true if the file was renamed
renameFile
(File
the file to rename
sourceFile
,
File
the destination file
destFile
,
boolean
if true, filtering is in operation, file will be copied/deleted instead of renamed
filtering
,
boolean
if true force overwrite even if destination file is newer than source file
overwrite
)

Attempts to rename a file from a source to a destination.

public void
setPerformGcOnFailedDelete(boolean
boolean
b
)

Whether to perform a garbage collection before retrying a failed delete.

protected void
validateAttributes()

Overrides org.apache.tools.ant.taskdefs.Copy.validateAttributes.

Ensure we have a consistent and legal set of attributes, and set any internal flags necessary based on different combinations of attributes..
Inherited from org.apache.tools.ant.taskdefs.Copy:
addaddaddFilesetbuildMapbuildMapcreateFilterChaincreateFilterSetcreateMapperdoResourceOperationsexecutegetEncodinggetFileUtilsgetFilterChainsgetFilterSetsgetForcegetOutputEncodinggetPreserveLastModifiedisEnableMultipleMappingscanscansetEnableMultipleMappingssetEncodingsetFailOnErrorsetFilesetFilteringsetFlattensetForcesetGranularitysetIncludeEmptyDirssetOutputEncodingsetOverwritesetPreserveLastModifiedsetPreserveLastModifiedsetQuietsetTodirsetTofilesetVerbosesupportsNonFileResources

Field Detail

performGcback to summary
private boolean performGc

Constructor Detail

Moveback to summary
public Move()

Constructor of object. This sets the forceOverwrite attribute of the Copy parent class to true.

Method Detail

copyFileback to summary
private void copyFile(File fromFile, File toFile, boolean filtering, boolean overwrite)

Copy fromFile to toFile.

Parameters
fromFile:File

File

toFile:File

File

filtering:boolean

boolean

overwrite:boolean

boolean

deleteDirback to summary
protected void deleteDir(File d)

Go and delete the directory tree.

Parameters
d:File

the directory to delete

deleteDirback to summary
protected void deleteDir(File d, boolean deleteFiles)

Go and delete the directory tree.

Parameters
d:File

the directory to delete

deleteFiles:boolean

whether to delete files

doFileOperationsback to summary
protected void doFileOperations()

Overrides org.apache.tools.ant.taskdefs.Copy.doFileOperations.

Override copy's doFileOperations to move the files instead of copying them.

Annotations
@Override
moveFileback to summary
private void moveFile(File fromFile, File toFile, boolean filtering, boolean overwrite)

Try to move the file via a rename, but if this fails or filtering is enabled, copy the file then delete the sourceFile.

okToDeleteback to summary
protected boolean okToDelete(File d)

Its only ok to delete a directory tree if there are no files in it.

Parameters
d:File

the directory to check

Returns:boolean

true if a deletion can go ahead

renameFileback to summary
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:File

the file to rename

destFile:File

the destination file

filtering:boolean

if true, filtering is in operation, file will be copied/deleted instead of renamed

overwrite:boolean

if true force overwrite even if destination file is newer than source file

Returns:boolean

true if the file was renamed

Exceptions
IOException:
if an error occurs
BuildException:
if an error occurs
setPerformGcOnFailedDeleteback to summary
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

boolean

Since
Ant 1.8.3
validateAttributesback to summary
protected void validateAttributes() throws BuildException

Overrides org.apache.tools.ant.taskdefs.Copy.validateAttributes.

Doc from org.apache.tools.ant.taskdefs.Copy.validateAttributes.

Ensure we have a consistent and legal set of attributes, and set any internal flags necessary based on different combinations of attributes..

Annotations
@Override
Exceptions
BuildException:
if an error occurs.