-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[MNG-8746] Preserve property insertion order in WrapperProperties #2404
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
Merged
Conversation
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
This commit implements order preservation for properties in the Maven compat layer's WrapperProperties class, ensuring that properties maintain their insertion order when accessed through the Properties API. Key changes: 1. Enhanced WrapperProperties template (src/mdo/java/WrapperProperties.java): - Added internal OrderedProperties class that maintains insertion order - Implemented caching mechanism to preserve order across read/write operations - Modified all read operations to use the ordered cache - Simplified write operations to work directly with the ordered properties 2. OrderedProperties implementation: - Uses ArrayList to track key insertion order - Overrides put/setProperty/remove to maintain order - Custom KeySet and EntrySet implementations that iterate in insertion order - Removed unnecessary synchronized wrappers that interfered with ordering 3. Updated model-v3.vm template: - Ensured LinkedHashMap is used when converting properties to v4 API - This preserves order when properties are synced between compat and v4 layers 4. Added comprehensive tests: - PropertiesOrderTest: Tests v4 API model order preservation - WrapperPropertiesOrderTest: Tests compat layer order preservation - Covers various scenarios including modification and initial properties The implementation ensures that properties accessed through model.getProperties() maintain their insertion order, which is important for consistent behavior and reproducible builds. Fixes: MNG-8746
cstamas
approved these changes
May 28, 2025
Pankraz76
suggested changes
May 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use PostConstruct ?
Co-authored-by: Pankraz76 <[email protected]>
Co-authored-by: Pankraz76 <[email protected]>
Pankraz76
added a commit
to Pankraz76/maven
that referenced
this pull request
Jun 4, 2025
…ache#2404) * Fix MNG-8746: Preserve property insertion order in WrapperProperties This commit implements order preservation for properties in the Maven compat layer's WrapperProperties class, ensuring that properties maintain their insertion order when accessed through the Properties API. Key changes: 1. Enhanced WrapperProperties template (src/mdo/java/WrapperProperties.java): - Added internal OrderedProperties class that maintains insertion order - Implemented caching mechanism to preserve order across read/write operations - Modified all read operations to use the ordered cache - Simplified write operations to work directly with the ordered properties 2. OrderedProperties implementation: - Uses ArrayList to track key insertion order - Overrides put/setProperty/remove to maintain order - Custom KeySet and EntrySet implementations that iterate in insertion order - Removed unnecessary synchronized wrappers that interfered with ordering 3. Updated model-v3.vm template: - Ensured LinkedHashMap is used when converting properties to v4 API - This preserves order when properties are synced between compat and v4 layers 4. Added comprehensive tests: - PropertiesOrderTest: Tests v4 API model order preservation - WrapperPropertiesOrderTest: Tests compat layer order preservation - Covers various scenarios including modification and initial properties The implementation ensures that properties accessed through model.getProperties() maintain their insertion order, which is important for consistent behavior and reproducible builds. Fixes: MNG-8746 * Update src/mdo/java/WrapperProperties.java Co-authored-by: Pankraz76 <[email protected]> * Update src/mdo/java/WrapperProperties.java Co-authored-by: Pankraz76 <[email protected]> --------- Co-authored-by: Pankraz76 <[email protected]>
Resolve #9550 |
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.
Description
This PR fixes MNG-8746 by implementing property insertion order preservation in Maven's WrapperProperties class. The issue was that properties accessed through
model.getProperties()
were not maintaining their insertion order, leading to inconsistent behavior.Problem
The WrapperProperties class in the Maven compat layer was not preserving the insertion order of properties. When properties were added through the Properties API and then accessed via methods like
keySet()
orentrySet()
, they would be returned in an arbitrary order (often alphabetical) rather than the order they were inserted.Solution
Implemented a comprehensive order preservation mechanism:
Key Changes:
Enhanced WrapperProperties Template (
src/mdo/java/WrapperProperties.java
):OrderedProperties
class that maintains insertion orderOrderedProperties Implementation:
ArrayList<Object> keyOrder
to track key insertion orderput()
,setProperty()
, andremove()
methods to maintain orderKeySet
andEntrySet
implementations that iterate in insertion orderArchitecture Simplification:
Testing
Added comprehensive tests:
PropertiesOrderTest
: Tests v4 API model order preservationWrapperPropertiesOrderTest
: Tests compat layer order preservationVerification
The implementation ensures that:
Impact
Fixes: https://issues.apache.org/jira/browse/MNG-8746
Pull Request opened by Augment Code with guidance from the PR author