Skip to content

Fix #11715: preserve 4.1.0 namespace/schema in help:effective-pom#11742

Open
arturobernalg wants to merge 2 commits into
apache:masterfrom
arturobernalg:11715
Open

Fix #11715: preserve 4.1.0 namespace/schema in help:effective-pom#11742
arturobernalg wants to merge 2 commits into
apache:masterfrom
arturobernalg:11715

Conversation

@arturobernalg
Copy link
Copy Markdown
Member

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:

  • [ X] Your pull request should address just one issue, without pulling in other changes.
  • [ X] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • [X ] Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • [X ] Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the Core IT successfully.

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.

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
Copy link
Copy Markdown
Contributor

@gnodet gnodet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Two concerns in one PR: The XmlService classloader 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.

  2. Minor thread-safety note: configureDelegate() mutates the shared delegate field before calling write(). This is not thread-safe if a single MavenXpp3Writer instance is used concurrently. This is a pre-existing issue (same as setFileComment/setStringFormatter), but worth noting since configureDelegate is now called on every write.

}
if (version == null || version.isBlank()) {
version = DEFAULT_MODEL_VERSION;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants