From fd66dd6dcd026ff3cc0651bd3f5e83e3f1f84e8c Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 20 Mar 2019 16:39:13 -0400 Subject: Convert specifiers (#38) * Add convert_specifiers * Add convert_specifiers to README --- README.md | 3 ++- vars/utils.groovy | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3304709..86efd98 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,8 @@ The `utils` library provides several functions: | --- | --- | | `if (utils.scm_checkout()) return` | Accepts: Will ignore any `[skip ci]`/`[ci skip]` directive found in the latest commit message. This is used in certain regression testing jobs that run on a schedule, the execution of which should never be skipped due to skip directives found in the commit history. | | `utils.copy()` | Accepts: | -| `utils.run(config_list, concurrent=true)` | Accepts: +| `utils.run(config_list, concurrent=true)` | Accepts: | +| `utils.convert_specifiers(s)` | #### JobConfig Class This class contains properties that may be adjusted to control the behavior of the overall Jenkins job. diff --git a/vars/utils.groovy b/vars/utils.groovy index 5390929..7b74187 100644 --- a/vars/utils.groovy +++ b/vars/utils.groovy @@ -726,6 +726,24 @@ def run(configs, concurrent = true) { } +// Condense version triplet and replace version specifier(s) with human-readable text +// +// @param String s string containing version specifiers +// @return String string with converted version specifiers +String convert_specifiers(String s) { + String result = s + result = result.replaceAll("\\.", "") // No period + .replaceAll(",", "") // No comma + .replaceAll("<", "L") // Less than + .replaceAll(">", "G") // Greater than + .replaceAll("~=", "C") // Compatible (GE x.y && L x.*) + .replaceAll("=", "E") // Equal to (=, E | ==, EE) + .replaceAll("\\!", "N") // Not equal to + + return result +} + + // Convenience function that performs a deep copy on the supplied object. // // @param obj Java/Groovy object to copy -- cgit