Skip to content

Commit 17e7374

Browse files
committed
Add support for parsing Scylla RC version numbers
Add support for parsing Scylla RC version numbers, such as 4.3.rc5. For it to co-exist with existing VersionNumber, 4.3.rc5 is parsed into 4.3.0-rc5.
1 parent 010b3fc commit 17e7374

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

driver-core/src/main/java/com/datastax/driver/core/VersionNumber.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
public class VersionNumber implements Comparable<VersionNumber> {
3535

3636
private static final String VERSION_REGEXP =
37-
"(\\d+)\\.(\\d+)(\\.\\d+)?(\\.\\d+)?([~\\-]\\w[.\\w]*(?:\\-\\w[.\\w]*)*)?(\\+[.\\w]+)?";
37+
"(\\d+)\\.(\\d+)(\\.(?:rc)?\\d+)?(\\.\\d+)?([~\\-]\\w[.\\w]*(?:\\-\\w[.\\w]*)*)?(\\+[.\\w]+)?";
3838
private static final Pattern pattern = Pattern.compile(VERSION_REGEXP);
3939

4040
private final int major;
@@ -79,8 +79,9 @@ public static VersionNumber parse(String version) {
7979
int minor = Integer.parseInt(matcher.group(2));
8080

8181
String pa = matcher.group(3);
82+
boolean isRC = pa != null && pa.startsWith(".rc"); // Detect Scylla naming convention: X.Y.rcZ
8283
int patch =
83-
pa == null || pa.isEmpty()
84+
pa == null || pa.isEmpty() || isRC
8485
? 0
8586
: Integer.parseInt(
8687
pa.substring(1)); // dropping the initial '.' since it's included this time
@@ -94,10 +95,12 @@ public static VersionNumber parse(String version) {
9495

9596
String pr = matcher.group(5);
9697
String[] preReleases =
97-
pr == null || pr.isEmpty()
98-
? null
99-
: pr.substring(1)
100-
.split("\\-"); // drop initial '-' or '~' then split on the remaining ones
98+
isRC
99+
? new String[] {pa.substring(1)}
100+
: pr == null || pr.isEmpty()
101+
? null
102+
: pr.substring(1)
103+
.split("\\-"); // drop initial '-' or '~' then split on the remaining ones
101104

102105
String bl = matcher.group(6);
103106
String build = bl == null || bl.isEmpty() ? null : bl.substring(1); // drop the initial '+'

driver-core/src/test/java/com/datastax/driver/core/VersionNumberTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ public void should_treat_same_prerelease_equal() {
106106
assertThat(version1.hashCode()).isEqualTo(version2.hashCode());
107107
}
108108

109+
@Test(groups = "unit")
110+
public void should_parse_scylla_release_candidates() {
111+
assertThat(VersionNumber.parse("4.3.rc5"))
112+
.hasMajorMinorPatch(4, 3, 0)
113+
.hasToString("4.3.0-rc5")
114+
.hasPreReleaseLabels("rc5");
115+
}
116+
109117
private void assertOrder(String version1, String version2, int expected) {
110118
assertThat(VersionNumber.parse(version1).compareTo(VersionNumber.parse(version2)))
111119
.isEqualTo(expected);

0 commit comments

Comments
 (0)