-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add PathMatcherFactory service with directory filtering optimization #10923
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
Add PathMatcherFactory service with directory filtering optimization #10923
Conversation
|
Update: I've restored the I initially thought it was accidentally created, but it was actually an existing file that should not have been deleted. The file has been restored with its original content: The PR now only includes the intended changes:
|
api/maven-api-core/src/main/java/org/apache/maven/api/services/PathMatcherFactory.java
Outdated
Show resolved
Hide resolved
api/maven-api-core/src/main/java/org/apache/maven/api/services/PathMatcherFactory.java
Outdated
Show resolved
Hide resolved
api/maven-api-core/src/main/java/org/apache/maven/api/services/PathMatcherFactory.java
Outdated
Show resolved
Hide resolved
api/maven-api-core/src/main/java/org/apache/maven/api/services/PathMatcherFactory.java
Outdated
Show resolved
Hide resolved
254c3a1 to
20ec66c
Compare
|
Cleaned up the commit history 🧹 I've used The PR now contains a single clean commit with only the intended changes:
The |
|
Updated to avoid conflicts with PR #10909 🔄 After reviewing PR #10909, I discovered that it already includes the PathSelector fix needed for exclude-only patterns to work correctly. To avoid conflicts, I've: ✅ Removed PathSelector changes from this PR Current Status
Why this approach?
This PR now focuses purely on adding the missing API method without duplicating the PathSelector fixes from #10909. 🎯 |
|
Addressed review comments from @elharo ✅ Thank you for the feedback! I've updated the PR to address all the comments: Changes made:
Why NPE is the right choice:
All tests pass and the behavior is now properly documented. Ready for another review! 🚀 |
|
Additional improvement: Enhanced PathSelector null safety I've made an additional improvement to the Changes to PathSelector:
Benefits:
Since All tests pass and the behavior is well-documented! |
|
Thanks! It look fine to me. One possible addition: the clean plugin invokes /**
* Returns a filter for directories that may contain paths accepted by the given matcher.
* The given path matcher should be an instance created by this service.
* The patch matcher returned by this argument expects <em>directory</em> paths.
* If that matcher returns {@code false}, then the directory will definitively not contain
* the paths selected by the matcher given in argument to this method.
* In such case, the whole directory and all its sub-directories can be skipped.
* In case of doubt, or if the matcher given in argument is not recognized by this method,
* then the matcher returned by this method will return {@code true}.
*
* @param fileMatcher a matcher created by one of the other methods of this interface
* @return filter for directories that may contain the selected files
*/
PathMatcher deriveDirectoryMatcher(PathMatcher fileMatcher);Implementation could be: @Override
public PathMatcher deriveDirectoryMatcher(PathMatcher fileMatcher) {
if (Objects.requireNonNull(fileMatcher) instanceof PathSelector selector) {
if (selector.canFilterDirectories()) {
return selector::couldHoldSelected;
}
}
return PathSelector.INCLUDES_ALL;;
}It would require to make /**
* Returns whether {@link #couldHoldSelected(Path)} may return {@code false} for some directories.
*/
boolean canFilterDirectories() {
return dirIncludes.length != 0 || dirExcludes.length != 0;
}If |
|
Implemented the directory filtering optimization suggested by @desruisseaux! 🚀 Thank you for the excellent suggestion! I've implemented the ✅ New API Method Added:/**
* Returns a filter for directories that may contain paths accepted by the given matcher.
* The given path matcher should be an instance created by this service.
* The path matcher returned by this method expects <em>directory</em> paths.
* If that matcher returns {@code false}, then the directory will definitively not contain
* the paths selected by the matcher given in argument to this method.
* In such case, the whole directory and all its sub-directories can be skipped.
* In case of doubt, or if the matcher given in argument is not recognized by this method,
* then the matcher returned by this method will return {@code true}.
*/
@Nonnull
PathMatcher deriveDirectoryMatcher(@Nonnull PathMatcher fileMatcher);✅ Implementation in DefaultPathMatcherFactory:@Override
public PathMatcher deriveDirectoryMatcher(@Nonnull PathMatcher fileMatcher) {
if (Objects.requireNonNull(fileMatcher) instanceof PathSelector selector) {
if (selector.canFilterDirectories()) {
return selector::couldHoldSelected;
}
}
return PathSelector.INCLUDES_ALL;
}✅ PathSelector Enhancements:
✅ Benefits:
🎯 Perfect for maven-clean-plugin:This allows the clean plugin to call All tests pass and the implementation follows your exact specification. Thank you for the thoughtful design suggestion! 🙏 |
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.
8c017d9 to
91e416d
Compare
|
🎆 Final Implementation - All Commits Squashed! I've successfully squashed all commits into a single clean commit and updated the PR description to reflect the complete changeset. Here's what this PR now delivers: 📦 Complete Package✅ Core API Implementation
✅ Performance Optimization
✅ Enhanced PathSelector
✅ Comprehensive Testing
🎯 Addresses All Feedback
🚀 Ready for ProductionThis implementation provides:
All tests pass and the implementation follows Maven's coding conventions. This PR is ready for final review and merge! 🎉 |
…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)
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation |
…10923) (#10926) 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 #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 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)- Full control over include/exclude patternscreatePathMatcher(baseDirectory, includes, excludes)- Convenience overload without default excludescreateExcludeOnlyMatcher(baseDirectory, excludes, useDefaultExcludes)- NEW: Exclude-only pattern matchingcreateIncludeOnlyMatcher(baseDirectory, includes)- Convenience method for include-only patternsderiveDirectoryMatcher(fileMatcher)- NEW: Directory filtering optimizationDefaultPathMatcherFactory Implementation
PathSelector.couldHoldSelected()INCLUDES_ALLfor unknown matcher types🔧 PathSelector Enhancements
Null Safety Improvements
@Nonnullannotation to constructor directory parameterObjects.requireNonNull()validation with descriptive error messagebaseDirectoryassignment to beginning for fail-fast behaviorNullPointerExceptionbehaviorDirectory Filtering Support
canFilterDirectories()method to check optimization capabilityINCLUDES_ALLfield package-private for factory reusecouldHoldSelected()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
NullPointerException)Backward Compatibility
🚀 Benefits
🔗 Related Work
This implementation complements PR #10909 by @desruisseaux which addresses PathSelector bug fixes. Both PRs can be merged independently and work together to provide complete exclude-only functionality.
📋 Testing
All tests pass, including:
DefaultPathMatcherFactoryTestwith comprehensive coveragePathSelectorTest(no regressions)🎉 Ready for Review
This PR provides the missing API methods needed by Maven plugins for efficient file filtering and addresses performance optimization suggestions from the community. The implementation follows Maven's coding conventions and includes thorough documentation and testing.