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:
java.lang.Cloneable,SelectorContainer
public class Delete extends MatchingTask
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
Fields Modifier and Type Field Description protected java.io.Filedirprotected java.io.Filefileprotected java.util.Vector<FileSet>filesetsprotected booleanincludeEmptyprotected booleanusedMatchingTask-
Fields inherited from class org.apache.tools.ant.taskdefs.MatchingTask
fileset
-
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
-
-
Constructor Summary
Constructors Constructor Description Delete()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(ResourceCollection rc)Add 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 listPatternSet.NameEntrycreateExclude()add a name entry on the exclude listPatternSet.NameEntrycreateExcludesFile()add a name entry on the include files listPatternSet.NameEntrycreateInclude()add a name entry on the include listPatternSet.NameEntrycreateIncludesFile()add a name entry on the include files listPatternSetcreatePatternSet()add a set of patternsvoidexecute()Delete the file(s).protected voidremoveDir(java.io.File d)Delete a directoryprotected voidremoveFiles(java.io.File d, java.lang.String[] files, java.lang.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 continuevoidsetDir(java.io.File dir)Set the directory from which files are to be deletedvoidsetExcludes(java.lang.String excludes)Sets the set of exclude patterns.voidsetExcludesfile(java.io.File excludesfile)Sets the name of the file containing the includes patterns.voidsetFailOnError(boolean failonerror)If false, note errors but continue.voidsetFile(java.io.File file)Set 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(java.lang.String includes)Sets the set of include patterns.voidsetIncludesfile(java.io.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, XsetItems
-
Methods 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, setTaskType
-
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation
-
-
-
-
Field Detail
-
file
protected java.io.File file
-
dir
protected java.io.File dir
-
filesets
protected java.util.Vector<FileSet> filesets
-
usedMatchingTask
protected boolean usedMatchingTask
-
includeEmpty
protected boolean includeEmpty
-
-
Method Detail
-
setFile
public void setFile(java.io.File file)
Set the name of a single file to be removed.- Parameters:
file- the file to be deleted
-
setDir
public void setDir(java.io.File dir)
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
public void addFileset(FileSet set)
Adds a set of files to be deleted.- Parameters:
set- the set of files to be deleted
-
add
public void add(ResourceCollection rc)
Add an arbitrary ResourceCollection to be deleted.- Parameters:
rc- the filesystem-only ResourceCollection.
-
createInclude
public PatternSet.NameEntry createInclude()
add a name entry on the include list- Overrides:
createIncludein classMatchingTask- Returns:
- a NameEntry object to be configured
-
createIncludesFile
public PatternSet.NameEntry createIncludesFile()
add a name entry on the include files list- Overrides:
createIncludesFilein classMatchingTask- Returns:
- a PatternFileNameEntry object to be configured
-
createExclude
public PatternSet.NameEntry createExclude()
add a name entry on the exclude list- Overrides:
createExcludein classMatchingTask- Returns:
- a NameEntry object to be configured
-
createExcludesFile
public PatternSet.NameEntry createExcludesFile()
add a name entry on the include files list- Overrides:
createExcludesFilein classMatchingTask- Returns:
- a PatternFileNameEntry object to be configured
-
createPatternSet
public PatternSet createPatternSet()
add a set of patterns- Overrides:
createPatternSetin classMatchingTask- Returns:
- PatternSet object to be configured
-
setIncludes
public void setIncludes(java.lang.String includes)
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
public void setExcludes(java.lang.String excludes)
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
public void setIncludesfile(java.io.File includesfile)
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
public void setExcludesfile(java.io.File excludesfile)
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
public void addSelector(SelectSelector selector)
add a "Select" selector entry on the selector list- Specified by:
addSelectorin interfaceSelectorContainer- Overrides:
addSelectorin classMatchingTask- Parameters:
selector- the selector to be added
-
addAnd
public void addAnd(AndSelector selector)
add an "And" selector entry on the selector list- Specified by:
addAndin interfaceSelectorContainer- Overrides:
addAndin classMatchingTask- Parameters:
selector- the selector to be added
-
addOr
public void addOr(OrSelector selector)
add an "Or" selector entry on the selector list- Specified by:
addOrin interfaceSelectorContainer- Overrides:
addOrin classMatchingTask- Parameters:
selector- the selector to be added
-
addNot
public void addNot(NotSelector selector)
add a "Not" selector entry on the selector list- Specified by:
addNotin interfaceSelectorContainer- Overrides:
addNotin classMatchingTask- Parameters:
selector- the selector to be added
-
addNone
public void addNone(NoneSelector selector)
add a "None" selector entry on the selector list- Specified by:
addNonein interfaceSelectorContainer- Overrides:
addNonein classMatchingTask- Parameters:
selector- the selector to be added
-
addMajority
public void addMajority(MajoritySelector selector)
add a majority selector entry on the selector list- Specified by:
addMajorityin interfaceSelectorContainer- Overrides:
addMajorityin classMatchingTask- Parameters:
selector- the selector to be added
-
addDate
public void addDate(DateSelector selector)
add a selector date entry on the selector list- Specified by:
addDatein interfaceSelectorContainer- Overrides:
addDatein classMatchingTask- Parameters:
selector- the selector to be added
-
addSize
public void addSize(SizeSelector selector)
add a selector size entry on the selector list- Specified by:
addSizein interfaceSelectorContainer- Overrides:
addSizein classMatchingTask- Parameters:
selector- the selector to be added
-
addFilename
public void addFilename(FilenameSelector selector)
add a selector filename entry on the selector list- Specified by:
addFilenamein interfaceSelectorContainer- Overrides:
addFilenamein classMatchingTask- Parameters:
selector- the selector to be added
-
addCustom
public void addCustom(ExtendSelector selector)
add an extended selector entry on the selector list- Specified by:
addCustomin interfaceSelectorContainer- Overrides:
addCustomin classMatchingTask- Parameters:
selector- the selector to be added
-
addContains
public void addContains(ContainsSelector selector)
add a contains selector entry on the selector list- Specified by:
addContainsin interfaceSelectorContainer- Overrides:
addContainsin classMatchingTask- Parameters:
selector- the selector to be added
-
addPresent
public void addPresent(PresentSelector selector)
add a present selector entry on the selector list- Specified by:
addPresentin interfaceSelectorContainer- Overrides:
addPresentin classMatchingTask- Parameters:
selector- the selector to be added
-
addDepth
public void addDepth(DepthSelector selector)
add a depth selector entry on the selector list- Specified by:
addDepthin interfaceSelectorContainer- Overrides:
addDepthin classMatchingTask- Parameters:
selector- the selector to be added
-
addDepend
public void addDepend(DependSelector selector)
add a depends selector entry on the selector list- Specified by:
addDependin interfaceSelectorContainer- Overrides:
addDependin classMatchingTask- Parameters:
selector- the selector to be added
-
addContainsRegexp
public void addContainsRegexp(ContainsRegexpSelector selector)
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
public void addModified(ModifiedSelector selector)
add the modified selector- Specified by:
addModifiedin interfaceSelectorContainer- Overrides:
addModifiedin classMatchingTask- Parameters:
selector- the selector to add- Since:
- ant 1.6
-
add
public void add(FileSelector selector)
add an arbitrary selector- Specified by:
addin interfaceSelectorContainer- Overrides:
addin classMatchingTask- Parameters:
selector- the selector to be added- Since:
- Ant 1.6
-
execute
public void execute() throws BuildExceptionDelete the file(s).- Overrides:
executein classTask- Throws:
BuildException- if an error occurs
-
removeDir
protected void removeDir(java.io.File d)
Delete a directory- Parameters:
d- the directory to delete
-
removeFiles
protected void removeFiles(java.io.File d, java.lang.String[] files, java.lang.String[] dirs)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
-
-