Fix #11715: preserve 4.1.0 namespace/schema in help:effective-pom#11742
Fix #11715: preserve 4.1.0 namespace/schema in help:effective-pom#11742arturobernalg wants to merge 2 commits into
Conversation
When generating the effective POM for a modelVersion 4.1.0 project, preserve the root <project> namespace and schemaLocation as 4.1.0 instead of falling back to 4.0.0. Add/keep coverage with MavenITgh11715EffectivePomNamespaceTest to verify the effective POM header contains: - xmlns http://maven.apache.org/POM/4.1.0 - schemaLocation .../maven-4.1.0.xsd
gnodet
left a comment
There was a problem hiding this comment.
Claude Code on behalf of Guillaume Nodet
The core fix in MavenXpp3Writer.configureDelegate() correctly derives the namespace and schema location from the model version, mirroring the existing pattern in TransformerSupport.write(). The fallback chain (modelVersion -> namespaceUri -> default 4.0.0) is sensible. Tests and integration test cover the primary scenario well.
Two observations:
-
Two concerns in one PR: The
XmlServiceclassloader fallback change is a separate fix from the namespace preservation. Consider splitting it into its own PR/commit so each can be reviewed and reverted independently. -
Minor thread-safety note:
configureDelegate()mutates the shareddelegatefield before callingwrite(). This is not thread-safe if a singleMavenXpp3Writerinstance is used concurrently. This is a pre-existing issue (same assetFileComment/setStringFormatter), but worth noting sinceconfigureDelegateis now called on everywrite.
| } | ||
| if (version == null || version.isBlank()) { | ||
| version = DEFAULT_MODEL_VERSION; | ||
| } |
There was a problem hiding this comment.
The version extraction from the namespace URI is a nice defensive fallback, but the constants here duplicate values already defined in TransformerSupport (NAMESPACE_FORMAT, SCHEMA_LOCATION_FORMAT). Consider extracting them to a shared location to avoid drift.
| ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); | ||
| return contextClassLoader != null | ||
| ? ServiceLoader.load(XmlService.class, contextClassLoader) | ||
| .findFirst() |
There was a problem hiding this comment.
This classloader fallback is a worthwhile robustness improvement, but it addresses a different problem than #11715 (namespace preservation). Consider splitting this into a separate commit/PR so the two fixes can be tracked and reverted independently.
Also, the order here (class classloader first, then TCCL) inverts the typical Java convention where TCCL is checked first. Is this intentional? In most ServiceLoader patterns the TCCL takes precedence because it represents the application's view. If the class's own classloader already sees the provider, the TCCL fallback will never trigger in practice -- which is fine for robustness, but worth documenting the intent.
- Remove XmlService classloader fallback (extracted to PR apache#12237) - Use MavenModelVersion to compute the minimum model version instead of hardcoding 4.0.0 as the fallback - Align namespace/schemaLocation format strings with TransformerSupport conventions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When generating the effective POM for a modelVersion 4.1.0 project, preserve the root namespace and schemaLocation as 4.1.0 instead of falling back to 4.0.0.
Add/keep coverage with MavenITgh11715EffectivePomNamespaceTest to verify the effective POM header contains:
Following this checklist to help us incorporate your
contribution quickly and easily:
Note that commits might be squashed by a maintainer on merge.
This may not always be possible but is a best-practice.
mvn verifyto make sure basic checks pass.A more thorough check will be performed on your pull request automatically.
If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.