Skip to content
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

Handy func: since and before #72

Open
da-tubi opened this issue Apr 2, 2022 · 10 comments
Open

Handy func: since and before #72

da-tubi opened this issue Apr 2, 2022 · 10 comments

Comments

@da-tubi
Copy link
Contributor

da-tubi commented Apr 2, 2022

Usually, a breaking API change happens on a specific version.

How about using since and before

@enableIf(classpathMatchesArtifact(crossScalaBinaryVersion("spark-catalyst"), since("3.2.1")))

But I think it is too verbose, how about:

@enableIf(since(crossScalaBinaryVersion("spark-catalyst"), "3.2.1"))
@enableIf(before(crossScalaBinaryVersion("spark-catalyst"), "3.2.1"))
  • since means >=
  • before means <
@da-tubi da-tubi changed the title Handy func: since Handy func: since and before Apr 2, 2022
@Atry
Copy link
Collaborator

Atry commented Apr 2, 2022

Is there any existing library for comparing versions?

@Atry
Copy link
Collaborator

Atry commented Apr 2, 2022

Version number could be extremely complicated to parse, and there are more than one standard, e.g. SemVer, PVP.

@Atry
Copy link
Collaborator

Atry commented Apr 2, 2022

@da-tubi
Copy link
Contributor Author

da-tubi commented Apr 2, 2022

Here is an overview of version comparison: https://www.baeldung.com/java-comparing-versions

I think we need a library which has zero dependencies.

@da-tubi
Copy link
Contributor Author

da-tubi commented Apr 2, 2022

How about sbt.librarymanagement.VersionNumber#matchesSemVer as https://stackoverflow.com/questions/14540503/comparing-versions-in-sbt indicated.

@da-tubi
Copy link
Contributor Author

da-tubi commented Apr 2, 2022

@ import $ivy.`org.scala-sbt::librarymanagement-core:1.6.1`

@ import sbt.librarymanagement.VersionNumber
import sbt.librarymanagement.VersionNumber

@ import sbt.librarymanagement.SemanticSelector
import sbt.librarymanagement.SemanticSelector

@ VersionNumber("2.12.5").matchesSemVer(SemanticSelector(">=2.12"))
res3: Boolean = true

@ VersionNumber("2.12.5").matchesSemVer(SemanticSelector(">2.12"))
res4: Boolean = false

@ VersionNumber("2.12.5").matchesSemVer(SemanticSelector("<2.12"))
res5: Boolean = false

@ VersionNumber("2.12.5").matchesSemVer(SemanticSelector("=2.12"))
res6: Boolean = true

@da-tubi
Copy link
Contributor Author

da-tubi commented Apr 2, 2022

Might be a better API:

@enableIf(matchesSemVer(crossScalaBinaryVersion("spark-catalyst"), ">=3.2.1"))

@da-tubi
Copy link
Contributor Author

da-tubi commented Apr 2, 2022

We may take the API from sbt and the IMPL from just-semver:

https://github.com/Kevin-Lee/just-semver

@Atry
Copy link
Collaborator

Atry commented Apr 2, 2022

I think enableIf.scala should not depend on any of the libraries. Instead it would be good to let enableIf.scala provide a helper function that accepts a String => Bool version predictor, while the users are free to use other libraries to create the predictor.

@Atry
Copy link
Collaborator

Atry commented Apr 7, 2022

Note that when using a library with the @enableIf annotation, you can use Provided scope to avoid introducing the dependency to the runtime

libraryDependencies += "group-id" %% "artifact-id" % "version" % Provided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants