From 617d90943809757f0aa71b90da052f72e9673c7b Mon Sep 17 00:00:00 2001 From: bom Date: Fri, 17 Nov 2023 14:42:47 +0100 Subject: [PATCH] Replace clojure version regex --- src/main/python/ddadevops/domain/build_file.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/main/python/ddadevops/domain/build_file.py b/src/main/python/ddadevops/domain/build_file.py index 1a65bf2..7c29ec9 100644 --- a/src/main/python/ddadevops/domain/build_file.py +++ b/src/main/python/ddadevops/domain/build_file.py @@ -52,7 +52,7 @@ class BuildFile(Validateable): case BuildFileType.PYTHON: return "[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?(-dev)?[0-9]*" case BuildFileType.JAVA_CLOJURE: - return "[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?" + return r'(?P\(defproject\s(\S)*\s)\"(?P\d*\.\d*\.\d*(-SNAPSHOT)?)\"' case _: return "" @@ -80,13 +80,7 @@ class BuildFile(Validateable): ) version_str = version_string.group() case BuildFileType.JAVA_CLOJURE: - # TODO: unsure about the trailing '\n' ! - version_line = re.search("\\(defproject .*\n", self.content) - version_line_group = version_line.group() - version_string = re.search( - self.__get_file_type_regex_str(build_file_type), version_line_group - ) - version_str = version_string.group() + version_str = re.search(self.__get_file_type_regex_str(build_file_type), self.content).group("version") except: raise RuntimeError(f"Version not found in file {self.file_path}") @@ -96,7 +90,6 @@ class BuildFile(Validateable): return result def set_version(self, new_version: Version): - # TODO: How can we create regex-pattern constants to use them at both places? if new_version.is_snapshot(): new_version.snapshot_suffix = self.get_default_suffix() @@ -125,8 +118,8 @@ class BuildFile(Validateable): case BuildFileType.JAVA_CLOJURE: # TODO: we should stick here on defproject instead of first line! substitute = re.sub( - f'"{self.__get_file_type_regex_str(build_file_type)}"', - f'"{new_version.to_string()}"', + self.__get_file_type_regex_str(build_file_type), + fr'\g"{new_version.to_string()}"', self.content, 1, )