Skip to content
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

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

Open
bergerst opened this issue Mar 14, 2023 · 4 comments

Comments

@bergerst
Copy link

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
Copy link
Author

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

LF followed by white space and CRLF

@hazendaz
Copy link
Collaborator

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?

@bergerst
Copy link
Author

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.

@hazendaz
Copy link
Collaborator

hazendaz commented Dec 2, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants