-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[#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
base: master
Are you sure you want to change the base?
Conversation
…y based on InputLocationFormatter presence
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); |
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.
maybe use an else block for this; what's the 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.
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?
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.
In that case, no need to set it to true below. Use an else block to set it to false
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.
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.
impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultModelXmlFactoryTest.java
Show resolved
Hide resolved
impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultModelXmlFactoryTest.java
Outdated
Show resolved
Hide resolved
impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultModelXmlFactoryTest.java
Show resolved
Hide resolved
I wonder if this should be moved further down in the MavenStaxWriter and remove the |
@@ -127,7 +127,9 @@ public void write(XmlWriterRequest<Model> request) throws XmlWriterException { | |||
} | |||
try { | |||
MavenStaxWriter w = new MavenStaxWriter(); | |||
w.setAddLocationInformation(false); |
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.
In that case, no need to set it to true below. Use an else block to set it to false
impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultModelXmlFactoryTest.java
Show resolved
Hide resolved
impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultModelXmlFactoryTest.java
Show resolved
Hide resolved
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.
We cannot break compatibility with Maven 3 API here.
Undo the changes in compat/* modules.
|
||
protected MavenXpp3Writer(boolean addLocationInformation) { |
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 API breakage in Maven 3 compatibility layer.
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.
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()); |
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.
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); |
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.
Undo
@@ -38,7 +38,6 @@ public class SettingsXpp3Writer { | |||
|
|||
public SettingsXpp3Writer() { | |||
delegate = new SettingsStaxWriter(); | |||
delegate.setAddLocationInformation(false); |
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.
Undo
@@ -41,7 +41,6 @@ public class MavenToolchainsXpp3Writer { | |||
|
|||
public MavenToolchainsXpp3Writer() { | |||
delegate = new MavenToolchainsStaxWriter(); | |||
delegate.setAddLocationInformation(false); |
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.
Undo
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:
Note that commits might be squashed by a maintainer on merge.
This may not always be possible but is a best-practice.
mvn verify
to 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.