-
Notifications
You must be signed in to change notification settings - Fork 3
fix: if a version < 4.3.0 is specified create an old-style TDF #234
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f07e544
add version class
mkleene f3b77ac
add features for hash compatibility settings
mkleene f00fbf4
fix up test
mkleene ce1bc69
add comment
mkleene dd95db1
add option to command line
mkleene b35f037
Update Config.java
mkleene 87fe9a9
Merge branch 'main' into feature/hash-compat
mkleene 51fa228
Update Config.java
mkleene 252c909
Update VersionTest.java
mkleene 0844225
assertions on manifest and hex chars
mkleene afa676e
rename and config test
mkleene ec3d1a0
one more
mkleene 2715a71
we do not need this encoding
mkleene 345c440
code review suggestions
mkleene 458626f
update regex so there is no backtracking
mkleene File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package io.opentdf.platform.sdk; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.annotation.Nullable; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.regex.Pattern; | ||
|
||
class Version implements Comparable<Version> { | ||
private final int major; | ||
private final int minor; | ||
private final int patch; | ||
private final String prereleaseAndMetadata; | ||
private static final Logger log = LoggerFactory.getLogger(Version.class); | ||
|
||
Pattern SEMVER_PATTERN = Pattern.compile("^(?<major>0|[1-9]\\d*)\\.(?<minor>0|[1-9]\\d*)\\.(?<patch>0|[1-9]\\d*)(?<prereleaseAndMetadata>\\D.*)?$"); | ||
|
||
@Override | ||
public String toString() { | ||
return "Version{" + | ||
"major=" + major + | ||
", minor=" + minor + | ||
", patch=" + patch + | ||
", prereleaseAndMetadata='" + prereleaseAndMetadata + '\'' + | ||
'}'; | ||
} | ||
|
||
public Version(String semver) { | ||
var matcher = SEMVER_PATTERN.matcher(semver); | ||
if (!matcher.matches()) { | ||
throw new IllegalArgumentException("Invalid version format: " + semver); | ||
} | ||
this.major = Integer.parseInt(matcher.group("major")); | ||
this.minor = Optional.ofNullable(matcher.group("minor")).map(Integer::parseInt).orElse(0); | ||
this.patch = Optional.ofNullable(matcher.group("patch")).map(Integer::parseInt).orElse(0); | ||
this.prereleaseAndMetadata = matcher.group("prereleaseAndMetadata"); | ||
} | ||
|
||
public Version(int major, int minor, int patch, @Nullable String prereleaseAndMetadata) { | ||
this.major = major; | ||
this.minor = minor; | ||
this.patch = patch; | ||
this.prereleaseAndMetadata = prereleaseAndMetadata; | ||
} | ||
|
||
@Override | ||
public int compareTo(@Nonnull Version o) { | ||
if (this.major != o.major) { | ||
return Integer.compare(this.major, o.major); | ||
} | ||
if (this.minor != o.minor) { | ||
return Integer.compare(this.minor, o.minor); | ||
} | ||
if (this.patch != o.patch) { | ||
return Integer.compare(this.patch, o.patch); | ||
} | ||
log.debug("ignoring prerelease and buildmetadata during comparision this = {} o = {}", this, o); | ||
return 0; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Version version = (Version) o; | ||
return major == version.major && minor == version.minor && patch == version.patch; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(major, minor, patch); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
sdk/src/test/java/io/opentdf/platform/sdk/VersionTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.opentdf.platform.sdk; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class VersionTest { | ||
|
||
@Test | ||
public void testParsingVersions() { | ||
assertThat(new Version("1.0.0")).isEqualTo(new Version(1, 0, 0, null)); | ||
assertThat(new Version("1.2.1-alpha")).isEqualTo(new Version(1, 2, 1, "alpha a build")); | ||
// ignore anything but the version | ||
assertThat(new Version("1.2.1-alpha+build.123")).isEqualTo(new Version(1, 2, 1, "beta build.1234")); | ||
} | ||
|
||
@Test | ||
public void testComparingVersions() { | ||
assertThat(new Version("1.0.0")).isLessThan(new Version("1.0.1")); | ||
assertThat(new Version("1.0.1")).isGreaterThan(new Version("1.0.0")); | ||
|
||
assertThat(new Version("500.0.1")).isLessThan(new Version("500.1.1")); | ||
assertThat(new Version("500.1.1")).isGreaterThan(new Version("500.0.1")); | ||
|
||
// ignore anything but the version | ||
assertThat(new Version("1.0.1-alpha+thisbuild")).isEqualByComparingTo(new Version("1.0.1-beta+thatbuild")); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.