Package org.apache.maven.plugins.clean
Class Cleaner
java.lang.Object
org.apache.maven.plugins.clean.Cleaner
Cleans directories.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static class
(package private) static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Path
private final String
private final boolean
Whether to force the deletion of read-only files.private static final String
private org.apache.maven.plugin.logging.Log
private static final boolean
private final org.apache.maven.execution.MavenSession
The maven session.private final boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static IOException
private int
Deletes the specified file, directory.private Cleaner.Result
delete
(Path file, String pathname, Selector selector, boolean followSymlinks, boolean failOnError, boolean retryOnError) Deletes the specified file or directory.void
delete
(Path basedir, Selector selector, boolean followSymlinks, boolean failOnError, boolean retryOnError) Deletes the specified directories and its contents.private boolean
fastDelete
(Path baseDir) private boolean
isSymbolicLink
(Path path) private static Path
setWritable
(Path file) Makes the given file or directory writable.
-
Field Details
-
ON_WINDOWS
private static final boolean ON_WINDOWS -
LAST_DIRECTORY_TO_DELETE
-
session
private final org.apache.maven.execution.MavenSession sessionThe maven session. This is typically non-null in a real run, but it can be during unit tests. -
fastDir
-
fastMode
-
verbose
private final boolean verbose -
log
private org.apache.maven.plugin.logging.Log log -
force
private final boolean forceWhether to force the deletion of read-only files. Note that on Linux,Files.delete(Path)
andFiles.deleteIfExists(Path)
delete read-only files but throwAccessDeniedException
if the directory containing the file is read-only.
-
-
Constructor Details
-
Cleaner
Cleaner(org.apache.maven.execution.MavenSession session, org.apache.maven.plugin.logging.Log log, boolean verbose, Path fastDir, String fastMode, boolean force) Creates a new cleaner.- Parameters:
session
- The Maven session to be used.log
- The logger to use.verbose
- Whether to perform verbose logging.fastDir
- The explicit configured directory or to be deleted in fast mode.fastMode
- The fast deletion mode.force
- whether to force the deletion of read-only files
-
-
Method Details
-
delete
public void delete(Path basedir, Selector selector, boolean followSymlinks, boolean failOnError, boolean retryOnError) throws IOException Deletes the specified directories and its contents.- Parameters:
basedir
- The directory to delete, must not benull
. Non-existing directories will be silently ignored.selector
- The selector used to determine what contents to delete, may benull
to delete everything.followSymlinks
- Whether to follow symlinks.failOnError
- Whether to abort with an exception in case a selected file/directory could not be deleted.retryOnError
- Whether to undertake additional delete attempts in case the first attempt failed.- Throws:
IOException
- If a file/directory could not be deleted andfailOnError
istrue
.
-
fastDelete
-
delete
private Cleaner.Result delete(Path file, String pathname, Selector selector, boolean followSymlinks, boolean failOnError, boolean retryOnError) throws IOException Deletes the specified file or directory.- Parameters:
file
- The file/directory to delete, must not benull
. IffollowSymlinks
isfalse
, it is assumed that the parent file is canonical.pathname
- The relative pathname of the file, usingFile.separatorChar
, must not benull
.selector
- The selector used to determine what contents to delete, may benull
to delete everything.followSymlinks
- Whether to follow symlinks.failOnError
- Whether to abort with an exception in case a selected file/directory could not be deleted.retryOnError
- Whether to undertake additional delete attempts in case the first attempt failed.- Returns:
- The result of the cleaning, never
null
. - Throws:
IOException
- If a file/directory could not be deleted andfailOnError
istrue
.
-
isSymbolicLink
- Throws:
IOException
-
setWritable
Makes the given file or directory writable. If the file is already writable, then this method tries to make the parent directory writable.- Parameters:
file
- the path to the file or directory to make writable, ornull
if none- Returns:
- the root path which has been made writable, or
null
if none - Throws:
IOException
-
delete
Deletes the specified file, directory. If the path denotes a symlink, only the link is removed, its target is left untouched.- Parameters:
file
- The file/directory to delete, must not benull
.failOnError
- Whether to abort with an exception in case the file/directory could not be deleted.retryOnError
- Whether to undertake additional delete attempts in case the first attempt failed.- Returns:
0
if the file was deleted,1
otherwise.- Throws:
IOException
- If a file/directory could not be deleted andfailOnError
istrue
.
-
delete
-