xml-format-maven-plugin icon indicating copy to clipboard operation
xml-format-maven-plugin copied to clipboard

lineEnding setting is not respected for empty lines and CDATA, multiline text content is deleted

Open bergerst opened this issue 2 years ago • 4 comments

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: image

I have several issues with the current behavior:

  1. The plugin inserts an empty line at the top
  2. The line breaks after </xml-format-plugin.version> are LFCRLF, so 1 Linux line break followed by 1 Windows line break. Both should be CRLF.
  3. The CDATA content will also have LFs instead of CRLFs.
  4. If I don't put the lines in the sonar exclusions into CDATA, the plugin will delete the text content.

bergerst avatar Mar 14 '23 16:03 bergerst

Even worse, when <trimText>false</trimText> is set, the formatted XML will look like this: image

LF followed by white space and CRLF

bergerst avatar Mar 14 '23 16:03 bergerst

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?

hazendaz avatar Oct 22 '23 01:10 hazendaz

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.

bergerst avatar Oct 23 '23 07:10 bergerst

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

hazendaz avatar Dec 02 '23 21:12 hazendaz