@Plugin(name="Delete", category="Core", printObject=true) public class DeleteAction extends AbstractPathAction
| Modifier and Type | Field and Description |
|---|---|
private PathSorter |
pathSorter |
private ScriptCondition |
scriptCondition |
private boolean |
testMode |
LOGGER| Constructor and Description |
|---|
DeleteAction(java.lang.String basePath,
boolean followSymbolicLinks,
int maxDepth,
boolean testMode,
PathSorter sorter,
PathCondition[] pathConditions,
ScriptCondition scriptCondition,
StrSubstitutor subst)
Creates a new DeleteAction that starts scanning for files to delete from the specified base path.
|
| Modifier and Type | Method and Description |
|---|---|
private java.util.List<PathWithAttributes> |
callScript() |
static DeleteAction |
createDeleteAction(java.lang.String basePath,
boolean followLinks,
int maxDepth,
boolean testMode,
PathSorter sorterParameter,
PathCondition[] pathConditions,
ScriptCondition scriptCondition,
Configuration config)
Create a DeleteAction.
|
protected java.nio.file.FileVisitor<java.nio.file.Path> |
createFileVisitor(java.nio.file.Path visitorBaseDir,
java.util.List<PathCondition> conditions)
Creates a new
FileVisitor<Path> to pass to the Files.walkFileTree(Path, Set, int, FileVisitor)
method when the AbstractPathAction.execute() method is invoked. |
protected void |
delete(java.nio.file.Path path)
Deletes the specified file.
|
private void |
deleteSelectedFiles(java.util.List<PathWithAttributes> selectedForDeletion) |
boolean |
execute()
Performs action.
|
boolean |
execute(java.nio.file.FileVisitor<java.nio.file.Path> visitor) |
private boolean |
executeScript() |
(package private) java.util.List<PathWithAttributes> |
getSortedPaths()
Returns a sorted list of all files up to maxDepth under the basePath.
|
boolean |
isTestMode()
Returns
true if files are not deleted even when all conditions accept a path, false otherwise. |
private void |
trace(java.lang.String label,
java.util.List<PathWithAttributes> sortedPaths) |
getBasePath, getBasePathString, getMaxDepth, getOptions, getPathConditions, getStrSubstitutor, isFollowSymbolicLinks, toStringclose, isComplete, isInterrupted, reportException, runprivate final PathSorter pathSorter
private final boolean testMode
private final ScriptCondition scriptCondition
DeleteAction(java.lang.String basePath,
boolean followSymbolicLinks,
int maxDepth,
boolean testMode,
PathSorter sorter,
PathCondition[] pathConditions,
ScriptCondition scriptCondition,
StrSubstitutor subst)
basePath - base path from where to start scanning for files to delete.followSymbolicLinks - whether to follow symbolic links. Default is false.maxDepth - The maxDepth parameter is the maximum number of levels of directories to visit. A value of 0
means that only the starting file is visited, unless denied by the security manager. A value of
MAX_VALUE may be used to indicate that all levels should be visited.testMode - if true, files are not deleted but instead a message is printed to the status logger
at INFO level. Users can use this to do a dry run to test if their configuration works as expected.sorter - sortspathConditions - an array of path filters (if more than one, they all need to accept a path before it is
deleted).scriptCondition - public boolean execute()
throws java.io.IOException
AbstractActionexecute in interface Actionexecute in class AbstractPathActionjava.io.IOException - if IO error.private boolean executeScript()
throws java.io.IOException
java.io.IOExceptionprivate java.util.List<PathWithAttributes> callScript() throws java.io.IOException
java.io.IOExceptionprivate void deleteSelectedFiles(java.util.List<PathWithAttributes> selectedForDeletion) throws java.io.IOException
java.io.IOExceptionprotected void delete(java.nio.file.Path path)
throws java.io.IOException
path - the file to deletejava.io.IOException - if a problem occurred deleting the filepublic boolean execute(java.nio.file.FileVisitor<java.nio.file.Path> visitor)
throws java.io.IOException
execute in class AbstractPathActionjava.io.IOExceptionprivate void trace(java.lang.String label,
java.util.List<PathWithAttributes> sortedPaths)
java.util.List<PathWithAttributes> getSortedPaths() throws java.io.IOException
java.io.IOExceptionpublic boolean isTestMode()
true if files are not deleted even when all conditions accept a path, false otherwise.true if files are not deleted even when all conditions accept a path, false otherwiseprotected java.nio.file.FileVisitor<java.nio.file.Path> createFileVisitor(java.nio.file.Path visitorBaseDir,
java.util.List<PathCondition> conditions)
AbstractPathActionFileVisitor<Path> to pass to the Files.walkFileTree(Path, Set, int, FileVisitor)
method when the AbstractPathAction.execute() method is invoked.
The visitor is responsible for processing the files it encounters that are accepted by all filters.
createFileVisitor in class AbstractPathActionvisitorBaseDir - base dir from where to start scanning for files to processconditions - filters that determine if a file should be processedFileVisitor<Path>@PluginFactory public static DeleteAction createDeleteAction(@PluginAttribute(value="basePath") java.lang.String basePath, @PluginAttribute(value="followLinks") boolean followLinks, @PluginAttribute(value="maxDepth",defaultInt=1) int maxDepth, @PluginAttribute(value="testMode") boolean testMode, @PluginElement(value="PathSorter") PathSorter sorterParameter, @PluginElement(value="PathConditions") PathCondition[] pathConditions, @PluginElement(value="ScriptCondition") ScriptCondition scriptCondition, @PluginConfiguration Configuration config)
basePath - base path from where to start scanning for files to delete.followLinks - whether to follow symbolic links. Default is false.maxDepth - The maxDepth parameter is the maximum number of levels of directories to visit. A value of 0
means that only the starting file is visited, unless denied by the security manager. A value of
MAX_VALUE may be used to indicate that all levels should be visited.testMode - if true, files are not deleted but instead a message is printed to the status logger
at INFO level. Users can use this to do a dry run to test if their configuration works as expected.
Default is false.PathSorter - a plugin implementing the PathSorter interfacePathConditions - an array of path conditions (if more than one, they all need to accept a path before it is
deleted).config - The Configuration.