Fix MSITE-1033: AbstractDeployMojo.getTopLevelProject() returns wrong project for SCM URLs #1177
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.
Problem
The
getTopLevelProject()method inAbstractDeployMojoincorrectly treats all SCM URLs as pointing to the same site, causing it to return the wrong top-level project when a project hierarchy uses different SCM URLs.For example, consider two projects:
scm:git:[email protected]:codehaus-plexus/plexus-sec-dispatcher.git/scm:git:https://github.com/codehaus-plexus/plexus-pom.git/These clearly point to different repositories, but the method incorrectly identifies them as the same site because SCM URLs are opaque URIs. When parsed as URIs, they only expose the scheme ("scm"), while host and port are both null, making all SCM URLs appear identical.
Solution
This PR fixes the issue by:
Adding maven-scm-api dependency to properly parse SCM URLs using
ScmUrlUtils.getProviderSpecificPart()Creating an
extractComparableUrl()helper method that:scm:)scm:git:https://github.com/user/repo.git→https://github.com/user/repo.git)[email protected]:user/repo.git) by converting it to a comparable format (ssh://github.com/user/repo.git)Updating
getTopLevelProject()to use the extracted comparable URLs for site comparisonExample
Before this fix:
After this fix:
Testing
Added comprehensive unit tests in
AbstractDeployMojoTestcovering:All tests pass (9 total, including 4 new tests).
Security
Backward Compatibility
Fully maintained - non-SCM URLs continue to work exactly as before.
Fixes #1159