Skip to content

Conversation

@arturobernalg
Copy link
Member

@arturobernalg arturobernalg commented Sep 3, 2025

…ault, enabled when an InputLocationFormatter is provided.

Adapt formatter to Function<InputLocation,String> and write to the actually opened stream for path output. Fixes #10939.

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.
  • [ X] 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.

====

Supersedes #10940

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

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

There seem to be a lot of changes here that have nothing to do with teh purpose of thiks PR. Try to keep the changes more focused

if (inputLocationFormatter != null) {
w.setStringFormatter((Function) inputLocationFormatter);
// OFF by default
final MavenStaxWriter xml = new MavenStaxWriter();
Copy link
Contributor

Choose a reason for hiding this comment

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

xml --> xmlWriter

}
} catch (Exception e) {
throw new XmlWriterException("Unable to write model: " + getMessage(e), getLocation(e), e);
throw new XmlWriterException("Unable to write model " + getMessage(e), getLocation(e), e);
Copy link
Contributor

Choose a reason for hiding this comment

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

This line doesn't need to be changed in this PR


String result = out.toString();
// Heuristic: when tracking is off there should be no location output (no comments)
assertTrue(!result.contains("<!--"), "Expected no XML comments when location tracking is disabled");
Copy link
Contributor

Choose a reason for hiding this comment

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

assretFalse

// Heuristic: when tracking is off there should be no location output (no comments)
assertTrue(!result.contains("<!--"), "Expected no XML comments when location tracking is disabled");
// And certainly not our marker
assertTrue(!result.contains("LOC_MARK"), "Unexpected marker found in output");
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't needed; or maybe keep this and get rid of the previous assert; if so, assertFalse

@arturobernalg
Copy link
Member Author

please do another pass

Function<Object, String> inputLocationFormatter = request.getInputLocationFormatter();
public void write(final XmlWriterRequest<Model> request) throws XmlWriterException {
Objects.requireNonNull(request, "request can not be null");
final Model content = Objects.requireNonNull(request.getContent(), "content can not be null");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to make all these variables final in this PR?

MavenStaxWriter w = new MavenStaxWriter();
if (inputLocationFormatter != null) {
w.setStringFormatter((Function) inputLocationFormatter);
// OFF by default
Copy link
Contributor

Choose a reason for hiding this comment

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

what is off by default?

final MavenStaxWriter xmlWriter = new MavenStaxWriter();
xmlWriter.setAddLocationInformation(false);

// Opt-in when a formatter is provided; adapt to the required type
Copy link
Contributor

Choose a reason for hiding this comment

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

"Optt-in" feels like the wrong language here. No human is making a choice

xmlWriter.setAddLocationInformation(false);

// Opt-in when a formatter is provided; adapt to the required type
final Function<Object, String> fmt = request.getInputLocationFormatter();
Copy link
Contributor

Choose a reason for hiding this comment

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

fmt --> formatter

.build());

String result = out.toString();
// And certainly not our marker
Copy link
Contributor

Choose a reason for hiding this comment

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

rewrite comment

@arturobernalg arturobernalg force-pushed the 10939 branch 2 times, most recently from 87ca49b to 28e2f84 Compare September 3, 2025 12:30
@arturobernalg arturobernalg requested a review from elharo September 3, 2025 12:36
final MavenStaxWriter xmlWriter = new MavenStaxWriter();
xmlWriter.setAddLocationInformation(false);

final Function<Object, String> fmtformatter = request.getInputLocationFormatter();
Copy link
Contributor

Choose a reason for hiding this comment

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

what is an fmtformatter? just formatter should be OK, or maybe inputLocationFormatter

Copy link
Member Author

Choose a reason for hiding this comment

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

what is an fmtformatter? just formatter should be OK, or maybe inputLocationFormatter

Sorry. type. Fixed

…ault, enabled when an InputLocationFormatter is provided.

Adapt formatter to Function<InputLocation,String> and write to the actually opened stream for path output.
Fixes apache#10939.
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.

No need for final variables here.

Remove final keywords
@gnodet gnodet added the bug Something isn't working label Sep 4, 2025
@gnodet gnodet merged commit 3338476 into apache:maven-4.0.x Oct 3, 2025
37 of 38 checks passed
@github-actions github-actions bot added this to the 4.0.0 milestone Oct 3, 2025
gnodet pushed a commit to gnodet/maven that referenced this pull request Oct 3, 2025
…in—disabled by def… (apache#11092)

DefaultModelXmlFactory: make location tracking opt-in—disabled by default, enabled when an InputLocationFormatter is provided.
Adapt formatter to Function<InputLocation,String> and write to the actually opened stream for path output.
Fixes apache#10939.

(cherry picked from commit 3338476)
@gnodet
Copy link
Contributor

gnodet commented Oct 3, 2025

💚 All backports created successfully

Status Branch Result
master

Questions ?

Please refer to the Backport tool documentation

gnodet added a commit that referenced this pull request Oct 6, 2025
…abled by def… (#11092) (#11198)

DefaultModelXmlFactory: make location tracking opt-in—disabled by default, enabled when an InputLocationFormatter is provided.
Adapt formatter to Function<InputLocation,String> and write to the actually opened stream for path output.
Fixes #10939.

(cherry picked from commit 3338476)

Co-authored-by: Arturo Bernal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants