Github user geomacy commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/740#discussion_r124298663
--- Diff:
utils/common/src/main/java/org/apache/brooklyn/util/text/BrooklynVersionSyntax.java
---
@@ -84,4 +89,100 @@ public static boolean isValidOsgiVersion(String
candidate) {
return candidate!=null &&
candidate.matches(VALID_OSGI_VERSION_REGEX);
}
+ /** Creates a string satisfying {@link #isValidOsgiVersion(String)}
based on the input.
+ * For input satisfying {@link #isGoodBrooklynVersion(String)} the
only change will be in the qualifer separator
+ * (from "-" to ".") and making any "0" minor/patch token explicit (so
"1-x" becomes "1.0.0.x"),
+ * and the change can be reversed using {@link
#toGoodBrooklynVersion(String)} (modulo insertion of "0"'s for minor/patch
numbers if missing).
+ * For input satisfying {@link #isValidOsgiVersion(String)}, the only
change will be insertions of 0 for minor/patch.
+ * Precise behaviour for other input is not guaranteed but callers can
expect output which resembles the input,
+ * with any major/minor/patch string at the front preserved and
internal contiguous alphanumeric sequences preserved. */
+ public static String toValidOsgiVersion(String input) {
+ Preconditions.checkNotNull(input);
+ return toGoodVersion(input, ".", true);
+ /* Note Maven has and used: DefaultMaven2OsgiConverter
+ * from
https://github.com/apache/felix/blob/trunk/tools/maven-bundle-plugin/src/main/java/org/apache/maven/shared/osgi/DefaultMaven2OsgiConverter.java
+ * but it (a) is more complicated, and (b) doesn't aggressively
find numbers e.g. "1beta" goes to "0.0.0.1beta" instead of "1.0.0.beta"
+ */
+ }
+
+ /** Creates a string satisfying {@link #isGoodBrooklynVersion(String)}
based on the input.
+ * For input satisfying {@link #isGoodBrooklynVersion(String)} the
input will be returned unchanged.
+ * For input satisfying {@link #isValidOsgiVersion(String)} the
qualifier separator will be changed to "-",
+ * and {@link #toValidOsgiVersion(String)} can be used to reverse the
input (modulo insertion of "0"'s for minor/patch numbers if missing).
+ * Precise behaviour for other input is not guaranteed but callers can
expect output which resembles the input,
+ * with any major/minor/patch string at the front preserved and
internal contiguous alphanumeric sequences preserved. */
+ public static String toGoodBrooklynVersion(String input) {
+ return toGoodVersion(input, "-", false);
+ }
+
+ private static String toGoodVersion(String input, String
qualifierSeparator, boolean requireMinorAndPatch) {
+ Preconditions.checkNotNull(input);
+ final String FUZZY_REGEX =
--- End diff --
Might be nice to try to get all the regexes that define all these variants
into one place, with duplications removed.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---