-
Notifications
You must be signed in to change notification settings - Fork 56
Replace Plexus dependency by more extensive usage of java.nio
#243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…io`. 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`.
…EFAULTEXCLUDES` array.
Now all tests pass, Windows included. |
The scanner is used in maven-filtering which is used in maven-resources-plugin. The fact that the Maven 4 API exposes PathMatcher while the plexus scanner uses String[] is a problematic. So yes, definitely interested in having this piece of code reusable. |
We can also revert this API to plain strings, and complete them by a |
I think that would make sense. The point is that the resource plugin can also be configured from the plugin, so with |
Okay, will prepare a pull request maybe tonight. |
Actually, maybe the problem was just in the implementation of the |
Forget the above. Even just for the sake of being able to obtain |
Created apache/maven#2232 |
We have to reviewers. Any objection that I perform the merge? If okay, I would turn the "add a force option" branch into a new pull request after this merge. |
(Copy of #242, which was accidentally merged. The merge has been immediately cancelled)
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.