sortpom icon indicating copy to clipboard operation
sortpom copied to clipboard

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

Open vrastov opened this issue 1 year ago • 6 comments

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

Maybe I misunderstood the description <endWithNewline>.

vrastov avatar Sep 04 '24 21:09 vrastov

Hi! I'll have a look 👍

Ekryd avatar Sep 06 '24 14:09 Ekryd

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).

Ekryd avatar Sep 15 '24 16:09 Ekryd

I used the feature "verify check formatting " 😄

Okay but why:

  • https://github.com/vrastov/sortpom/pull/3 goal verify filed if <relativePath/> and requires <relativePath></relativePath>
  • https://github.com/vrastov/sortpom/pull/4 goal verify filed if <modelVersion>4.0.0</modelVersion> (4 spase) and requires <modelVersion>4.0.0</modelVersion> (2 spase)

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.

vrastov avatar Sep 18 '24 06:09 vrastov

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.

Ekryd avatar Oct 12 '24 18:10 Ekryd

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 avatar Oct 14 '24 18:10 vrastov

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...

vrastov avatar Oct 14 '24 19:10 vrastov

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

Ekryd avatar Oct 28 '24 20:10 Ekryd

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 avatar Oct 28 '24 22:10 Ekryd

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

Ekryd avatar Oct 29 '24 18:10 Ekryd