-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MNG-7559] Fix version comparison (master 4.0.x branch) #929
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the extra space after/before <li>
tags.
maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java
Outdated
Show resolved
Hide resolved
* <li> | ||
* String qualifiers are ordered lexically (case insensitive), with the following exceptions: | ||
* <ul> | ||
* <li> 'snapshot' < '' < 'sp' </li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sp
for service pack?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed. SP has been hard coded in maven code since ages. the maven docs now discourages its use. but removing it altogether might not be without surprises. most known are Hibernate and Weld using 'Final' qualifiers instead of none, and Weld using SP1 instead of patch versions increment. i hope to see them change their release procedures in the future. Spring was using 'release' qualifier but has now stopped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maven team might want at some point to not support Final, GA, Release, and SP qualifiers anymore. in that case i will happily change the code and documentation. letting as is for now (unless instructed otherwise)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what about really following semantic version instead of creating exceptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what about really following semantic version instead of creating exceptions?
A breaking change suitable for the Major 4 update. if the Maven team accepts, i can perform a separate Jira/PR removing the exceptions in the master branch only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what about really following semantic version instead of creating exceptions?
A breaking change suitable for the Major 4 update. if the Maven team accepts, i can perform a separate Jira/PR removing the exceptions in the master branch only.
I agree with that. Please, let's leave breaking changes out of this PR and not conflate things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Michael, could you perhaps write a post to the mailing list with a vote about that if you agree? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cleanup you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cleanup you mean?
i think Andrzej meant a vote for Maven 4 to be semver compatible or at least move towards it step by step (PR by PR)
5246e0f
to
4f0c93f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I now understand is that arbitrary qualifiers are not considered after GA
. Following example:
I need to fork commons-io 2.12.0 for the company and it will be named 2.12.0-company-1
through 2.12.0-company-5
. I would expect that those come after the GA because I had to apply custom patches.
I do this at work for various reasons and if you check libs bundled with Nexus they have SONATYPE
qualifier.
maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java
Outdated
Show resolved
Hide resolved
maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java
Show resolved
Hide resolved
maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java
Show resolved
Hide resolved
maven-artifact/src/main/java/org/apache/maven/artifact/versioning/ComparableVersion.java
Outdated
Show resolved
Hide resolved
maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java
Show resolved
Hide resolved
maven-artifact/src/test/java/org/apache/maven/artifact/versioning/ComparableVersionTest.java
Show resolved
Hide resolved
checkVersionsOrder("2.0.1.MR", "2.0.1"); | ||
checkVersionsOrder("9.4.1.jre16-preview", "9.4.1.jre16"); | ||
checkVersionsEqual("2.0.a", "2.0.0.a"); // previously ordered, now equals | ||
checkVersionsOrder("1-sp-1", "1-ga-1"); // proving website documentation right. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also there is no change here, this is weird, isn't? I mean a service pack comes after GA
, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i agree with you but the website documentation says otherwise. this is an edge case that may need a separate PR to fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the test checkVersionsOrder("9.4.1.jre16-preview", "9.4.1.jre16");
Is there a feature wish to support "filters" inside the version extension like "jre\d+"? I assume, the specification of version number must be adapted for that, because it's not the idea of "jre17" is later or better than a "jdk8" release. It's just the same release for another platform.
So semantically, checkVersionsEqual("9.4.1.jre16", "9.4.1.jre8");
and the result to get a newer version from the complete version list depends on the current selected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think the number are already taken into account but a unit test for them will not hurt
i'll have to amend the code; meanwhile there should be a talk -maybe i should join the mailing list- about what the future yields between Maven and SemVer
I must honestly admit that I feel a lot of pain in my ass with this class because:
Edge case: I think this needs to be split up again. Let's first focus on the |
4f0c93f
to
00d5d53
Compare
@hboutemy I know that you worked on this once in a while. What is your opinion? |
this can be split into two PRs if needed. the ordering is dispatched into specific locations:
still open for a better approach to make things more readable |
What would those two PRs contain? |
one for dot/dash case ( .RC1 < -RC2 ) but that would only separate 10 lines of code from the rest. |
Yes, please let's do the dot/hyphen issue with a separate JIRA ticket first. |
JIRA/PRs created:
|
you may want to use the + instead of - as in: maybe a third PR to be merged before for this case ? |
Right, according to SemVer my approach is wrong. Thanks for the clarification. |
@sultan Please rebase this PR on top of current master. |
00d5d53
to
1ff256c
Compare
1ff256c
to
ed7fb4d
Compare
rebased with a minor change in javadoc and tests |
As far as I understand now this is a change in behavior? If so, I cannot apply to 3.8.x because it is not a bugfix. Is it? |
still a bug fix but i am ok to have it only in Major update 4.0 if the change breaks behaviour |
Let me have a fresh look at this tomorrow. |
yes no hurry, the Maven docs used to tell that all other qualifiers were considered later than release, and as of now: lesser than release. if the spec was not in error but require a change then its a major update. what i wonder if its also the same for the dot/hyphen change and need revert 3.8 and 3.9 so the fix is only on 4.0 |
Will check that.
Why? The docs say:
so |
I must admit that I partially lost overview. @sultan Can you again briefly summarize how the current implementation does not correspond to the spec regardless of pfd or preview qualifiers? |
Hi @michael-o if I may, I think the current implementation is in line with the specification as I have a feeling that the specification has been based on it 😄 The problem is that the spec deviates from SemVer in how it treats non-standard qualifiers, like the "pfd" here. According to SemVer, all qualifiers should be treated as less than -.number whereas with "the spec" all non-standard qualifiers are treated as later than -.number. As is the case of "-pdf" which is later than the release. So this:
is not exactly true. @Test
public void testComparableVersionWithCustomQualifier()
{
assertThat( new DefaultArtifactVersion( "2.3" ).compareTo( new DefaultArtifactVersion( "2.3-pfd" ) ),
greaterThan( 0 ) );
}
So, adding "pfd" as a recognised qualifier would mean that the spec also needs to be updated. Which is why it's a breaking change and not a bugfix. Frankly, to me it looks like this behaviour contradicts the statement that "-qualifier" < "-number", but I've long given up on that. |
I have just re-read the spec. It says:
So what it does is just use the syntax of SemVer 1.0 and not the semantics. It considers only a new qualifiers as pre-release and not all, e.g., sp for service pack is a post-GA qualifier. So to me this change is change of the specs since it wants add more qualifiers to the pre-release state. I will remove this ticket from 3.x for obvious reasons. I think that the version scheme requires an update in 4.0, but that is a different discussion. Opinions? Side note:
PS: I am not happy with the ambiguity/lack of precision of the current spec |
As of now Javadoc:
Previously, Javadoc used to be:
no trace of the old statement on maven site, but a major change in the public javadoc the PR that should not be merged are already closed/unmerged |
this equality is a change in the docs dated from Nov 14th on maven site it was previously
thus a major change in the docs from maven site that would mean revert change on 3.x for Jira #7644 |
Bah, I am really about to puke. So much complexity for something quite obvious, I guess. Looking at |
the numbers part gave me headaches as well ^^
the parser was and is treating numbers and string differently (else/if). the previous parser
i can see a benefit of change with .RC4 = -RC4 and .RC1 < -RC2 but i cannot yet see a benefit of change for numbers, as you may want to keep treat - as dot for numbers will lead to bad surprises. we should discourage the use of numeric qualifiers -1, -2 -N in the docs |
returning back to this PR feature. (qualifiers ordering)
yeah i forgot that, sorry.
the SemVer way to achieve this would be on the artifact id:
the choice of adding 'company' as a qualifier is ambiguous regarding to features and versions ordering |
This is quite ugly, if you can host the repo on corporate Nexus. I have the feeling that SemVer 2.0 is not ideally suited for Maven. |
we might not be able to be fully SemVer 2.0 compatible because of legacy artifacts that were there before SemVer 1.0 was even defined. so if we cant be semver 2 compatible, why not borrow the + sign? or any other sign to distinguish between natural ordering from maven custom ordering. there is surely a good reason for the expected behaviour, but i seem to lack the understanding and i'm not sure i can suggest a valid solution until the expected result is formalized
there could be other approaches like minus is before GA and plus is after GA 1.0.0-x < 1.0.0 < 1.0.0+x |
why not put a pause on the pr? i'll try to send questions to the mailing list after the holidays. i would not want to suggest a solution that put aside someone wishes. |
This is also my desire to pause until clarified. |
This PR can be merged, If wanted to port (to 4.0.x) the fix for https://issues.apache.org/jira/browse/MNG-7559
intention is:
following semver rules should be encouraged, natural ordering is used without the need to hard code strings, except for hard coded qualifiers 'a', 'b', 'm', 'cr', 'snapshot', 'final', 'ga', 'release', '' and 'sp':
the documentation should discourage the usage of 'CR', 'final', 'ga', 'release' and 'SP' qualifiers.
Maven Central should begin to reject new artifact using CR and SP qualifiers.
Following this checklist to help us incorporate your
contribution quickly and easily:
for the change (usually before you start working on it). Trivial changes like typos do not
require a JIRA issue. Your pull request should address just this issue, without
pulling in other changes.
[MNG-XXX] SUMMARY
,where you replace
MNG-XXX
andSUMMARY
with the appropriate JIRA issue.[MNG-XXX] SUMMARY
.Best practice is to use the JIRA issue title in both the pull request title and in the first line of the commit message.
mvn clean verify
to make sure basic checks pass. A more thorough check willbe performed on your pull request automatically.
If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.