diff --git a/src/main/java/org/auioc/mods/arnicalib/utils/java/VersionUtils.java b/src/main/java/org/auioc/mods/arnicalib/utils/java/VersionUtils.java index e54efd7c..c4c7a57e 100644 --- a/src/main/java/org/auioc/mods/arnicalib/utils/java/VersionUtils.java +++ b/src/main/java/org/auioc/mods/arnicalib/utils/java/VersionUtils.java @@ -4,7 +4,6 @@ import java.util.jar.Attributes; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.annotation.Nullable; import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.Marker; import org.auioc.mods.arnicalib.utils.LogUtil; @@ -15,6 +14,7 @@ public class VersionUtils { private static final Pair DEFAULT_VERSION_TUPLE = Pair.of("0", "0"); private static final Pattern REVISION_NUMBER_PATTERN = Pattern.compile("(?<=rev\\.)[0-9a-fA-F]{7}"); + private static final Pattern BUILD_NUMBER_PATTERN = Pattern.compile("(?<=build\\.)\\d+"); public static String getMainVersion(Attributes attrs) { return attrs.getValue("Implementation-Version"); @@ -22,7 +22,7 @@ public static String getMainVersion(Attributes attrs) { public static String getFullVersion(Attributes attrs, String modName) { String version = attrs.getValue(modName + "-Version"); - if (getRevisionNumber(version) == null) { + if (getRevisionNumber(version).isEmpty()) { LOGGER.warn(MARKER, "The revision number of mod " + modName + " is null. If this is a manually built version you can ignore this message."); } return version; @@ -44,13 +44,20 @@ public static Pair getModVersion(Class clazz) { return getModVersion(clazz, clazz.getSimpleName()); } - @Nullable public static String getRevisionNumber(String fullVersion) { Matcher matcher = REVISION_NUMBER_PATTERN.matcher(fullVersion); if (matcher.find()) { return matcher.group(); } - return null; + return ""; + } + + public static int getBuildNumber(String fullVersion) { + Matcher matcher = BUILD_NUMBER_PATTERN.matcher(fullVersion); + if (matcher.find()) { + return Integer.parseInt(matcher.group()); + } + return 0; } }