From 04f67823e5a51468a0b6b79c73f72ec5736679a2 Mon Sep 17 00:00:00 2001 From: Luke Bemish Date: Wed, 21 Feb 2024 08:06:12 -0600 Subject: [PATCH] Smarter version bumping --- .../managedversioning/VersionValueSource.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/lukebemish/managedversioning/VersionValueSource.java b/src/main/java/dev/lukebemish/managedversioning/VersionValueSource.java index 5ed77ef..05ad557 100644 --- a/src/main/java/dev/lukebemish/managedversioning/VersionValueSource.java +++ b/src/main/java/dev/lukebemish/managedversioning/VersionValueSource.java @@ -50,11 +50,23 @@ public final String obtain() { if (fileVersion.equals(lastTagVersion)) { if (!lastTagHash.equals(getParameters().getCommitHash().get())) { var noMetaParts = version.toString().split("-"); - var noBuildParts = noMetaParts[0].split("\\+"); - var mainParts = noBuildParts[0].split("\\."); + int lastMetaNumber = 0; + for (int i = 0; i < noMetaParts.length; i++) { + if (noMetaParts[i].matches(".*\\.\\d+.*")) { + lastMetaNumber = i; + } + } + var noBuildParts = noMetaParts[lastMetaNumber].split("\\+"); + int lastBuildNumber = 0; + for (int i = 0; i < noBuildParts.length; i++) { + if (noBuildParts[i].matches(".*\\.\\d+.*")) { + lastBuildNumber = i; + } + } + var mainParts = noBuildParts[lastBuildNumber].split("\\."); mainParts[mainParts.length-1] = Integer.toString(Integer.parseInt(mainParts[mainParts.length-1])+1); - noBuildParts[0] = String.join(".", mainParts); - noMetaParts[0] = String.join("+", noBuildParts); + noBuildParts[lastBuildNumber] = String.join(".", mainParts); + noMetaParts[lastMetaNumber] = String.join("+", noBuildParts); version = new StringBuilder(String.join("-", noMetaParts)); } }