This is an automated email from the ASF dual-hosted git repository.
diqiu50 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new aa4043d646 [#9482] improvement(common): Enhance version parsing to
support release candidates with validation (#9939)
aa4043d646 is described below
commit aa4043d646f335852397088497b5d9b8829cc075
Author: Qi Yu <[email protected]>
AuthorDate: Thu Feb 26 16:39:11 2026 +0800
[#9482] improvement(common): Enhance version parsing to support release
candidates with validation (#9939)
### What changes were proposed in this pull request?
This pull request updates the version parsing logic in `Version.java` to
support release candidate (RC) versions and adds tests to ensure correct
handling of RC numbers. The main changes include expanding the regex
pattern to recognize RC versions, enforcing bounds on RC numbers, and
introducing unit tests for these scenarios.
### Why are the changes needed?
To make it work when verifing release candidate version in the
playground.
Fix: #9482
### Does this PR introduce _any_ user-facing change?
N/A
### How was this patch tested?
UTs
---
.../main/java/org/apache/gravitino/Version.java | 2 +-
.../java/org/apache/gravitino/TestVersion.java | 56 ++++++++++++++++++++++
2 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/common/src/main/java/org/apache/gravitino/Version.java
b/common/src/main/java/org/apache/gravitino/Version.java
index b4183b10ed..64eb3c49bc 100644
--- a/common/src/main/java/org/apache/gravitino/Version.java
+++ b/common/src/main/java/org/apache/gravitino/Version.java
@@ -36,7 +36,7 @@ public class Version {
private static final int VERSION_PART_NUMBER = 3;
private static final Pattern PATTERN =
- Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+)(?:-.*|\\.([a-zA-Z].*))?$");
+
Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+)(?:rc(\\d{1,9})|-.*|\\.([a-zA-Z].*))?$");
private static final Version INSTANCE = new Version();
diff --git a/common/src/test/java/org/apache/gravitino/TestVersion.java
b/common/src/test/java/org/apache/gravitino/TestVersion.java
new file mode 100644
index 0000000000..9cadb9b814
--- /dev/null
+++ b/common/src/test/java/org/apache/gravitino/TestVersion.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino;
+
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestVersion {
+
+ @Test
+ public void testParseReleaseCandidateVersions() {
+ Assertions.assertArrayEquals(new int[] {1, 1, 0},
Version.parseVersionNumber("1.1.0rc0"));
+ Assertions.assertArrayEquals(new int[] {1, 1, 0},
Version.parseVersionNumber("1.1.0rc1"));
+ Assertions.assertArrayEquals(new int[] {1, 1, 0},
Version.parseVersionNumber("1.1.0rc1000"));
+ }
+
+ @Test
+ public void testParseReleaseCandidateOutOfRange() {
+ Assertions.assertDoesNotThrow(() ->
Version.parseVersionNumber("1.1.0rc1001"));
+ Assertions.assertThrowsExactly(
+ GravitinoRuntimeException.class, () ->
Version.parseVersionNumber("1.1.0rc"));
+ Assertions.assertThrowsExactly(
+ GravitinoRuntimeException.class, () ->
Version.parseVersionNumber("1.1.0rc-1"));
+ }
+
+ @Test
+ public void testParseSnapshotVersion() {
+ Assertions.assertArrayEquals(new int[] {1, 1, 0},
Version.parseVersionNumber("1.1.0-SNAPSHOT"));
+ Assertions.assertArrayEquals(new int[] {2, 0, 1},
Version.parseVersionNumber("2.0.1-beta"));
+ Assertions.assertArrayEquals(new int[] {3, 2, 4},
Version.parseVersionNumber("3.2.4-foo.bar"));
+ }
+
+ @Test
+ public void testParseAlphaVersion() {
+ Assertions.assertArrayEquals(new int[] {1, 1, 0},
Version.parseVersionNumber("1.1.0.alpha"));
+ Assertions.assertArrayEquals(new int[] {0, 9, 9},
Version.parseVersionNumber("0.9.9.alpha1"));
+ }
+}