diff --git a/pontos/version/commands/_java.py b/pontos/version/commands/_java.py index 379c7e07..2eb89bd7 100644 --- a/pontos/version/commands/_java.py +++ b/pontos/version/commands/_java.py @@ -24,16 +24,18 @@ from ..errors import VersionError from ..version import Version, VersionUpdate -VERSION_PATTERN = ( - r"^(?P
.*[^\d])"
-    r"(?P\d+\.\d+\.\d+"
-    r"(-?([ab]|rc|alpha|beta)\d+(.dev\d+)?)?)"
-    r"(?P.*$)"
-)
-
 
 # This class is used for Java Version command(s)
 class JavaVersionCommand(VersionCommand):
+    VERSION_PATTERN = (
+        r"^(?P
.*[^\d])?"
+        r"("
+        r"?P\d+\.\d+\.\d+"
+        r"([-\.]+(dev|rc|beta|a|alpha|b)\d+)*"
+        r")"
+        r"(?P.*$)"
+    )
+
     project_file_name = "upgradeVersion.json"
 
     def get_current_version(self) -> Version:
@@ -79,6 +81,9 @@ def update_version(
             changed_files=changed_files,
         )
 
+    def parse_line(self, version_line: str):
+        return re.match(self.VERSION_PATTERN, version_line, re.DOTALL)
+
     def _update_version_files(self, new_version) -> List[Path]:
         config = self._load_config()
 
@@ -90,7 +95,7 @@ def _update_version_files(self, new_version) -> List[Path]:
                 line_number = file_config["line"]
                 version_line = lines[line_number - 1]
 
-                matches = re.match(VERSION_PATTERN, version_line, re.DOTALL)
+                matches = self.parse_line(version_line)
                 if matches is None:
                     raise VersionError(
                         f"Line has no version, "
@@ -143,7 +148,7 @@ def _read_versions_from_files(self) -> Dict[str, str]:
                         f"file:'{file_path}'"
                     )
                 version_line = readlines[line_number - 1]
-                matches = re.match(VERSION_PATTERN, version_line, re.DOTALL)
+                matches = self.parse_line(version_line)
                 if matches is None:
                     raise VersionError(
                         f"Line has no version, "
diff --git a/tests/version/commands/test_java.py b/tests/version/commands/test_java.py
index 50f2a8ec..5f42160b 100644
--- a/tests/version/commands/test_java.py
+++ b/tests/version/commands/test_java.py
@@ -72,6 +72,45 @@
 """
 
 
+class VerifyJavaVersionParsingTestCase(unittest.TestCase):
+    def test_version_parsing(self):
+        versions = {
+            "2023.12.10",
+            "2023.1.1",
+            "2023.10.1",
+            "2023.1.99",
+            "0.0.1",
+            "1.2.3-a1",
+            "1.2.3-alpha1",
+            "1.2.3-alpha1-dev1",
+            "1.2.3-b1",
+            "1.2.3-beta1",
+            "1.2.3-beta1-dev1",
+            "1.2.3-rc1",
+            "1.2.3-rc1-dev1",
+            "1.2.3-dev1",
+            "22.4.1",
+            "22.4.1-dev1",
+            "0.5.0.dev1",
+            "1.0.0-dev1",
+            "1.0.0-alpha1",
+            "1.0.0-alpha1-dev1",
+            "1.0.0-beta1",
+            "1.0.0-beta1-dev1",
+            "1.0.0-rc1",
+            "1.0.0-rc1-dev1",
+        }
+        for version in versions:
+            with self.subTest(version=version):
+                matches = JavaVersionCommand(
+                    SemanticVersioningScheme
+                ).parse_line(f"pre{version}post")
+
+                self.assertEqual(matches.group("pre"), "pre")
+                self.assertEqual(matches.group("version"), version)
+                self.assertEqual(matches.group("post"), "post")
+
+
 class GetCurrentJavaVersionCommandTestCase(unittest.TestCase):
     def test_getting_version(self):
         with temp_directory(change_into=True):