Skip to content

Commit

Permalink
feat(utils): method for getting build number from full mod version
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Jan 13, 2022
1 parent 21c33a2 commit df44fa1
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,14 +14,15 @@ public class VersionUtils {

private static final Pair<String, String> 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");
}

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;
Expand All @@ -44,13 +44,20 @@ public static Pair<String, String> 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;
}

}
Expand Down

0 comments on commit df44fa1

Please sign in to comment.