This is an automated email from the ASF dual-hosted git repository.

roryqi pushed a commit to branch branch-1.1
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/branch-1.1 by this push:
     new 46bbd250ef [Cherry-pick to branch-1.1] [#9482] improvement(common): 
Enhance version parsing to support release candidates with validation (#10057) 
(#10060)
46bbd250ef is described below

commit 46bbd250efcb8571f929837e542087cffeac830f
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Fri Feb 27 14:53:35 2026 +0800

    [Cherry-pick to branch-1.1] [#9482] improvement(common): Enhance version 
parsing to support release candidates with validation (#10057) (#10060)
    
    **Cherry-pick Information:**
    - Original commit: dcba1bd05f30fe87dc2053e871ea8beb64225fab
    - Target branch: `branch-1.1`
    - Status: ✅ Clean cherry-pick (no conflicts)
    
    Co-authored-by: Qi Yu <[email protected]>
---
 .../main/java/org/apache/gravitino/Version.java    |  2 +-
 .../java/org/apache/gravitino/TestVersion.java     | 62 ++++++++++++++++++++++
 2 files changed, 63 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..f62252f552 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(0|[1-9]\\d*)|-.*|\\.([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..5ef5fdf8d4
--- /dev/null
+++ b/common/src/test/java/org/apache/gravitino/TestVersion.java
@@ -0,0 +1,62 @@
+/*
+ * 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"));
+    Assertions.assertThrowsExactly(
+        GravitinoRuntimeException.class, () -> 
Version.parseVersionNumber("1.1.0rc01"));
+    Assertions.assertThrowsExactly(
+        GravitinoRuntimeException.class, () -> 
Version.parseVersionNumber("1.1.0rc001"));
+    Assertions.assertThrowsExactly(
+        GravitinoRuntimeException.class, () -> 
Version.parseVersionNumber("1.1.0rc11xx"));
+  }
+
+  @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"));
+  }
+}

Reply via email to