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

The goal `verify` does not fail, although the file does not end with a new line. #445

Open vrastov opened 2 months ago

vrastov commented 2 months ago

See pull rquest in my fork https://github.com/vrastov/sortpom/pull/1

Maybe I misunderstood the description <endWithNewline>.

Ekryd commented 2 months ago

Hi! I'll have a look 👍

Ekryd commented 1 month ago

The verify goal does only look at the xml elements themselves: verify only sorts the current pom.xml file if the xml elements are unsorted. This goal ignores text formatting (such as indentation and line breaks) when it verifies if the pom is sorted or not.

So endWithNewLine should not affect the verify goal at all (for the verification part).

vrastov commented 1 month ago

I used the feature "verify check formatting " 😄

Okay but why:

I can continue...

Earlier i use

mvn com.github.ekryd.sortpom:sortpom-maven-plugin:sort
git diff-index --quiet HEAD --

I thought using verify to check the format was more correct.

Ekryd commented 4 weeks ago

I'm a bit confused. Let me try to explain and see where it takes us :-) . There are two goals: 'sort' and 'verify'

sort will sort the pom file. The sort goal has a bunch of configurations regarding the sorting (e.g. endWithNewLine or keepBlankLines etc.). This goal is the one that you usually use as a developer.

verify will only check if the xml elements are unsorted. If the elements are unsorted, then the verifyFail configuration will determine what will happen: If unsorted and verifyFail is 'Stop' then the build would terminate. This can be used in a CI pipeline to enforce each developer to sort before they checkin. If unsorted and verifyFail is 'Warn' then the build would continue but warnings would be generated. Again, this is mostly useful in a CI pipeline If unsorted and verifyFail is 'Sort' then the pom is sorted exactly as the sort goal would do. All the parameters that are applicable for 'sort' would be used during the actual sorting. This can be used if you want a lesser control of the sorting, i.e. just resort everything whenever an xml element is placed in the wrong order.

To sum it up, the verify goal is useful for building really strict Continuous Integration pipelines or when you want to keep a personally formatted pom file, but ensure that xml elements are in the right order.

vrastov commented 3 weeks ago

I need a strict continuous integration pipeline.

I like the behavior of https://github.com/vrastov/sortpom/pull/3 and https://github.com/vrastov/sortpom/pull/4 and the rest.

And I would like to control the presence of a blank line at the end of the file, https://medium.com/@alexey.inkin/how-to-force-newline-at-end-of-files-and-why-you-should-do-it-fdf76d1d090e

vrastov commented 3 weeks ago

I think I understand what you mean, my examples are slightly different.

Added to https://github.com/vrastov/sortpom/pull/1

  <build>
    <plugins>

      <plugin>
        <groupId>com.github.ekryd.sortpom</groupId>
        <artifactId>sortpom-maven-plugin</artifactId>
        <version>4.0.0</version>

        <configuration>
          <verifyFail>stop</verifyFail>
          <verifyFailOn>strict</verifyFailOn>
        </configuration>
      </plugin>

    </plugins>
  </build>

And the test didn't pass, but it should have...

Ekryd commented 1 week ago

Sorry for the silent pause. Work has been hectic recently. I'll check it out

Ekryd commented 1 week ago

Now, I see the problem! There is a very old parameter that is called ignoreLineSeparators. Basically, if only the line breaks differ (including a missing line break at the end), the plugin will not sort the pom. Try setting ignoreLineSeparators to false to make the SortPom plugin even pickier.

Ekryd commented 1 week ago

Please check out this PR that is using your test https://github.com/Ekryd/sortpom/pull/456