Compare commits

..

No commits in common. "a0c7d27fec12251712f4c360d0e60b3d8fb25d7d" and "65ffe5a3e1186b1e48f92b2c60568061c33b1b92" have entirely different histories.

3 changed files with 5 additions and 8 deletions

View file

@ -7,7 +7,7 @@ plugins {
} }
group = "dev.frogmc" group = "dev.frogmc"
version = "0.0.1-alpha.15" version = "0.0.1-alpha.14"
repositories { repositories {
maven { maven {

View file

@ -4,6 +4,6 @@ import java.io.IOException;
public class SemVerParseException extends IOException { public class SemVerParseException extends IOException {
public SemVerParseException(String message) { public SemVerParseException(String message) {
super("Failed to parse SemVer: `" + message + "`"); super("Failed to parse SemVer: " + message);
} }
} }

View file

@ -9,13 +9,12 @@ import java.util.regex.Pattern;
import dev.frogmc.frogloader.api.mod.SemVer; import dev.frogmc.frogloader.api.mod.SemVer;
import dev.frogmc.frogloader.impl.SemVerParseException; import dev.frogmc.frogloader.impl.SemVerParseException;
import lombok.NonNull; import lombok.NonNull;
import org.jetbrains.annotations.Nullable;
public record SemVerImpl(int major, int minor, int patch, String prerelease, String build) implements SemVer { public record SemVerImpl(int major, int minor, int patch, String prerelease, String build) implements SemVer {
// Adapted from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string // Adapted from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
private static final Pattern SEMVER_PATTERN = Pattern.compile("^(?<major>0|[1-9]\\d*)\\." + private static final Pattern SEMVER_PATTERN = Pattern.compile("^(?<major>0|[1-9]\\d*)\\." +
"(?<minor>0|[1-9]\\d*)" + "(?<minor>0|[1-9]\\d*)\\." +
"(\\.(?<patch>0|[1-9]\\d*))?" + "(?<patch>0|[1-9]\\d*)" +
"(?:-(?<prerelease>(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)" + "(?:-(?<prerelease>(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)" +
"(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?" + "(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?" +
"(?:\\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"); "(?:\\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$");
@ -28,9 +27,7 @@ public record SemVerImpl(int major, int minor, int patch, String prerelease, Str
int major = Integer.parseInt(matcher.group("major")); int major = Integer.parseInt(matcher.group("major"));
int minor = Integer.parseInt(matcher.group("minor")); int minor = Integer.parseInt(matcher.group("minor"));
// minecraft treats the `patch` component as optional... int patch = Integer.parseInt(matcher.group("patch"));
@Nullable String patchString = matcher.group("patch");
int patch = patchString == null ? 0 : Integer.parseInt(patchString);
String prerelease = matcher.group("prerelease"); String prerelease = matcher.group("prerelease");
String buildmetadata = matcher.group("buildmetadata"); String buildmetadata = matcher.group("buildmetadata");
return new SemVerImpl(major, minor, patch, prerelease, buildmetadata); return new SemVerImpl(major, minor, patch, prerelease, buildmetadata);