Skip to content

Commit 3281578

Browse files
committed
added --maven-settings-file parameter
1 parent 63d97fe commit 3281578

2 files changed

Lines changed: 35 additions & 14 deletions

File tree

cycode/cli/apps/scan/scan_command.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,17 @@ 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 '
97+
'when building the maven dependency tree.',
98+
dir_okay=False,
99+
rich_help_panel=_SCA_RICH_HELP_PANEL,
100+
),
101+
] = None,
91102
export_type: Annotated[
92103
ExportTypeOption,
93104
typer.Option(
@@ -143,6 +154,7 @@ def scan_command(
143154
ctx.obj['sync'] = sync
144155
ctx.obj['severity_threshold'] = severity_threshold
145156
ctx.obj['monitor'] = monitor
157+
ctx.obj['maven_settings_file'] = maven_settings_file
146158
ctx.obj['report'] = report
147159

148160
scan_client = get_scan_cycode_client(ctx)

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

Lines changed: 23 additions & 14 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
)
@@ -62,15 +67,19 @@ def restore_from_secondary_command(self, document: Document, manifest_file_path:
6267
)
6368

6469

65-
def create_secondary_restore_commands(manifest_file_path: str) -> list[list[str]]:
66-
return [
67-
[
68-
'mvn',
69-
'dependency:tree',
70-
'-B',
71-
'-DoutputType=text',
72-
'-f',
73-
manifest_file_path,
74-
f'-DoutputFile={MAVEN_DEP_TREE_FILE_NAME}',
75-
]
76-
]
70+
def create_secondary_restore_commands(self,manifest_file_path: str) -> list[list[str]]:
71+
command = [
72+
'mvn',
73+
'dependency:tree',
74+
'-B',
75+
'-DoutputType=text',
76+
'-f',
77+
manifest_file_path,
78+
f'-DoutputFile={MAVEN_DEP_TREE_FILE_NAME}',
79+
]
80+
81+
maven_settings_file = self.ctx.obj.get('maven_settings_file')
82+
if maven_settings_file:
83+
command += ['-s', str(maven_settings_file)]
84+
85+
return [command]

0 commit comments

Comments
 (0)