[maven-4.0.x] Add PathMatcherFactory service with directory filtering optimization (#10923)#10926
Merged
gnodet merged 1 commit intoapache:maven-4.0.xfrom Jul 18, 2025
Merged
Conversation
…pache#10923) This PR adds a comprehensive PathMatcherFactory service to Maven 4 API with directory filtering optimization capabilities, addressing the need for exclude-only pattern matching and performance optimizations. ## New API Features ### PathMatcherFactory Interface - createPathMatcher(baseDirectory, includes, excludes, useDefaultExcludes) - createPathMatcher(baseDirectory, includes, excludes) - convenience overload - createExcludeOnlyMatcher(baseDirectory, excludes, useDefaultExcludes) - createIncludeOnlyMatcher(baseDirectory, includes) - convenience method - deriveDirectoryMatcher(fileMatcher) - directory filtering optimization ### DefaultPathMatcherFactory Implementation - Full implementation of all PathMatcherFactory methods - Delegates to PathSelector for actual pattern matching - Provides directory optimization via PathSelector.couldHoldSelected() - Fail-safe design returning INCLUDES_ALL for unknown matcher types ## PathSelector Enhancements ### Null Safety Improvements - Added @nonnull annotation to constructor directory parameter - Added Objects.requireNonNull() validation with descriptive error message - Moved baseDirectory assignment to beginning for fail-fast behavior - Updated JavaDoc to document NullPointerException behavior ### Directory Filtering Support - Added canFilterDirectories() method to check optimization capability - Made INCLUDES_ALL field package-private for factory reuse - Enhanced couldHoldSelected() method accessibility ## Directory Filtering Optimization The deriveDirectoryMatcher() method enables significant performance improvements by allowing plugins to skip entire directory trees when they definitively won't contain matching files. This preserves Maven 3's optimization behavior. ### Usage Example: ## Comprehensive Testing ### DefaultPathMatcherFactoryTest - Tests all factory methods with various parameter combinations - Verifies null parameter handling (NullPointerException) - Tests directory matcher derivation functionality - Includes edge cases and fail-safe behavior verification ### Backward Compatibility - All existing PathSelector functionality preserved - No breaking changes to existing APIs - Enhanced error handling with better exception types ## Benefits 1. **Plugin Compatibility**: Enables maven-clean-plugin and other plugins to use exclude-only patterns efficiently 2. **Performance**: Directory filtering optimization preserves Maven 3 behavior 3. **Developer Experience**: Clean service interface with comprehensive JavaDoc 4. **Robustness**: Fail-fast null validation and defensive programming 5. **Future-Proof**: Extensible design for additional pattern matching needs ## Related Work This implementation complements PR apache#10909 by @desruisseaux which addresses PathSelector bug fixes. Both PRs can be merged independently and work together to provide complete exclude-only functionality. Addresses performance optimization suggestions and provides the missing API methods needed by Maven plugins for efficient file filtering. (cherry picked from commit 38e0a71)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Backport
This will backport the following commits from
mastertomaven-4.0.x:Questions ?
Please refer to the Backport tool documentation