Ekryd / sortpom

Maven plugin that helps the user sort pom.xml.
https://github.com/Ekryd/sortpom/wiki/
BSD 3-Clause "New" or "Revised" License
336 stars 181 forks source link

Preserve comments formatting #249

Closed lestephane closed 2 years ago

lestephane commented 2 years ago

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?

Ekryd commented 2 years ago

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

Ekryd commented 2 years ago

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>
lestephane commented 2 years ago

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.

Ekryd commented 2 years ago

Glad that it was resolved

Ekryd commented 2 years ago

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.