-
Notifications
You must be signed in to change notification settings - Fork 56
Add ignorePattern attribute to TrackedProperty for array filtering #391
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 ignorePattern attribute to TrackedProperty for array filtering #391
Conversation
Fixes apache#375 - Maven 4 auto-injects --module-version to compilerArgs during cache storage but not during validation, causing parameter mismatches. Changes: - Add ignorePattern field to TrackedProperty in MDO model - Implement regex-based filtering in BuildCacheMojosExecutionStrategy - Filter arrays before comparison (both runtime and cached values) The ignorePattern attribute allows filtering specific array elements before comparison, solving the Maven 4 module-version problem while still detecting legitimate compilerArgs changes. Users can configure this in maven-build-cache-config.xml: <reconcile propertyName="compilerArgs" ignorePattern="--module-version"/> Tested with multi-module JPMS project using Maven 4.0.0-rc-4.
|
This PR addresses #375 by adding an |
|
@khmarbaise Can you please double-check whether this behavior needs to be fixed in Maven 4? Or do you believe this workaround is the right way to go? |
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java
Outdated
Show resolved
Hide resolved
src/main/java/org/apache/maven/buildcache/BuildCacheMojosExecutionStrategy.java
Outdated
Show resolved
Hide resolved
|
@AlexanderAshitkin I think the first step is to establish whether the problem lies in Maven or this extension. It's not clear to me that Maven 4.0's behavior is correct, given than 3.x does not exhibit this problem. Is this something you can dig into in the mailing list? |
Implemented all suggestions from @AlexanderAshitkin: 1. **Extracted filtering logic to utility class** - Created ArrayFilterUtils with pattern caching - Removed inline filtering methods from BuildCacheMojosExecutionStrategy 2. **Changed pattern matching from find() to matches()** - Ensures exact pattern matching (e.g., "\d+" matches "123" but not "Maven4") - Addresses reviewer's concern about unexpected substring matches 3. **Added pattern caching** - Uses ConcurrentHashMap to cache compiled patterns - Improves performance for repeated pattern usage 4. **Renamed variable to excludePattern** - More descriptive than generic "pattern" 5. **Removed filterArrayString() method** - Simplified approach: only filter current values, not cached values - When ignore pattern changes, cache rebuilds naturally 6. **Added proper imports** - Eliminated fully qualified names (FQNs) - All imports are at the top of the file 7. **Comprehensive unit tests** - 13 test cases covering all scenarios - Tests verify matches() vs find() behavior - Tests validate pattern caching - All 87 tests pass (existing + new)
Implemented all suggestions from @AlexanderAshitkin: 1. **Extracted filtering logic to utility class** - Created ArrayFilterUtils with pattern caching - Removed inline filtering methods from BuildCacheMojosExecutionStrategy 2. **Changed pattern matching from find() to matches()** - Ensures exact pattern matching (e.g., "\d+" matches "123" but not "Maven4") - Addresses reviewer's concern about unexpected substring matches 3. **Added pattern caching** - Uses ConcurrentHashMap to cache compiled patterns - Improves performance for repeated pattern usage 4. **Renamed variable to excludePattern** - More descriptive than generic "pattern" 5. **Removed filterArrayString() method** - Simplified approach: only filter current values, not cached values - When ignore pattern changes, cache rebuilds naturally 6. **Added proper imports** - Eliminated fully qualified names (FQNs) - All imports are at the top of the file 7. **Comprehensive unit tests** - 13 test cases covering all scenarios - Tests verify matches() vs find() behavior - Tests validate pattern caching - All 87 tests pass (existing + new)
0c4074b to
4438f43
Compare
Implemented all suggestions from @AlexanderAshitkin: 1. **Extracted filtering logic to utility class** - Created ArrayFilterUtils with pattern caching - Removed inline filtering methods from BuildCacheMojosExecutionStrategy 2. **Changed pattern matching from find() to matches()** - Ensures exact pattern matching (e.g., "\d+" matches "123" but not "Maven4") - Addresses reviewer's concern about unexpected substring matches 3. **Added pattern caching** - Uses ConcurrentHashMap to cache compiled patterns - Improves performance for repeated pattern usage 4. **Renamed variable to excludePattern** - More descriptive than generic "pattern" 5. **Removed filterArrayString() method** - Simplified approach: only filter current values, not cached values - When ignore pattern changes, cache rebuilds naturally 6. **Added proper imports** - Eliminated fully qualified names (FQNs) - All imports are at the top of the file 7. **Comprehensive unit tests** - 13 test cases covering all scenarios - Tests verify matches() vs find() behavior - Tests validate pattern caching - All 87 tests pass (existing + new)
4438f43 to
bb010f6
Compare
…nate timing mismatch Maven 4 automatically injects --module-version into compiler arguments during execution, but cache validation happens before execution. This creates a timing mismatch that causes cache invalidation. This fix captures properties at validation time for ALL builds, ensuring consistent reading at the same lifecycle point. Changes: - Modified CacheResult to store validation-time mojo events - Added captureValidationTimeProperties() method to BuildCacheMojosExecutionStrategy - Modified execute() to capture properties after findCachedBuild() - Modified save() to use validation-time events instead of execution-time events - Added comprehensive integration tests (Maven4Jpms, ExplicitModuleVersion, NonJpms, MultiModule) - Added implementation documentation This approach eliminates the need for ignorePattern configuration and fixes the root cause rather than treating the symptom. Alternative to PR apache#391
|
Actually, I think we can do better than this... Please take a look at #395 I suggest closing this PR and going with the new approach instead. |
…nate timing mismatch Maven 4 automatically injects --module-version into compiler arguments during execution, but cache validation happens before execution. This creates a timing mismatch that causes cache invalidation. This fix captures properties at validation time for ALL builds, ensuring consistent reading at the same lifecycle point. Changes: - Modified CacheResult to store validation-time mojo events - Added captureValidationTimeProperties() method to BuildCacheMojosExecutionStrategy - Modified execute() to capture properties after findCachedBuild() - Modified save() to use validation-time events instead of execution-time events - Added comprehensive integration tests (Maven4Jpms, ExplicitModuleVersion, NonJpms, MultiModule) - Added implementation documentation This approach eliminates the need for ignorePattern configuration and fixes the root cause rather than treating the symptom. Alternative to PR apache#391
…nate timing mismatch Maven 4 automatically injects --module-version into compiler arguments during execution, but cache validation happens before execution. This creates a timing mismatch that causes cache invalidation. This fix captures properties at validation time for ALL builds, ensuring consistent reading at the same lifecycle point. Changes: - Modified CacheResult to store validation-time mojo events - Added captureValidationTimeProperties() method to BuildCacheMojosExecutionStrategy - Modified execute() to capture properties after findCachedBuild() - Modified save() to use validation-time events instead of execution-time events - Added comprehensive integration tests (Maven4Jpms, ExplicitModuleVersion, NonJpms, MultiModule) - Added implementation documentation This approach eliminates the need for ignorePattern configuration and fixes the root cause rather than treating the symptom. Alternative to PR apache#391
…nate timing mismatch Maven 4 automatically injects --module-version into compiler arguments during execution, but cache validation happens before execution. This creates a timing mismatch that causes cache invalidation. This fix captures properties at validation time for ALL builds and stores ONLY validation-time values in the cache, ensuring consistent reading at the same lifecycle point. Changes: - Modified CacheResult to store validation-time mojo events - Added captureValidationTimeProperties() to BuildCacheMojosExecutionStrategy - Modified execute() to capture properties after findCachedBuild() - Modified save() to store ONLY validation-time events (AssertionError if missing) - Added comprehensive integration tests (Maven4Jpms, ExplicitModuleVersion, NonJpms, MultiModule) Benefits: - No configuration required (vs ignorePattern in PR apache#391) - Fixes root cause (timing mismatch) not symptom (value mismatch) - Works for ALL Maven 4 auto-injected properties - Preserves execution-time logging for debugging Alternative to PR apache#391
|
Closing per @cowwoc suggestion |
Fixes #375
Problem
Maven 4 auto-injects
--module-version ${project.version}tocompilerArgsduring cache storage but not during validation, causing parameter mismatches and forcing rebuilds on every invocation for modules withmodule-info.java.Solution
Add
ignorePatternattribute toTrackedPropertythat filters array elements using regex before comparison.Changes
build-cache-config.mdo): AddignorePatternfield toTrackedPropertyBuildCacheMojosExecutionStrategy.java):filterAndStringifyArray()- filters runtime array values before stringificationfilterArrayString()- filters cached string representationsConfiguration Example
Testing
Tested with multi-module JPMS project using Maven 4.0.0-rc-4:
--module-versionpresentcompilerArgschanges still invalidate cacheRelated Issues