From e1b1eb2a0c9318e03b83a3f033135444174a1732 Mon Sep 17 00:00:00 2001 From: helderjosue Date: Thu, 4 Apr 2024 21:41:56 +0200 Subject: [PATCH 1/2] TRUNK-5480: adding support to module version ranges using plus(+) sign --- .../java/org/openmrs/module/ModuleUtil.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/ModuleUtil.java b/api/src/main/java/org/openmrs/module/ModuleUtil.java index 738ffa115066..4273f6baab48 100644 --- a/api/src/main/java/org/openmrs/module/ModuleUtil.java +++ b/api/src/main/java/org/openmrs/module/ModuleUtil.java @@ -287,8 +287,8 @@ public static boolean matchRequiredVersions(String version, String versionRange) for (String range : ranges) { // need to externalize this string String separator = "-"; - if (range.indexOf("*") > 0 || range.indexOf(separator) > 0 && (!isVersionWithQualifier(range))) { - // if it contains "*" or "-" then we must separate those two + if (range.indexOf("*") > 0 || range.indexOf("+") > 0 || range.indexOf(separator) > 0 && (!isVersionWithQualifier(range))) { + // if it contains "*" or "-" or "+" then we must separate those two // assume it's always going to be two part // assign the upper and lower bound // if there's no "-" to split lower and upper bound @@ -309,17 +309,24 @@ public static boolean matchRequiredVersions(String version, String versionRange) // only preserve part of the string that match the following format: // - xx.yy.* // - xx.yy.zz* - lowerBound = StringUtils.remove(lowerBound, lowerBound.replaceAll("^\\s?\\d+[\\.\\d+\\*?|\\.\\*]+", "")); - upperBound = StringUtils.remove(upperBound, upperBound.replaceAll("^\\s?\\d+[\\.\\d+\\*?|\\.\\*]+", "")); + // - aa.bb+ + // - aa.b+ + lowerBound = StringUtils.remove(lowerBound, lowerBound.replaceAll("^\\s?\\d+[\\.\\d+\\*?|\\.\\*|\\.\\d+\\+?|\\.\\+]+", "")); + upperBound = StringUtils.remove(upperBound, upperBound.replaceAll("^\\s?\\d+[\\.\\d+\\*?|\\.\\*|\\.\\d+\\+?|\\.\\+]+", "")); - // if the lower contains "*" then change it to zero + // if the lower contains "*" or "+" then change it to zero if (lowerBound.indexOf("*") > 0) { lowerBound = lowerBound.replaceAll("\\*", "0"); + }else if (lowerBound.indexOf("+") > 0) { + lowerBound = lowerBound.replaceAll("\\+", ".0"); } - // if the upper contains "*" then change it to maxRevisionNumber + // if the upper contains "*" or "+" then change it to maxRevisionNumber + String maxRevisionNumber = Integer.toString(Integer.MAX_VALUE); if (upperBound.indexOf("*") > 0) { - upperBound = upperBound.replaceAll("\\*", Integer.toString(Integer.MAX_VALUE)); + upperBound = upperBound.replaceAll("\\*", maxRevisionNumber); + }else if (upperBound.indexOf("+") > 0) { + upperBound = upperBound.replaceAll("\\+", ".".concat(maxRevisionNumber)); } int lowerReturn = compareVersion(version, lowerBound); From bcdcf861c6ef71434ce381a37d81fa342b1c87e4 Mon Sep 17 00:00:00 2001 From: helderjosue Date: Fri, 5 Apr 2024 09:20:04 +0200 Subject: [PATCH 2/2] TRUNK-5480: adding test for plus sign version range --- api/src/main/java/org/openmrs/module/ModuleUtil.java | 2 ++ api/src/test/java/org/openmrs/module/ModuleUtilTest.java | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/api/src/main/java/org/openmrs/module/ModuleUtil.java b/api/src/main/java/org/openmrs/module/ModuleUtil.java index 4273f6baab48..42e6300c129b 100644 --- a/api/src/main/java/org/openmrs/module/ModuleUtil.java +++ b/api/src/main/java/org/openmrs/module/ModuleUtil.java @@ -242,11 +242,13 @@ public static boolean isOpenmrsVersionInVersions(String ...versions) { *
  • 1.2.*
  • *
  • 1.2.2 - 1.2.3
  • *
  • 1.2.* - 1.3.*
  • + *
  • 1.4+ - 1.3.3
  • * *

    * Again the possible require version number formats with their interpretation: *