Skip to content

Commit 908f5b8

Browse files
authored
CM-31147 - Add support reading existing restore file from directory for gradle (#193)
1 parent b956ea5 commit 908f5b8

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

cycode/cli/files_collector/sca/maven/base_restore_maven_dependencies.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import click
55

66
from cycode.cli.models import Document
7-
from cycode.cli.utils.path_utils import get_file_dir, join_paths
7+
from cycode.cli.utils.path_utils import get_file_content, get_file_dir, join_paths
88
from cycode.cli.utils.shell_executor import shell
99
from cycode.cyclient import logger
1010

@@ -39,6 +39,23 @@ def get_manifest_file_path(self, document: Document) -> str:
3939
else document.path
4040
)
4141

42+
def try_restore_dependencies(self, document: Document) -> Optional[Document]:
43+
manifest_file_path = self.get_manifest_file_path(document)
44+
restore_file_path = build_dep_tree_path(document.path, self.get_lock_file_name())
45+
46+
if self.verify_restore_file_already_exist(restore_file_path):
47+
restore_file_content = get_file_content(restore_file_path)
48+
else:
49+
restore_file_content = execute_command(
50+
self.get_command(manifest_file_path), manifest_file_path, self.command_timeout
51+
)
52+
53+
return Document(restore_file_path, restore_file_content, self.is_git_diff)
54+
55+
@abstractmethod
56+
def verify_restore_file_already_exist(self, restore_file_path: str) -> bool:
57+
pass
58+
4259
@abstractmethod
4360
def is_project(self, document: Document) -> bool:
4461
pass
@@ -50,11 +67,3 @@ def get_command(self, manifest_file_path: str) -> List[str]:
5067
@abstractmethod
5168
def get_lock_file_name(self) -> str:
5269
pass
53-
54-
def try_restore_dependencies(self, document: Document) -> Optional[Document]:
55-
manifest_file_path = self.get_manifest_file_path(document)
56-
return Document(
57-
build_dep_tree_path(document.path, self.get_lock_file_name()),
58-
execute_command(self.get_command(manifest_file_path), manifest_file_path, self.command_timeout),
59-
self.is_git_diff,
60-
)

cycode/cli/files_collector/sca/maven/restore_gradle_dependencies.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from typing import List
23

34
import click
@@ -22,3 +23,6 @@ def get_command(self, manifest_file_path: str) -> List[str]:
2223

2324
def get_lock_file_name(self) -> str:
2425
return BUILD_GRADLE_DEP_TREE_FILE_NAME
26+
27+
def verify_restore_file_already_exist(self, restore_file_path: str) -> bool:
28+
return os.path.isfile(restore_file_path)

cycode/cli/files_collector/sca/maven/restore_maven_dependencies.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ def get_command(self, manifest_file_path: str) -> List[str]:
2929
def get_lock_file_name(self) -> str:
3030
return join_paths('target', MAVEN_CYCLONE_DEP_TREE_FILE_NAME)
3131

32+
def verify_restore_file_already_exist(self, restore_file_path: str) -> bool:
33+
return False
34+
3235
def try_restore_dependencies(self, document: Document) -> Optional[Document]:
3336
restore_dependencies_document = super().try_restore_dependencies(document)
3437
manifest_file_path = self.get_manifest_file_path(document)

0 commit comments

Comments
 (0)