-
Notifications
You must be signed in to change notification settings - Fork 85
Add semantic version selector API #239
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
Conversation
This semantic version number selector API is based on - https://draftin.com/documents/375100?token=rR30GmJJzi4l3BRlD-cHs8lcAcdDAXH4oTzqOWeL0CT0BNv3PZEx0g8pBkI13sQgYXTBqShZ0Ucsqek3Fn3d-aU - https://docs.npmjs.com/misc/semver
ed94d88
to
c0c88ed
Compare
@tanishiking Thanks for the PR!
Doesn't that contradict SemVer? We don't have |
* Semantic version selector API to check if the VersionNumber satisfies | ||
* conditions described by semantic version selector. | ||
*/ | ||
sealed abstract case class SemanticSelector( |
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.
For binary compatibility reasons, let's avoid case classes.
I think we should use Contraband here. I have a PR on sbt/sbt that adds JavaVersion
for example:
type JavaVersion {
numbers: [Long]
vendor: String
#x def numberStr: String = numbers.mkString(".")
#xtostring vendor.map(_ + "@").getOrElse("") + numberStr
#xcompanion def apply(version: String): JavaVersion = sbt.internal.CrossJava.parseJavaVersion(version)
}
@@ -27,6 +27,10 @@ final class VersionNumber private[sbt] ( | |||
case _ => false | |||
} | |||
|
|||
def satisfies(selector: String): Boolean = { |
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.
"satisfies" might be too strong since Ivy/Coursier/Maven have their own implementations, and also many of Scala or Java versions are not SemVer. A better name might be matchesSemVer
, and let it accept selector: SemanticSelector
?
- When major, minor, and patch are equal, a pre-release version has lower precedence than a normal version. Example: 1.0.0-alpha < 1.0.0. - Precedence for two pre-release versions with the same major, minor, and patch version MUST be determined by comparing each <del>dot</del> hyphen separated identifier from left to right until a difference is found as follows - identifiers consisting of only digits are compared numerically and identifiers with letters or hyphens are compared lexically in ASCII sort order. - Numeric identifiers always have lower precedence than non-numeric identifiers. - A larger set of pre-release fields has a higher precedence than a smaller set, if all of the preceding identifiers are equal. - Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0. https://semver.org/#spec-item-11
VersionNumber#matchesSemVer receive SemanticSelector instead of String
case object Gte extends SemSelOperator | ||
case object Gt extends SemSelOperator | ||
case object Eq extends SemSelOperator | ||
} |
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 implemented SemSelOperator
without contraband, because contraband's enum
doesn't seem to have any ways to implement custom toString
method?
@eed3si9n Thank you for the reviewing!
Hmm, yes you are right. It was'nt approprite to just ignore pre-release tags...
I undefstantood, 4e8b6dc changes the
I agree with you! d5f5cbb renames |
I think we are good to go on this. |
This PR addresses sbt/sbt#3710.
As disscussed in #218, it is unnatural to implement an
Ordering[VersionNumber]
for satisfying the use case presented in #3710. So this PR implements an API that is based on semantic version selector intead of implementing anOrdering[VersionNumber]
. Some behaviors are revised to satisfy #3710 refering npm's semver implementation.Logical operators
>1.0.0 <2.0.0
means(greater than 1.0.0) AND (less than 2.0.0)
)||
to or clause. (>1.0.0 <2.0.0 || >3.0.0
means((greater than 1.0.0) AND (less than 2.0.0)) OR (greater than 3.0.0)
).Basic operators
<=
,<
,>=
,>
,=
). If no operator is specified,=
is assumed.VersionNumber("1.0.0-alpha+meta").satisfies("=1.0.0")
would betrue
.1.0.0-alpha
from range matching semantics for avoiding auto upgrade libraries to their prerelease versions. https://docs.npmjs.com/misc/semver#prerelease-tags<=1.0
is equivalent to<1.1.0
.<1.0
is equivalent to<1.0.0
.>=1.0
is equivalent to>=1.0.0
.>1.0
is equivalent to>=1.1.0
.=1.0
is equivalent to>=1.0 <=1.0
(so>=1.0.0 <1.1.0
).Range operator
A.B.C - D.E.F
. This is equivalent to>=A.B.C <=D.E.F
.-
are required and they can not have any operators.Wildcard
*
,x
,X
. (For example1.2.x
.)=1.x
is equivalent to=1
,1.2.x
is equivalent to1.2
.If invalid form of selector string is passed to
SemanticSelector()
,IllegalArgumentException
wii be thrown.Examples