-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix #10939: DefaultModelXmlFactory: make location tracking opt-in—disabled by def… #11092
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
Conversation
elharo
left a comment
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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
|
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"); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rewrite comment
87ca49b to
28e2f84
Compare
| final MavenStaxWriter xmlWriter = new MavenStaxWriter(); | ||
| xmlWriter.setAddLocationInformation(false); | ||
|
|
||
| final Function<Object, String> fmtformatter = request.getInputLocationFormatter(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
gnodet
left a comment
There was a problem hiding this 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.
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultModelXmlFactory.java
Outdated
Show resolved
Hide resolved
Remove final keywords
…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)
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation |
…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]>
…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:
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.
====
Supersedes #10940