Skip to content

[#10939] Enable addLocationInformation in DefaultModelXmlFactory base on InputLocationFormatter presence #10940

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Giovds
Copy link
Contributor

@Giovds Giovds commented Jul 18, 2025

Show example for [#10939]

Set addLocationInformation to false by default in DefaultModelXmlFactory.
If the XmlWriterRequest specifies an InputLocationFormatter, set addLocationInformation to true and apply the formatter.


Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • 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.
  • 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.

@Giovds
Copy link
Contributor Author

Giovds commented Jul 18, 2025

Current behaviour without a formatter will result in:

<?xml version="1.0" encoding="UTF-8"?>
  <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion><!-- 2 -->
    <groupId>org.example</groupId><!-- 3 -->
    <artifactId>example-artifact</artifactId><!-- 4 -->
    <version>1.0.0</version><!-- 5 -->
    <name>Example Project</name><!-- 6 -->
    <properties>
      <example.property>value</example.property><!-- 8 -->
    </properties>
  </project>

@@ -127,7 +127,9 @@ public void write(XmlWriterRequest<Model> request) throws XmlWriterException {
}
try {
MavenStaxWriter w = new MavenStaxWriter();
w.setAddLocationInformation(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe use an else block for this; what's the default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The MavenStaxWriter is initialized with true therefore I explicitly set it to false. I personally prefer to keep nesting brackets to a minimum, as this makes it less verbose and easier to understand what's happening. The result would be the same?

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, no need to set it to true below. Use an else block to set it to false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would make it depend on the implementation of the MavenStaxWriter. If it changes the default this will affect our class.

I was thinking the same as @gnodet:

I wonder if this should be moved further down in the MavenStaxWriter and remove the addLocationInformation completely in that case.

If we use the proposed solution of moving this behaviour to the MavenStaxWriter this might solve both the need to set the value, and other XML factory implementations.

This is a generic generated class (throughwriter-stax.vm), so all ZZZStaxWriter classes (which are about 8 classes) will use this behaviour from then on. I'm not entirely sure about that change, but probably will be the better option as it will solve the issues for other DefaultZZZXmlFactory classes as well that use one of the ZZZStaxWriter's.

@gnodet
Copy link
Contributor

gnodet commented Jul 18, 2025

I wonder if this should be moved further down in the MavenStaxWriter and remove the addLocationInformation completely in that case.

@@ -127,7 +127,9 @@ public void write(XmlWriterRequest<Model> request) throws XmlWriterException {
}
try {
MavenStaxWriter w = new MavenStaxWriter();
w.setAddLocationInformation(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, no need to set it to true below. Use an else block to set it to false

Copy link
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.

We cannot break compatibility with Maven 3 API here.
Undo the changes in compat/* modules.


protected MavenXpp3Writer(boolean addLocationInformation) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No API breakage in Maven 3 compatibility layer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check. Won’t be able to work on this due to holiday for the next couple weeks. Feel free to adjust it, otherwise I’ll look into this when I’m back.

@@ -36,7 +37,7 @@ public class MavenXpp3WriterEx extends MavenXpp3Writer {
// -----------/

public MavenXpp3WriterEx() {
super(true);
super((inputLocation) -> inputLocation.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

Undo

@@ -89,7 +89,6 @@ void testNamespaceInXmlNode() throws XMLStreamException {
String toXml(Model model) throws IOException, XMLStreamException {
StringWriter sw = new StringWriter();
MavenStaxWriter writer = new MavenStaxWriter();
writer.setAddLocationInformation(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Undo

@@ -38,7 +38,6 @@ public class SettingsXpp3Writer {

public SettingsXpp3Writer() {
delegate = new SettingsStaxWriter();
delegate.setAddLocationInformation(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Undo

@@ -41,7 +41,6 @@ public class MavenToolchainsXpp3Writer {

public MavenToolchainsXpp3Writer() {
delegate = new MavenToolchainsStaxWriter();
delegate.setAddLocationInformation(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Undo

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.

3 participants