Replace Plexus dependency by more extensive usage of java.nio
#242
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Remove the dependency to Plexus, replaced by more reliance on
java.nio
.Work items
java.nio.file.PathMatcher
. A 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 (see below).java.nio.file.FileVisitor
for walking over files and directory trees. Consequently, symbolic links are now followed byFileVisitor
instead of bymaven-clean-plugin
itself. An advantage is thatFileVisitor
is safe against infinite loops when there is cycles. Also, file attributes (whether the file is regular, a directory or a link) are queried only once per file.IOException
throws by Java is no longer wrapped in anotherIOException
, 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 theAccessDeniedException
. Instead, it was aDirectoryNotEmptyException
thrown when the plugin tried to delete the directory that contains the file that the plugin failed to delete. After this commit, the exception thrown is the originalAccessDeniedException
.Matcher syntax
The "glob" syntax of
java.nio.file.PathMatcher
seems to have slightly different rules than Plexus. In particular, the tests suggest that the**
pattern means "0 or more directories" in Maven 3 whereas the "glob" syntax ofPathMatcher
seems to understand**
as "1 or more directories". This commit applies the following rules:/
(the standardized separator expected byPathMatcher
).**
, generate new patterns without the**
in order to simulate the case of 0 directory.glob:
to the resulting pattern.Risk
This commit is a significant changes. While the JUnir and integration tests pass, there is still a risk for some unforeseen behavioural changes. Differences compared to the previous version will be addressed as they are reported. There is also non-trivial optimizations for deciding whether to skip and entire directory (those optimizations were already present in the previous version, but behind Plexus).
Future work
If experience shows that the new version is working well, maybe we should move the
Selector
class and an abstractFileVisitor
base class to Maven core for allowing other plugins, such asmaven-compiler-plugin
, to use it.