Skip to content

Commit 9085e2b

Browse files
committed
Remove the dependency to Plexus, replaced by more reliance on java.nio.
This commit contains the following work items: * Replacement of Plexus includes/excludes filters by `java.nio.file.PathMatcher`. One benefit is the support of different syntax, at least "glob" and "regex". If no syntax is specified, default to the "glob" syntax with modifications for reproducing the behavior of Plexus filters when it differs from "glob". * Use `java.nio.file.FileVisitor` for walking over files and directory trees. Consequently, the following of symbolic links is now handled by `FileVisitor` instead of by `maven-clean-plugin` itself. An advantage is that `FileVisitor` is safe against infinite loops when there is cycles in the symbolic links. Also, file attributes (whether the file is regular, a directory or a link) are queried only once per file. * Changes in some logging messages and exceptions. "Deleting XYZ" is replaced by either "Deleted XYZ" if the deletion has been successful, or replaced by "Failed to delete XYZ" in case of failure (i.e., "XYZ" is not logged twice in case of failure). * The `IOException` throws by Java is no longer wrapped in another `IOException`, so that the callers can catch an exception of the specific sub-type if desired. The exception is also thrown earlier, before it causes another exception. The difference can be seen in the tests: a deletion fails because unauthorized, but the error that was reported to the user was not the `AccessDeniedException`. Instead, it was a `DirectoryNotEmptyException` thrown when the plugin tried to delete the directory that contains the file that the plugin failed to delete. After this commit, the exception throws is the original `AccessDeniedException`.
1 parent 39b9ee1 commit 9085e2b

File tree

7 files changed

+637
-409
lines changed

7 files changed

+637
-409
lines changed

src/main/java/org/apache/maven/plugins/clean/CleanMojo.java

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public class CleanMojo implements org.apache.maven.api.plugin.Mojo {
222222
@Override
223223
public void execute() {
224224
if (skip) {
225-
getLog().info("Clean is skipped.");
225+
logger.info("Clean is skipped.");
226226
return;
227227
}
228228

@@ -236,7 +236,7 @@ public void execute() {
236236
} else {
237237
fastDir = null;
238238
if (fast) {
239-
getLog().warn("Fast clean requires maven 3.3.1 or newer, "
239+
logger.warn("Fast clean requires maven 3.3.1 or newer, "
240240
+ "or an explicit directory to be specified with the 'fastDir' configuration of "
241241
+ "this plugin, or the 'maven.clean.fastDir' user property to be set.");
242242
}
@@ -248,37 +248,22 @@ public void execute() {
248248
throw new IllegalArgumentException("Illegal value '" + fastMode + "' for fastMode. Allowed values are '"
249249
+ FAST_MODE_BACKGROUND + "', '" + FAST_MODE_AT_END + "' and '" + FAST_MODE_DEFER + "'.");
250250
}
251-
252-
Cleaner cleaner = new Cleaner(session, getLog(), isVerbose(), fastDir, fastMode);
253-
251+
final var cleaner =
252+
new Cleaner(session, logger, isVerbose(), fastDir, fastMode, followSymLinks, failOnError, retryOnError);
254253
try {
255254
for (Path directoryItem : getDirectories()) {
256255
if (directoryItem != null) {
257-
cleaner.delete(directoryItem, null, followSymLinks, failOnError, retryOnError);
256+
cleaner.delete(directoryItem);
258257
}
259258
}
260-
261259
if (filesets != null) {
262260
for (Fileset fileset : filesets) {
263261
if (fileset.getDirectory() == null) {
264262
throw new MojoException("Missing base directory for " + fileset);
265263
}
266-
final String[] includes = fileset.getIncludes();
267-
final String[] excludes = fileset.getExcludes();
268-
final boolean useDefaultExcludes = fileset.isUseDefaultExcludes();
269-
final GlobSelector selector;
270-
if ((includes != null && includes.length != 0)
271-
|| (excludes != null && excludes.length != 0)
272-
|| useDefaultExcludes) {
273-
selector = new GlobSelector(includes, excludes, useDefaultExcludes);
274-
} else {
275-
selector = null;
276-
}
277-
cleaner.delete(
278-
fileset.getDirectory(), selector, fileset.isFollowSymlinks(), failOnError, retryOnError);
264+
cleaner.delete(fileset);
279265
}
280266
}
281-
282267
} catch (IOException e) {
283268
throw new MojoException("Failed to clean project: " + e.getMessage(), e);
284269
}
@@ -290,7 +275,7 @@ public void execute() {
290275
* @return <code>true</code> if verbose output is enabled, <code>false</code> otherwise.
291276
*/
292277
private boolean isVerbose() {
293-
return (verbose != null) ? verbose : getLog().isDebugEnabled();
278+
return (verbose != null) ? verbose : logger.isDebugEnabled();
294279
}
295280

296281
/**
@@ -307,8 +292,4 @@ private Path[] getDirectories() {
307292
}
308293
return directories;
309294
}
310-
311-
private Log getLog() {
312-
return logger;
313-
}
314295
}

0 commit comments

Comments
 (0)