Skip to content

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented Jul 15, 2025

Backport

This will backport the following commits from master to maven-4.0.x:

Questions ?

Please refer to the Backport tool documentation

* Fix mvnup tool issues apache#7934-apache#7938

This commit addresses five critical issues with the Maven upgrade tool (mvnup):

**Issue apache#7934: External parent preservation**
- Fixed InferenceStrategy to detect external parents vs reactor parents
- External parents now preserve required groupId, artifactId, and version elements
- Prevents 'parent.groupId is missing' errors when using META-POMs

**Issue apache#7935: .mvn directory creation for all model versions**
- Modified AbstractUpgradeGoal to create .mvn directory for both 4.0.0 and 4.1.0
- Helps Maven find project root and avoids root directory warnings

**Issue apache#7936: Downgrade error handling**
- Changed ModelUpgradeStrategy to fail with errors instead of warnings for invalid downgrades
- Tool now properly exits with error code when attempting 4.1.0 → 4.0.0 downgrade

**Issue apache#7937: Unicode icon fallback**
- Enhanced UpgradeContext to detect Unicode support using terminal.stdoutEncoding()
- Falls back to ASCII characters ([OK], [ERROR], etc.) when Unicode not supported
- Improves compatibility with Windows CMD/PowerShell and other terminals

**Issue apache#7938: Child version removal in 4.1.0**
- Enhanced inference logic to properly remove matching child versions in subprojects
- Ensures child project versions are removed when they match parent version

**Testing:**
- Updated existing tests to reflect correct behavior
- Added new tests for downgrade handling and Unicode detection
- All mvnup tests passing with comprehensive coverage

Fixes apache#7934, apache#7935, apache#7936, apache#7937, apache#7938

* Improve parent reactor detection logic

- Replace heuristic-based approach with direct GAV matching against pomMap
- More accurate detection of external vs reactor parents
- Added comprehensive test coverage for both scenarios
- Suggested by code review feedback

* Refactor to use GAVUtils.extractGAVWithParentResolution

- Replace manual GAV extraction with existing GAVUtils method
- More robust handling of parent resolution and inheritance
- Leverages existing tested utility for GAV extraction
- Cleaner and more maintainable code

* Address review feedback: Implement ConsoleIcon enum with charset detection

This commit addresses all review feedback from @elharo and @Bukama:

**Icon Management Improvements:**
- Created ConsoleIcon enum with Unicode/ASCII fallback pairs
- Moved all icon logic into the enum for consistency and reusability
- Implemented ConsoleIcon.getIcon(Terminal) for clean integration

**Unicode Detection Enhancements:**
- Use Charset.newEncoder().canEncode(char) for accurate character testing
- Use terminal.encoding() instead of deprecated stdoutEncoding()
- Simplified fallback to Charset.defaultCharset()
- Removed complex heuristics and exception handling

**Code Quality Improvements:**
- UpgradeContext methods are now clean one-liners
- Better separation of concerns between icon rendering and context management
- Comprehensive test coverage for all scenarios
- Future-proof design for adding new icons

**Review Comments Addressed:**
- @elharo: 'maybe this should be a field that can be shared?' → Icons now shared via enum
- @Bukama: 'maybe an enum with icon and fallback text?' → Implemented with Terminal integration
- @elharo: 'There are others that also support Unicode, e.g. UCS-2., UCS-4' → Now tests actual encoding capability
- @elharo: 'Please be specific about exceptions' → No longer needed with simplified approach
- @elharo: 'toLowerCase(Locale.ENGLISH)' → No longer needed with canEncode() approach

**Technical Benefits:**
- More accurate Unicode detection per character
- Works with any charset automatically
- Cleaner and more maintainable code
- Better test coverage and reliability

(cherry picked from commit adf2c49)
@gnodet gnodet mentioned this pull request Jul 15, 2025
7 tasks
@gnodet gnodet added bug Something isn't working backport mvn40 labels Jul 16, 2025
@gnodet gnodet merged commit 18080e7 into apache:maven-4.0.x Jul 16, 2025
19 checks passed
@gnodet gnodet deleted the backport/maven-4.0.x/pr-9311 branch July 16, 2025 03:44
@github-actions github-actions bot added this to the 4.0.0 milestone Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport bug Something isn't working mvn40

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant