Skip to content

Commit 0e27280

Browse files
Bouncheckavelanarius
authored andcommitted
Port 17e7374 from 3.x branch (Parse rc versions)
1 parent d9d4531 commit 0e27280

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

core/src/main/java/com/datastax/oss/driver/api/core/Version.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class Version implements Comparable<Version>, Serializable {
4242
private static final long serialVersionUID = 1;
4343

4444
private static final String VERSION_REGEXP =
45-
"(\\d+)\\.(\\d+)(\\.\\d+)?(\\.\\d+)?([~\\-]\\w[.\\w]*(?:-\\w[.\\w]*)*)?(\\+[.\\w]+)?";
45+
"(\\d+)\\.(\\d+)(\\.(?:rc)?\\d+)?(\\.\\d+)?([~\\-]\\w[.\\w]*(?:-\\w[.\\w]*)*)?(\\+[.\\w]+)?";
4646

4747
private static final Pattern pattern = Pattern.compile(VERSION_REGEXP);
4848

@@ -100,8 +100,9 @@ public static Version parse(@Nullable String version) {
100100
int minor = Integer.parseInt(matcher.group(2));
101101

102102
String pa = matcher.group(3);
103+
boolean isRC = pa != null && pa.startsWith(".rc"); // Detect Scylla naming convention: X.Y.rcZ
103104
int patch =
104-
pa == null || pa.isEmpty()
105+
pa == null || pa.isEmpty() || isRC
105106
? 0
106107
: Integer.parseInt(
107108
pa.substring(1)); // dropping the initial '.' since it's included this time
@@ -115,10 +116,12 @@ public static Version parse(@Nullable String version) {
115116

116117
String pr = matcher.group(5);
117118
String[] preReleases =
118-
pr == null || pr.isEmpty()
119-
? null
120-
: pr.substring(1)
121-
.split("-"); // drop initial '-' or '~' then split on the remaining ones
119+
isRC
120+
? new String[] {pa.substring(1)}
121+
: pr == null || pr.isEmpty()
122+
? null
123+
: pr.substring(1)
124+
.split("-"); // drop initial '-' or '~' then split on the remaining ones
122125

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

core/src/test/java/com/datastax/oss/driver/api/core/VersionTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ public void should_parse_dse_patch() {
6868
.hasNextStable("1.2.19.2");
6969
}
7070

71+
@Test
72+
public void should_parse_scylla_release_candidates() {
73+
assertThat(Version.parse("4.3.rc5"))
74+
.hasMajorMinorPatch(4, 3, 0)
75+
.hasToString("4.3.0-rc5")
76+
.hasPreReleaseLabels("rc5");
77+
}
78+
7179
@Test
7280
public void should_order_versions() {
7381
// by component

0 commit comments

Comments
 (0)