slachiewicz opened a new issue, #13889:
URL: https://github.com/apache/maven/issues/13889

   ### Affected version
   
   4.0.0-rc-7 (since 4.0.0-alpha-7; master is the same)
   
   ### Bug description
   
   `ComparableVersion#getCanonical()` spells the same version differently under 
Maven 4 than under Maven 3. Since 
[MNG-7714](https://issues.apache.org/jira/browse/MNG-7714) (e3529c9582), a 
qualifier followed by a number is parsed into one `CombinationItem`, and 
`CombinationItem#toString()` concatenates both parts without a separator. A 
plugin uses the `maven-artifact` of the Maven that runs it, so code that reads 
the canonical form gets a different answer under Maven 4.
   
   Output of the `ComparableVersion` main method:
   
   | Version | 3.9.16 and 3.10.0 | 4.0.0-rc-7 |
   |---|---|---|
   | `3.0.0-M2` | `3-milestone-2`, tokens `[3, [milestone, [2]]]` | 
`3-milestone2`, tokens `[3, [milestone2]]` |
   | `4.0.0-beta-1` | `4-beta-1` | `4-beta1` |
   | `3.34.0.CR1` | `3.34-rc-1` | `3.34-rc1` |
   | `1.0-sp1` | `1-sp-1` | `1-sp1` |
   
   The versions in the table order the same in both lines, and both spellings 
compare equal in both (`3-milestone2 == 3-milestone-2`); the ordering changes 
of MNG-7714 are intended. Maven 4 already parses `3-milestone-2` into the same 
`CombinationItem`, so only the spelling differs. `ComparableVersionTest` checks 
that a canonical form parses back to itself, and asserts the form itself only 
for the MNG-7700 cases.
   
   This came up in the Versions Maven Plugin, which classifies pre-releases by 
the `alpha`, `beta`, `milestone` and `rc` items of the canonical form, split on 
`.` and `-`. Under Maven 4 it reads `milestone2` as one item and treats every 
pre-release as a release. mojohaus/versions#1482 works around it by also 
splitting where letters and digits meet.
   
   Related but different: #9277 (MNG-7700) and #8873 (MNG-7594), where the 
canonical form does not parse back to an equal version. Here it does, and only 
the spelling differs between the lines.
   
   **Suggested fix:** write the separator in `CombinationItem#toString()` 
(`stringPart + "-" + digitPart`). That gives Maven 3 and Maven 4 the same 
canonical form for the alpha, beta, milestone, rc and sp qualifiers. With that 
change, every version literal in `ComparableVersionTest` plus edge cases 
(`1-sp-1`, `1.0-a1`, `1-x1`, `rc0`, `rc-0`, `1-rc-1a`), 292 in all, still 
parses back equal, with unchanged `equals`, `compareTo` and `hashCode`. Failing 
that, document `getCanonical()` as having no stable format.
   
   For consumers, parsing the canonical string is the fragile part. Comparing 
is sturdier: a version that sorts before its own release (`4.0.0-beta-3 < 
4.0.0`) and is not a snapshot is a pre-release, and that holds in both lines. 
The hard part is finding "its own release" (`3.34.0.CR1` has no hyphen to split 
on). Resolver's `GenericQualifiers.qualifier(version)` does that comparison for 
the qualifier, where a value below zero means a pre-release. It is what 
`DefaultPluginVersionResolver#isPreRelease` on master already uses (#12771). It 
needs resolver 2.0.21 or later, so Maven 3.10 and 4, not 3.9. Exposing that 
check as `VersionParser#isPreRelease(String)`, next to the existing 
`isSnapshot(String)`, would give plugins a supported way to ask the question 
without reading the canonical form.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to