-
Notifications
You must be signed in to change notification settings - Fork 25
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
Introduce VersionRange
#330
Conversation
@dmlloyd @aloubyansky I introduced an utility class to check the range introduced in quarkusio/quarkus#41908 |
version/src/main/java/io/smallrye/common/version/VersionRange.java
Outdated
Show resolved
Hide resolved
version/src/main/java/io/smallrye/common/version/VersionRange.java
Outdated
Show resolved
Hide resolved
version/src/main/java/io/smallrye/common/version/VersionRange.java
Outdated
Show resolved
Hide resolved
version/src/main/java/io/smallrye/common/version/VersionRange.java
Outdated
Show resolved
Hide resolved
Looks nice @gastaldi, thanks! Could we also add tests involving version qualifiers? Right now the tests are limited to "Final" versions. So, for example, if a range starts with |
But |
We may want to test |
The |
@aloubyansky I added more tests, see if they make sense |
assertTrue(versionRange.test("3.8.4.SP1-redhat-00001")); | ||
assertTrue(versionRange.test("3.8.4.SP2-redhat-00001")); | ||
assertTrue(versionRange.test("3.8.4.redhat-00002")); | ||
assertFalse(versionRange.test("3.8.5.redhat-00003")); |
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.
Thanks, this looks good. What if you test 3.8.0.SP1-redhat-00001
for [3.8.0.redhat-00001,)
?
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.
It fails. Not sure why.
This returns 1
:
VersionScheme.MAVEN.compare("3.8.0.redhat-00001", "3.8.0.SP1-redhat-00001")
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 wonder if we shouldn't have a specific Red Hat VersionScheme
for cases like these
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.
It's ok, it's not a blocker, I was just wondering. Dependabot has the same issue. We can fix it later. It'd be good to fix it though :)
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 resolver actually does handle it properly.
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.
Hm, that sounds like a bug in MavenVersionScheme
. WDYT @dmlloyd ?
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 believe that custom qualifiers come after predefined qualifiers (like SP
) according to the Maven rules.
$ jbang --main=org.eclipse.aether.util.version.GenericVersionScheme org.apache.maven.resolver:maven-resolver-util:1.9.6 1.redhat 1.sp
Display parameters as parsed by Maven Resolver (in canonical form and as a list of tokens) and comparison result:
1. 1.redhat -> 1.redhat; tokens: [1, redhat]
1.redhat > 1.sp
2. 1.sp -> 1.sp; tokens: [1, 1]
$ jbang --main=org.eclipse.aether.util.version.GenericVersionScheme org.apache.maven.resolver:maven-resolver-util:1.9.6 3.8.0.redhat-00001 3.8.0.SP1-redhat-00001
Display parameters as parsed by Maven Resolver (in canonical form and as a list of tokens) and comparison result:
1. 3.8.0.redhat-00001 -> 3.8.0.redhat-00001; tokens: [3, 8, redhat, 1]
3.8.0.redhat-00001 > 3.8.0.SP1-redhat-00001
2. 3.8.0.SP1-redhat-00001 -> 3.8.0.SP1-redhat-00001; tokens: [3, 8, 1, 1, redhat, 1]
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.
Make sure you aren't using the utilities in maven-artifact
to test, because that is generally considered to be deprecated at this point (and IIUC is not used by Maven anymore).
This introduces a predicate that can be used for comparing if given a version is contained inside a version range pattern
f2d9318
to
258257d
Compare
There are two main problems remaining that I can see. The first problem is that of the parser. It operates by searching the same string ranges many times (using The second problem is the restriction classes, which implement a parallel variety of predicate compared to the I'd made an example commit here which you can feel free to use as you wish. This commit institutes a left-to-right parser and ensures there is only one way for the API to represent a range predicate. One thing that this commit does not do, which we can look into if you think this would be a valid use case, is validate that a given version range is indeed valid (other than a couple very opportunistic checks). The reason for this again is that the predicate methods should behave identically to the range-parsed predicates. That is, if the parser rejects I hope this makes sense. Feel free to use some, all, or none of my example commit to get this over the line. Thanks! |
Intoduce a left-to-right recursive-descent parser for version ranges. Use the predicates on `VersionScheme` to compose the resultant range.
@dmlloyd loved it! I've pushed your commit to my branch for your appreciation |
This introduces a predicate that can be used for comparing if given a version is contained inside a version range pattern