[#10939] Enable addLocationInformation in DefaultModelXmlFactory base on InputLocationFormatter presence#10940
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> |
| } | ||
| try { | ||
| MavenStaxWriter w = new MavenStaxWriter(); | ||
| w.setAddLocationInformation(false); |
There was a problem hiding this comment.
maybe use an else block for this; what's the default?
There was a problem hiding this comment.
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.
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.
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 |
| } | ||
| try { | ||
| MavenStaxWriter w = new MavenStaxWriter(); | ||
| w.setAddLocationInformation(false); |
There was a problem hiding this comment.
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
gnodet
left a comment
There was a problem hiding this comment.
We cannot break compatibility with Maven 3 API here.
Undo the changes in compat/* modules.
| } | ||
| public MavenXpp3Writer() {} | ||
|
|
||
| protected MavenXpp3Writer(boolean addLocationInformation) { |
There was a problem hiding this comment.
No API breakage in Maven 3 compatibility layer.
There was a problem hiding this comment.
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.
|
|
||
| public MavenXpp3WriterEx() { | ||
| super(true); | ||
| super((inputLocation) -> inputLocation.toString()); |
| String toXml(Model model) throws IOException, XMLStreamException { | ||
| StringWriter sw = new StringWriter(); | ||
| MavenStaxWriter writer = new MavenStaxWriter(); | ||
| writer.setAddLocationInformation(false); |
|
|
||
| public SettingsXpp3Writer() { | ||
| delegate = new SettingsStaxWriter(); | ||
| delegate.setAddLocationInformation(false); |
|
|
||
| public MavenToolchainsXpp3Writer() { | ||
| delegate = new MavenToolchainsStaxWriter(); | ||
| delegate.setAddLocationInformation(false); |
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 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.