diff --git a/cycode/cli/files_collector/sca/maven/base_restore_maven_dependencies.py b/cycode/cli/files_collector/sca/maven/base_restore_maven_dependencies.py index 064b9eeb..d15e1ef0 100644 --- a/cycode/cli/files_collector/sca/maven/base_restore_maven_dependencies.py +++ b/cycode/cli/files_collector/sca/maven/base_restore_maven_dependencies.py @@ -4,7 +4,7 @@ import click from cycode.cli.models import Document -from cycode.cli.utils.path_utils import get_file_dir, join_paths +from cycode.cli.utils.path_utils import get_file_content, get_file_dir, join_paths from cycode.cli.utils.shell_executor import shell from cycode.cyclient import logger @@ -39,6 +39,23 @@ def get_manifest_file_path(self, document: Document) -> str: else document.path ) + def try_restore_dependencies(self, document: Document) -> Optional[Document]: + manifest_file_path = self.get_manifest_file_path(document) + restore_file_path = build_dep_tree_path(document.path, self.get_lock_file_name()) + + if self.verify_restore_file_already_exist(restore_file_path): + restore_file_content = get_file_content(restore_file_path) + else: + restore_file_content = execute_command( + self.get_command(manifest_file_path), manifest_file_path, self.command_timeout + ) + + return Document(restore_file_path, restore_file_content, self.is_git_diff) + + @abstractmethod + def verify_restore_file_already_exist(self, restore_file_path: str) -> bool: + pass + @abstractmethod def is_project(self, document: Document) -> bool: pass @@ -50,11 +67,3 @@ def get_command(self, manifest_file_path: str) -> List[str]: @abstractmethod def get_lock_file_name(self) -> str: pass - - def try_restore_dependencies(self, document: Document) -> Optional[Document]: - manifest_file_path = self.get_manifest_file_path(document) - return Document( - build_dep_tree_path(document.path, self.get_lock_file_name()), - execute_command(self.get_command(manifest_file_path), manifest_file_path, self.command_timeout), - self.is_git_diff, - ) diff --git a/cycode/cli/files_collector/sca/maven/restore_gradle_dependencies.py b/cycode/cli/files_collector/sca/maven/restore_gradle_dependencies.py index ef975ba5..21fdb7c3 100644 --- a/cycode/cli/files_collector/sca/maven/restore_gradle_dependencies.py +++ b/cycode/cli/files_collector/sca/maven/restore_gradle_dependencies.py @@ -1,3 +1,4 @@ +import os from typing import List import click @@ -22,3 +23,6 @@ def get_command(self, manifest_file_path: str) -> List[str]: def get_lock_file_name(self) -> str: return BUILD_GRADLE_DEP_TREE_FILE_NAME + + def verify_restore_file_already_exist(self, restore_file_path: str) -> bool: + return os.path.isfile(restore_file_path) diff --git a/cycode/cli/files_collector/sca/maven/restore_maven_dependencies.py b/cycode/cli/files_collector/sca/maven/restore_maven_dependencies.py index 0e21df12..d9c117e6 100644 --- a/cycode/cli/files_collector/sca/maven/restore_maven_dependencies.py +++ b/cycode/cli/files_collector/sca/maven/restore_maven_dependencies.py @@ -29,6 +29,9 @@ def get_command(self, manifest_file_path: str) -> List[str]: def get_lock_file_name(self) -> str: return join_paths('target', MAVEN_CYCLONE_DEP_TREE_FILE_NAME) + def verify_restore_file_already_exist(self, restore_file_path: str) -> bool: + return False + def try_restore_dependencies(self, document: Document) -> Optional[Document]: restore_dependencies_document = super().try_restore_dependencies(document) manifest_file_path = self.get_manifest_file_path(document)