sortpom icon indicating copy to clipboard operation
sortpom copied to clipboard

Preserve comments formatting

Open lestephane opened this issue 1 year ago • 2 comments

I have some xml comment like so

<element>
    <!-- some comment
          continued here -->
   <nestedElement>

That gets converted to

<element><!-- some comment
          continued here -->
   <nestedElement>

Is there a way to control this behaviour?

lestephane avatar Sep 15 '22 08:09 lestephane

Hi! No parameter for this currently, I can have a look and see how it is handled.

Ekryd avatar Sep 15 '22 10:09 Ekryd

I was not able to reproduce the problem. Used v3.2.0 with the following elements:

      <dependency>
        <!-- some comment
          continued here -->
        <groupId>org.dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>2.1.3</version>
      </dependency>

and the properties

        <plugin>
          <groupId>com.github.ekryd.sortpom</groupId>
          <artifactId>sortpom-maven-plugin</artifactId>
          <version>3.2.0</version>
          <configuration>
            <createBackupFile>false</createBackupFile>
            <predefinedSortOrder>custom_1</predefinedSortOrder>
            <lineSeparator>\n</lineSeparator>
            <encoding>${project.build.sourceEncoding}</encoding>
            <sortProperties>true</sortProperties>
            <sortDependencies>scope,groupId,artifactId</sortDependencies>
            <indentSchemaLocation>true</indentSchemaLocation>
          </configuration>
        </plugin>

Ekryd avatar Sep 23 '22 19:09 Ekryd

Sorry I was mistaken about who's causing what. The tidy:pom target outputs xml without the newline.

<dependency><!--

If i run sortpom even with <lineSeparator/> (ie, no separator), the xml is changed to

<dependency>
    <!--

And I wanted a way to have sortpom:sort behave the same as tidy:pom while I migrate a bunch of modules. After that I'll drop tidy, and just use sortpom, but for now I want to avoid diffs when a person is using one plugin vs another (at least on that aspect of comment handling). This handling of comments is the only problem I have left. And I was hoping there was a way to not have sortpom insert the newline before a text comment, or just respect the formatting that is already there and not touch it if everything is already sorted. My understanding is that everything in sortpom is configureable, and so I was asking which config item I can use to prevent the insertion of the newline in front of xml comments, basically.

lestephane avatar Oct 26 '22 13:10 lestephane

Glad that it was resolved

Ekryd avatar Oct 26 '22 16:10 Ekryd

There is another goal, verify That can check the pom and only reformat it if the elements are in the wrong place. It that doesn’t work, experiment some more and feel free to add suggestion ( or even better, a PR!) of new functionality.

Ekryd avatar Oct 26 '22 16:10 Ekryd