Package org.apache.tools.ant.taskdefs
Class Delete
java.lang.Object
org.apache.tools.ant.ProjectComponent
org.apache.tools.ant.Task
org.apache.tools.ant.taskdefs.MatchingTask
org.apache.tools.ant.taskdefs.Delete
- All Implemented Interfaces:
Cloneable,SelectorContainer
Deletes a file or directory, or set of files defined by a fileset.
The original delete task would delete a file, or a set of files
using the include/exclude syntax. The deltree task would delete a
directory tree. This task combines the functionality of these two
originally distinct tasks.
Currently Delete extends MatchingTask. This is intended only to provide backwards compatibility for a release. The future position is to use nested filesets exclusively.
- Since:
- Ant 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Fileprotected Fileprotected booleanprotected booleanFields inherited from class org.apache.tools.ant.taskdefs.MatchingTask
filesetFields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an arbitrary ResourceCollection to be deleted.voidadd(FileSelector selector) add an arbitrary selectorvoidaddAnd(AndSelector selector) add an "And" selector entry on the selector listvoidaddContains(ContainsSelector selector) add a contains selector entry on the selector listvoidaddContainsRegexp(ContainsRegexpSelector selector) add a regular expression selector entry on the selector listvoidaddCustom(ExtendSelector selector) add an extended selector entry on the selector listvoidaddDate(DateSelector selector) add a selector date entry on the selector listvoidaddDepend(DependSelector selector) add a depends selector entry on the selector listvoidaddDepth(DepthSelector selector) add a depth selector entry on the selector listvoidaddFilename(FilenameSelector selector) add a selector filename entry on the selector listvoidaddFileset(FileSet set) Adds a set of files to be deleted.voidaddMajority(MajoritySelector selector) add a majority selector entry on the selector listvoidaddModified(ModifiedSelector selector) add the modified selectorvoidaddNone(NoneSelector selector) add a "None" selector entry on the selector listvoidaddNot(NotSelector selector) add a "Not" selector entry on the selector listvoidaddOr(OrSelector selector) add an "Or" selector entry on the selector listvoidaddPresent(PresentSelector selector) add a present selector entry on the selector listvoidaddSelector(SelectSelector selector) add a "Select" selector entry on the selector listvoidaddSize(SizeSelector selector) add a selector size entry on the selector listadd a name entry on the exclude listadd a name entry on the include files listadd a name entry on the include listadd a name entry on the include files listadd a set of patternsvoidexecute()Delete the file(s).protected voidDelete a directoryprotected voidremoveFiles(File d, String[] files, String[] dirs) remove an array of files in a directory, and a list of subdirectories which will only be deleted if 'includeEmpty' is truevoidsetCaseSensitive(boolean isCaseSensitive) Sets case sensitivity of the file systemvoidsetDefaultexcludes(boolean useDefaultExcludes) Sets whether default exclusions should be used or not.voidsetDeleteOnExit(boolean deleteOnExit) If true, on failure to delete, note the error and set the deleteonexit flag, and continuevoidSet the directory from which files are to be deletedvoidsetExcludes(String excludes) Sets the set of exclude patterns.voidsetExcludesfile(File excludesfile) Sets the name of the file containing the includes patterns.voidsetFailOnError(boolean failonerror) If false, note errors but continue.voidSet the name of a single file to be removed.voidsetFollowSymlinks(boolean followSymlinks) Sets whether or not symbolic links should be followed.voidsetIncludeEmptyDirs(boolean includeEmpty) If true, delete empty directories.voidsetIncludes(String includes) Sets the set of include patterns.voidsetIncludesfile(File includesfile) Sets the name of the file containing the includes patterns.voidsetPerformGcOnFailedDelete(boolean b) Whether to perform a garbage collection before retrying a failed delete.voidsetQuiet(boolean quiet) If true and the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error.voidsetRemoveNotFollowedSymlinks(boolean b) Sets whether the symbolic links that have not been followed shall be removed (the links, not the locations they point at).voidsetVerbose(boolean verbose) If true, list all names of deleted files.Methods inherited from class org.apache.tools.ant.taskdefs.MatchingTask
addDifferent, addType, appendSelector, getDirectoryScanner, getImplicitFileSet, getSelectors, hasSelectors, selectorCount, selectorElements, setProject, XsetIgnore, XsetItemsMethods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskTypeMethods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation
-
Field Details
-
file
-
dir
-
filesets
-
usedMatchingTask
protected boolean usedMatchingTask -
includeEmpty
protected boolean includeEmpty
-
-
Constructor Details
-
Delete
public Delete()
-
-
Method Details
-
setFile
Set the name of a single file to be removed.- Parameters:
file- the file to be deleted
-
setDir
Set the directory from which files are to be deleted- Parameters:
dir- the directory path.
-
setVerbose
public void setVerbose(boolean verbose) If true, list all names of deleted files.- Parameters:
verbose- "true" or "on"
-
setQuiet
public void setQuiet(boolean quiet) If true and the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error. This means that if a file or directory cannot be deleted, then no error is reported. This setting emulates the -f option to the Unix "rm" command. Default is false meaning things are "noisy"- Parameters:
quiet- "true" or "on"
-
setFailOnError
public void setFailOnError(boolean failonerror) If false, note errors but continue.- Parameters:
failonerror- true or false
-
setDeleteOnExit
public void setDeleteOnExit(boolean deleteOnExit) If true, on failure to delete, note the error and set the deleteonexit flag, and continue- Parameters:
deleteOnExit- true or false
-
setIncludeEmptyDirs
public void setIncludeEmptyDirs(boolean includeEmpty) If true, delete empty directories.- Parameters:
includeEmpty- if true delete empty directories (only for filesets). Default is false.
-
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
-
addFileset
Adds a set of files to be deleted.- Parameters:
set- the set of files to be deleted
-
add
Add an arbitrary ResourceCollection to be deleted.- Parameters:
rc- the filesystem-only ResourceCollection.
-
createInclude
add a name entry on the include list- Overrides:
createIncludein classMatchingTask- Returns:
- a NameEntry object to be configured
-
createIncludesFile
add a name entry on the include files list- Overrides:
createIncludesFilein classMatchingTask- Returns:
- a PatternFileNameEntry object to be configured
-
createExclude
add a name entry on the exclude list- Overrides:
createExcludein classMatchingTask- Returns:
- a NameEntry object to be configured
-
createExcludesFile
add a name entry on the include files list- Overrides:
createExcludesFilein classMatchingTask- Returns:
- a PatternFileNameEntry object to be configured
-
createPatternSet
add a set of patterns- Overrides:
createPatternSetin classMatchingTask- Returns:
- PatternSet object to be configured
-
setIncludes
Sets the set of include patterns. Patterns may be separated by a comma or a space.- Overrides:
setIncludesin classMatchingTask- Parameters:
includes- the string containing the include patterns
-
setExcludes
Sets the set of exclude patterns. Patterns may be separated by a comma or a space.- Overrides:
setExcludesin classMatchingTask- Parameters:
excludes- the string containing the exclude patterns
-
setDefaultexcludes
public void setDefaultexcludes(boolean useDefaultExcludes) Sets whether default exclusions should be used or not.- Overrides:
setDefaultexcludesin classMatchingTask- Parameters:
useDefaultExcludes- "true"|"on"|"yes" when default exclusions should be used, "false"|"off"|"no" when they shouldn't be used.
-
setIncludesfile
Sets the name of the file containing the includes patterns.- Overrides:
setIncludesfilein classMatchingTask- Parameters:
includesfile- A string containing the filename to fetch the include patterns from.
-
setExcludesfile
Sets the name of the file containing the includes patterns.- Overrides:
setExcludesfilein classMatchingTask- Parameters:
excludesfile- A string containing the filename to fetch the include patterns from.
-
setCaseSensitive
public void setCaseSensitive(boolean isCaseSensitive) Sets case sensitivity of the file system- Overrides:
setCaseSensitivein classMatchingTask- Parameters:
isCaseSensitive- "true"|"on"|"yes" if file system is case sensitive, "false"|"off"|"no" when not.
-
setFollowSymlinks
public void setFollowSymlinks(boolean followSymlinks) Sets whether or not symbolic links should be followed.- Overrides:
setFollowSymlinksin classMatchingTask- Parameters:
followSymlinks- whether or not symbolic links should be followed
-
setRemoveNotFollowedSymlinks
public void setRemoveNotFollowedSymlinks(boolean b) Sets whether the symbolic links that have not been followed shall be removed (the links, not the locations they point at).- Parameters:
b- boolean- Since:
- Ant 1.8.0
-
addSelector
add a "Select" selector entry on the selector list- Specified by:
addSelectorin interfaceSelectorContainer- Overrides:
addSelectorin classMatchingTask- Parameters:
selector- the selector to be added
-
addAnd
add an "And" selector entry on the selector list- Specified by:
addAndin interfaceSelectorContainer- Overrides:
addAndin classMatchingTask- Parameters:
selector- the selector to be added
-
addOr
add an "Or" selector entry on the selector list- Specified by:
addOrin interfaceSelectorContainer- Overrides:
addOrin classMatchingTask- Parameters:
selector- the selector to be added
-
addNot
add a "Not" selector entry on the selector list- Specified by:
addNotin interfaceSelectorContainer- Overrides:
addNotin classMatchingTask- Parameters:
selector- the selector to be added
-
addNone
add a "None" selector entry on the selector list- Specified by:
addNonein interfaceSelectorContainer- Overrides:
addNonein classMatchingTask- Parameters:
selector- the selector to be added
-
addMajority
add a majority selector entry on the selector list- Specified by:
addMajorityin interfaceSelectorContainer- Overrides:
addMajorityin classMatchingTask- Parameters:
selector- the selector to be added
-
addDate
add a selector date entry on the selector list- Specified by:
addDatein interfaceSelectorContainer- Overrides:
addDatein classMatchingTask- Parameters:
selector- the selector to be added
-
addSize
add a selector size entry on the selector list- Specified by:
addSizein interfaceSelectorContainer- Overrides:
addSizein classMatchingTask- Parameters:
selector- the selector to be added
-
addFilename
add a selector filename entry on the selector list- Specified by:
addFilenamein interfaceSelectorContainer- Overrides:
addFilenamein classMatchingTask- Parameters:
selector- the selector to be added
-
addCustom
add an extended selector entry on the selector list- Specified by:
addCustomin interfaceSelectorContainer- Overrides:
addCustomin classMatchingTask- Parameters:
selector- the selector to be added
-
addContains
add a contains selector entry on the selector list- Specified by:
addContainsin interfaceSelectorContainer- Overrides:
addContainsin classMatchingTask- Parameters:
selector- the selector to be added
-
addPresent
add a present selector entry on the selector list- Specified by:
addPresentin interfaceSelectorContainer- Overrides:
addPresentin classMatchingTask- Parameters:
selector- the selector to be added
-
addDepth
add a depth selector entry on the selector list- Specified by:
addDepthin interfaceSelectorContainer- Overrides:
addDepthin classMatchingTask- Parameters:
selector- the selector to be added
-
addDepend
add a depends selector entry on the selector list- Specified by:
addDependin interfaceSelectorContainer- Overrides:
addDependin classMatchingTask- Parameters:
selector- the selector to be added
-
addContainsRegexp
add a regular expression selector entry on the selector list- Specified by:
addContainsRegexpin interfaceSelectorContainer- Overrides:
addContainsRegexpin classMatchingTask- Parameters:
selector- the selector to be added
-
addModified
add the modified selector- Specified by:
addModifiedin interfaceSelectorContainer- Overrides:
addModifiedin classMatchingTask- Parameters:
selector- the selector to add- Since:
- ant 1.6
-
add
add an arbitrary selector- Specified by:
addin interfaceSelectorContainer- Overrides:
addin classMatchingTask- Parameters:
selector- the selector to be added- Since:
- Ant 1.6
-
execute
Delete the file(s).- Overrides:
executein classTask- Throws:
BuildException- if an error occurs
-
removeDir
Delete a directory- Parameters:
d- the directory to delete
-
removeFiles
remove an array of files in a directory, and a list of subdirectories which will only be deleted if 'includeEmpty' is true- Parameters:
d- directory to work fromfiles- array of files to delete; can be of zero lengthdirs- array of directories to delete; can of zero length
-