|
| 1 | +import os |
1 | 2 | from os import path |
2 | 3 | from typing import Optional |
3 | 4 |
|
@@ -29,35 +30,40 @@ def get_commands(self, manifest_file_path: str) -> list[list[str]]: |
29 | 30 | def get_lock_file_name(self) -> str: |
30 | 31 | return join_paths('target', MAVEN_CYCLONE_DEP_TREE_FILE_NAME) |
31 | 32 |
|
| 33 | + def get_working_directory(self, document: Document) -> Optional[str]: |
| 34 | + return os.path.dirname(document.absolute_path) |
| 35 | + |
32 | 36 | def try_restore_dependencies(self, document: Document) -> Optional[Document]: |
33 | | - restore_dependencies_document = super().try_restore_dependencies(document) |
34 | 37 | manifest_file_path = self.get_manifest_file_path(document) |
35 | 38 | if document.content is None: |
36 | | - restore_dependencies_document = self.restore_from_secondary_command( |
37 | | - document, manifest_file_path, restore_dependencies_document |
38 | | - ) |
39 | | - else: |
40 | | - restore_dependencies_document.content = get_file_content( |
41 | | - join_paths(get_file_dir(manifest_file_path), self.get_lock_file_name()) |
42 | | - ) |
| 39 | + return self.restore_from_secondary_command(document, manifest_file_path) |
| 40 | + |
| 41 | + restore_dependencies_document = super().try_restore_dependencies(document) |
| 42 | + if restore_dependencies_document is None: |
| 43 | + return None |
| 44 | + |
| 45 | + restore_dependencies_document.content = get_file_content( |
| 46 | + join_paths(get_file_dir(manifest_file_path), self.get_lock_file_name()) |
| 47 | + ) |
43 | 48 |
|
44 | 49 | return restore_dependencies_document |
45 | 50 |
|
46 | | - def restore_from_secondary_command( |
47 | | - self, document: Document, manifest_file_path: str, restore_dependencies_document: Optional[Document] |
48 | | - ) -> Optional[Document]: |
49 | | - # TODO(MarshalX): does it even work? Ignored restore_dependencies_document arg |
50 | | - secondary_restore_command = create_secondary_restore_commands(manifest_file_path) |
51 | | - backup_restore_content = execute_commands(secondary_restore_command, self.command_timeout) |
52 | | - restore_dependencies_document = Document( |
53 | | - build_dep_tree_path(document.path, MAVEN_DEP_TREE_FILE_NAME), backup_restore_content, self.is_git_diff |
| 51 | + def restore_from_secondary_command(self, document: Document, manifest_file_path: str) -> Optional[Document]: |
| 52 | + restore_content = execute_commands( |
| 53 | + commands=create_secondary_restore_commands(manifest_file_path), |
| 54 | + timeout=self.command_timeout, |
| 55 | + working_directory=self.get_working_directory(document), |
54 | 56 | ) |
55 | | - restore_dependencies = None |
56 | | - if restore_dependencies_document.content is not None: |
57 | | - restore_dependencies = restore_dependencies_document |
58 | | - restore_dependencies.content = get_file_content(MAVEN_DEP_TREE_FILE_NAME) |
| 57 | + if restore_content is None: |
| 58 | + return None |
59 | 59 |
|
60 | | - return restore_dependencies |
| 60 | + restore_file_path = build_dep_tree_path(document.absolute_path, MAVEN_DEP_TREE_FILE_NAME) |
| 61 | + return Document( |
| 62 | + path=build_dep_tree_path(document.path, MAVEN_DEP_TREE_FILE_NAME), |
| 63 | + content=get_file_content(restore_file_path), |
| 64 | + is_git_diff_format=self.is_git_diff, |
| 65 | + absolute_path=restore_file_path, |
| 66 | + ) |
61 | 67 |
|
62 | 68 |
|
63 | 69 | def create_secondary_restore_commands(manifest_file_path: str) -> list[list[str]]: |
|
0 commit comments