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

feat!: make version comparison semver compliant #115

Merged
merged 6 commits into from
May 6, 2021

Conversation

jdrueckert
Copy link
Member

Closes #113

@jdrueckert jdrueckert added the Type: Improvement Request for or addition/enhancement of a feature label May 4, 2021
@jdrueckert jdrueckert requested a review from keturn May 4, 2021 21:05
@jdrueckert jdrueckert self-assigned this May 4, 2021
@jdrueckert jdrueckert changed the base branch from develop to release/v7.x May 4, 2021 21:06
@skaldarnar
Copy link
Member

skaldarnar commented May 4, 2021

@jdrueckert
Copy link
Member Author

Copy link
Member

@keturn keturn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This abandons the attempt at moving the compatible-version logic to the JSemVer library. But since writing that I have found out that gradle's default version-compatibility logic is not nearly as semver-compatible as I thought it was. VersionRange is a pretty good model as a thing to translate to gradle after all, as gradle doesn't have the ^ range comparison operator.

I marked a nit or two but I am good with the overall approach.

Suggestion: I think this got rid of the things that needed Version.semver to be package-visible:

com.github.zafarkhaja.semver.Version semver;

so we can make that private again and revert 4b6ea6d (should do before release)

@@ -44,7 +44,7 @@ public Version getUpperBound() {
* @return Whether version falls within the range
*/
public boolean contains(Version version) {
return version.compareTo(lowerBound.getSnapshot()) >= 0 && version.compareTo(upperBound.getSnapshot()) < 0;
return version.compareTo(lowerBound) >= 0 && version.compareTo(upperBound.getSnapshot()) < 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for Terasology's current use cases. I agree that having one VersionRange class is better than having the one-foot-in-one-foot-out thing I had going on.

The edge cases this falls apart on are things like 1.4.7-SNA or 1.4.7-SNAPSHOT-2. Which—maybe we don't care? Would be fine with declaring that out of scope. But that is the sort of thing that motivated me to try to delegate the problem to the SemVer library (since we have it anyway).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like completely removing VersionRange would be another option.

Technically, SemVer does not describe anything special about -SNAPSHOT (I think this is a maven concept). All of the -.... exmaples are pre-releases, and none of them matches a version requirement for the released version.

Comment on lines 74 to 77
if (minVersion.getMajor() == 0) {
return minVersion.getNextMinorVersion();
return minVersion.getVersionCore().getNextMinorVersion();
}
return minVersion.getNextMajorVersion();
return minVersion.getVersionCore().getNextMajorVersion();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: this is another one of those places that makes me think "if we have to keep this if "0.x" logic ourselves, what good is having JSemVer?"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking): regardless of JSemVer, we could move this to a method on Version. "getExclusiveUpperCompatibleRangeVersion" or somesuch.

or maybe instead of trying to figure out what to name the method that returns the exclusive-upper-bound-version, have Version construct the VersionRange itself.

public VersionRange getCompatibleRange()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 noted - have to think about this.

public VersionRange versionRange() {
return new VersionRange(getMinVersion(), getMaxVersion());
}

public Predicate<Version> versionPredicate() {
Copy link
Member

@keturn keturn May 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about types here.

Predicate<Version> is sufficient for gestalt ResolutionAttempt to do its thing. But there are a few other requirements we should consider:

  • for troubleshooting purposes, this should at least have a toString value that makes more sense than lambda@123 or whatever. (Give feedback on failed dependency resolution #15 might also appreciate a rich type, but will probably find a string sufficient.)
  • for gradle compatibility, it needs either this minVersion, maxVersion pair or a string containing a maven-compatible range descriptor (which is what VersionRange.toString currently provides)

which makes me think we want to keep the return type as VersionRange after all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me bring up my question about sum types again... 🙄 nargh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this one needs sum types. One class can implement both Predicate<Version> and ConvertableToMavenRange or whatever.

@skaldarnar skaldarnar requested a review from keturn May 6, 2021 07:28
@skaldarnar
Copy link
Member

@keturn are any of the remaining comments blocking for this PR? If not, let's merge it and continue the discussion on VersionRange and semver fun in Discord and open a follow-up if we settled on something.

@keturn keturn merged commit 1fa1664 into release/v7.x May 6, 2021
@keturn keturn deleted the feat/make-version-comparison-semver-compliant branch May 6, 2021 17:03
*/
public VersionRange versionRange() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keturn this is actually used in the Terasology modules builds 🙈 Guess we need to bring this method back to make that work again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Improvement Request for or addition/enhancement of a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

change VersionRange comparison so 2.0-SNAPSHOT does not satisfy 2.0
3 participants