From 6399a1dfeb52a6c5bc155da1845202b94e064834 Mon Sep 17 00:00:00 2001 From: bom Date: Fri, 17 Nov 2023 14:58:53 +0100 Subject: [PATCH] Update regexes for gradle and python files --- .../python/ddadevops/domain/build_file.py | 35 +++++++------------ 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/src/main/python/ddadevops/domain/build_file.py b/src/main/python/ddadevops/domain/build_file.py index c159ca6..76cb044 100644 --- a/src/main/python/ddadevops/domain/build_file.py +++ b/src/main/python/ddadevops/domain/build_file.py @@ -48,11 +48,11 @@ class BuildFile(Validateable): def __get_file_type_regex_str(self, file_type: BuildFileType): match file_type: case BuildFileType.JAVA_GRADLE: - return "[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?" + return r'(?Pversion\s?=\s?)\"(?P\d*\.\d*\.\d*(-SNAPSHOT)?)\"' case BuildFileType.PYTHON: - return "[0-9]*\\.[0-9]*\\.[0-9]*(-SNAPSHOT)?(-dev)?[0-9]*" + return r'(?Pversion\s?=\s?)\"(?P\d*\.\d*\.\d*(-SNAPSHOT|-dev\d*)?)\"' case BuildFileType.JAVA_CLOJURE: - return r'(?P\(defproject\s(\S)*\s)\"(?P\d*\.\d*\.\d*(-SNAPSHOT)?)\"' + return r'(?P\(defproject\s(\S)*\s)\"(?P\d*\.\d*\.\d*(-SNAPSHOT)?)\"' case _: return "" @@ -63,22 +63,9 @@ class BuildFile(Validateable): case BuildFileType.JS: version_str = json.loads(self.content)["version"] case BuildFileType.JAVA_GRADLE: - # TODO: '\nversion = ' will not parse all ?! - version_line = re.search("\nversion = .*", 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") case BuildFileType.PYTHON: - # TODO: '\nversion = ' will not parse all ?! - version_line = re.search("\nversion = .*\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") case BuildFileType.JAVA_CLOJURE: version_str = re.search(self.__get_file_type_regex_str(build_file_type), self.content).group("version") except: @@ -103,22 +90,24 @@ class BuildFile(Validateable): self.content = json.dumps(json_data, indent=4) case BuildFileType.JAVA_GRADLE: substitute = re.sub( - f'\nversion = "{self.__get_file_type_regex_str(build_file_type)}"', - f'\nversion = "{new_version.to_string()}"', + self.__get_file_type_regex_str(build_file_type), + fr'\g"{new_version.to_string()}"', self.content, + 1, ) self.content = substitute case BuildFileType.PYTHON: substitute = re.sub( - f'\nversion = "{self.__get_file_type_regex_str(build_file_type)}"', - f'\nversion = "{new_version.to_string()}"', + self.__get_file_type_regex_str(build_file_type), + fr'\g"{new_version.to_string()}"', self.content, + 1, ) self.content = substitute case BuildFileType.JAVA_CLOJURE: substitute = re.sub( self.__get_file_type_regex_str(build_file_type), - fr'\g"{new_version.to_string()}"', + fr'\g"{new_version.to_string()}"', self.content, 1, )