From 22c41880012191f4e63c48a9c724b307b55659dc Mon Sep 17 00:00:00 2001 From: Joel Strasser Date: Mon, 25 Sep 2023 22:41:04 +0200 Subject: [PATCH 1/2] additionally match release stub for YaCy version --- .../peers/operation/yacyBuildProperties.java | 1 + .../net/yacy/peers/operation/yacyVersion.java | 37 +++++++++++-------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/source/net/yacy/peers/operation/yacyBuildProperties.java b/source/net/yacy/peers/operation/yacyBuildProperties.java index d71f28b98..0da296595 100644 --- a/source/net/yacy/peers/operation/yacyBuildProperties.java +++ b/source/net/yacy/peers/operation/yacyBuildProperties.java @@ -49,4 +49,5 @@ public static String getTstamp() { public static final Pattern versionMatcher = Pattern.compile("\\A(\\d+\\.\\d{1,3})(\\d{0,5})\\z"); + public static final Pattern releaseStubVersionMatcher = Pattern.compile("yacy_v(\\d+.\\d{1,3})_(\\d{12})_([0-9a-f]{9})"); } diff --git a/source/net/yacy/peers/operation/yacyVersion.java b/source/net/yacy/peers/operation/yacyVersion.java index b9bd56e68..f668b0088 100644 --- a/source/net/yacy/peers/operation/yacyVersion.java +++ b/source/net/yacy/peers/operation/yacyVersion.java @@ -129,29 +129,36 @@ public int hashCode() { } /** - * Converts combined version-string to a pretty string, e.g. "0.435/01818" or "dev/01818" (development version) or "dev/00000" (in case of wrong input) + * Converts combined version-string to a pretty string, e.g. "1.926/3230df6e2", "0.435/01818" or "dev/01818" (development version) or "dev/00000" (in case of wrong input) * - * @param ver Combined version string matching regular expression: "\A(\d+\.\d{3})(\d{4}|\d{5})\z"
- * (i.e.: start of input, 1 or more digits in front of decimal point, decimal point followed by 3 digits as major version, 4 or 5 digits for SVN-Version, end of input) - * @return If the major version is < 0.11 - major version is separated from SVN-version by '/', e.g. "0.435/01818"
- * If the major version is >= 0.11 - major version is replaced by "dev" and separated SVN-version by '/', e.g."dev/01818"
- * "dev/00000" - If the input does not matcht the regular expression above + * @param combinedVersion Combined version string matching regular expression: "yacy_v(\d+.\d{1,3})_(\d{12})_([0-9a-f]{9})" or "\A(\d+\.\d{1,3})(\d{0,5})\z" + * @return If the combined version matches a release stub - "1.926/3230df6e2"
+ * If the major version is < 0.11 - major version is replaced by "dev" and separated SVN-version by '/', e.g."dev/01818"
+ * If the major version is >= 0.11 - major version is separated from SVN-version by '/', e.g. "0.435/01818"
+ * "dev/00000" - If the input does not match either regular expression above */ - public static String[] combined2prettyVersion(final String ver) { - return combined2prettyVersion(ver, ""); + public static String[] combined2prettyVersion(final String combinedVersion) { + return combined2prettyVersion(combinedVersion, ""); } public static String[] combined2prettyVersion(final String ver, final String computerName) { final Matcher matcher = yacyBuildProperties.versionMatcher.matcher(ver); - if (!matcher.find()) { - ConcurrentLog.warn("STARTUP", "Peer '"+computerName+"': wrong format of version-string: '" + ver + "'. Using default string 'dev/00000' instead"); - return new String[]{"dev", "0000"}; + final Matcher releaseStubMatcher = yacyBuildProperties.releaseStubVersionMatcher.matcher(ver); + + String mainVersion = "dev"; + String revision = "00000"; + + if (matcher.find()) { + mainVersion = (Double.parseDouble(matcher.group(1)) < 0.11 ? "dev" : matcher.group(1)); + revision = matcher.group(2); + } else if (releaseStubMatcher.find()){ + mainVersion = releaseStubMatcher.group(1); + revision = releaseStubMatcher.group(3); + } else { + ConcurrentLog.warn("STARTUP", "Peer '"+computerName+"': wrong format of version-string: '" + ver + "'. Using default string '" + mainVersion + "/" + revision + "' instead"); } - final String mainversion = (Double.parseDouble(matcher.group(1)) < 0.11 ? "dev" : matcher.group(1)); - String revision = matcher.group(2); - for(int i=revision.length();i<4;++i) revision += "0"; - return new String[]{mainversion, revision}; + return new String[]{mainVersion, revision}; } public static int revision(final String ver) { From 53bafa15442e4f44af51673c6763061891912082 Mon Sep 17 00:00:00 2001 From: Joel Strasser Date: Mon, 25 Sep 2023 23:31:55 +0200 Subject: [PATCH 2/2] consistent formatting in string concatenation --- source/net/yacy/peers/operation/yacyVersion.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/net/yacy/peers/operation/yacyVersion.java b/source/net/yacy/peers/operation/yacyVersion.java index f668b0088..b3a202c1c 100644 --- a/source/net/yacy/peers/operation/yacyVersion.java +++ b/source/net/yacy/peers/operation/yacyVersion.java @@ -155,7 +155,7 @@ public static String[] combined2prettyVersion(final String ver, final String com mainVersion = releaseStubMatcher.group(1); revision = releaseStubMatcher.group(3); } else { - ConcurrentLog.warn("STARTUP", "Peer '"+computerName+"': wrong format of version-string: '" + ver + "'. Using default string '" + mainVersion + "/" + revision + "' instead"); + ConcurrentLog.warn("STARTUP", "Peer '" + computerName + "': wrong format of version-string: '" + ver + "'. Using default string '" + mainVersion + "/" + revision + "' instead"); } return new String[]{mainVersion, revision};