xml-format-maven-plugin
xml-format-maven-plugin copied to clipboard
lineEnding setting is not respected for empty lines and CDATA, multiline text content is deleted
I have a pom.xml which is structed like this:
<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>
<groupId>com.mycompany.app</groupId>
<artifactId>my-module</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<xml-format-plugin.version>3.2.2</xml-format-plugin.version>
<sonar.coverage.exclusions><![CDATA[
src/main/java/A.java,
src/main/java/B.java,
src/main/java/C.java,
]]></sonar.coverage.exclusions>
<sonar.exclusions><![CDATA[
src/main/java/D.java,
src/main/java/E.java,
]]></sonar.exclusions>
</properties>
<build>
<plugins>
<plugin>
<groupId>au.com.acegi</groupId>
<artifactId>xml-format-maven-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<id>xml-format</id>
<goals>
<goal>xml-format</goal>
</goals>
<phase>process-sources</phase>
<configuration>
<indentSize>2</indentSize>
<suppressDeclaration>true</suppressDeclaration>
<keepBlankLines>true</keepBlankLines>
<includes>pom.xml</includes>
<lineEnding>CRLF</lineEnding>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Here's a screenshot of Notepad++ after the pom.xml was formatted:

I have several issues with the current behavior:
- The plugin inserts an empty line at the top
- The line breaks after
</xml-format-plugin.version>areLFCRLF, so 1 Linux line break followed by 1 Windows line break. Both should be CRLF. - The CDATA content will also have LFs instead of CRLFs.
- If I don't put the lines in the sonar exclusions into CDATA, the plugin will delete the text content.
Even worse, when <trimText>false</trimText> is set, the formatted XML will look like this:

LF followed by white space and CRLF
The content deletion is a duplicate of #36 I believe and I have a pull request out for that.
This one will be a bit more complicated to look into right now given the project itself is forcing LF usage which expects any contributors (including myself) are either not using windows or do not have globals set to force proper line normalization (also myself). So I have to work that issue out as I cannot even build the project at the moment.
@bergerst Do you know if this issue was present in earlier versions?
The bug with blank lines having LFCRLF is present in 3.2.0 and 3.2.2 (haven't tested 3.2.1)
The bug with <trimText>false</trimText> and it inserting LFCRLF everywhere is present in all versions I've tested.
ok going to try to get @benalexau get a release out as it is now since it seems issue is present for a while. After that is out, I'd like this retested to just confirm what is broken since I believe part of the issues were resolved here now for next release