Skip to content

Commit a838ebd

Browse files
authored
CM-50594 - Add --maven-settings-file SCA option (#324)
1 parent 63d97fe commit a838ebd

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

cycode/cli/apps/scan/scan_command.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ def scan_command(
8888
rich_help_panel=_SCA_RICH_HELP_PANEL,
8989
),
9090
] = False,
91+
maven_settings_file: Annotated[
92+
Optional[Path],
93+
typer.Option(
94+
'--maven-settings-file',
95+
show_default=False,
96+
help='When specified, Cycode will use this settings.xml file when building the maven dependency tree.',
97+
dir_okay=False,
98+
rich_help_panel=_SCA_RICH_HELP_PANEL,
99+
),
100+
] = None,
91101
export_type: Annotated[
92102
ExportTypeOption,
93103
typer.Option(
@@ -143,6 +153,7 @@ def scan_command(
143153
ctx.obj['sync'] = sync
144154
ctx.obj['severity_threshold'] = severity_threshold
145155
ctx.obj['monitor'] = monitor
156+
ctx.obj['maven_settings_file'] = maven_settings_file
146157
ctx.obj['report'] = report
147158

148159
scan_client = get_scan_cycode_client(ctx)

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ def is_project(self, document: Document) -> bool:
2424
return path.basename(document.path).split('/')[-1] == BUILD_MAVEN_FILE_NAME
2525

2626
def get_commands(self, manifest_file_path: str) -> list[list[str]]:
27-
return [['mvn', 'org.cyclonedx:cyclonedx-maven-plugin:2.7.4:makeAggregateBom', '-f', manifest_file_path]]
27+
command = ['mvn', 'org.cyclonedx:cyclonedx-maven-plugin:2.7.4:makeAggregateBom', '-f', manifest_file_path]
28+
29+
maven_settings_file = self.ctx.obj.get('maven_settings_file')
30+
if maven_settings_file:
31+
command += ['-s', str(maven_settings_file)]
32+
return [command]
2833

2934
def get_lock_file_name(self) -> str:
3035
return join_paths('target', MAVEN_CYCLONE_DEP_TREE_FILE_NAME)
@@ -46,7 +51,7 @@ def try_restore_dependencies(self, document: Document) -> Optional[Document]:
4651

4752
def restore_from_secondary_command(self, document: Document, manifest_file_path: str) -> Optional[Document]:
4853
restore_content = execute_commands(
49-
commands=create_secondary_restore_commands(manifest_file_path),
54+
commands=self.create_secondary_restore_commands(manifest_file_path),
5055
timeout=self.command_timeout,
5156
working_directory=self.get_working_directory(document),
5257
)
@@ -61,10 +66,8 @@ def restore_from_secondary_command(self, document: Document, manifest_file_path:
6166
absolute_path=restore_file_path,
6267
)
6368

64-
65-
def create_secondary_restore_commands(manifest_file_path: str) -> list[list[str]]:
66-
return [
67-
[
69+
def create_secondary_restore_commands(self, manifest_file_path: str) -> list[list[str]]:
70+
command = [
6871
'mvn',
6972
'dependency:tree',
7073
'-B',
@@ -73,4 +76,9 @@ def create_secondary_restore_commands(manifest_file_path: str) -> list[list[str]
7376
manifest_file_path,
7477
f'-DoutputFile={MAVEN_DEP_TREE_FILE_NAME}',
7578
]
76-
]
79+
80+
maven_settings_file = self.ctx.obj.get('maven_settings_file')
81+
if maven_settings_file:
82+
command += ['-s', str(maven_settings_file)]
83+
84+
return [command]

0 commit comments

Comments
 (0)