@@ -138,7 +138,9 @@ def __init__(self, resources_path: str, file_name: str, tool_name: str, tool_ver
138
138
self .visited_deps : set = set ()
139
139
140
140
@abstractmethod
141
- def collect_dependencies (self , dir_path : str , target_component : Component ) -> dict [str , DependencyInfo ]:
141
+ def collect_dependencies (
142
+ self , dir_path : str , target_component : Component , recursive : bool = False
143
+ ) -> dict [str , DependencyInfo ]:
142
144
"""Process the dependency JSON files and collect direct dependencies.
143
145
144
146
Parameters
@@ -147,6 +149,8 @@ def collect_dependencies(self, dir_path: str, target_component: Component) -> di
147
149
Local path to the target repo.
148
150
target_component: Component
149
151
The analyzed target software component.
152
+ recursive: bool
153
+ Set to False to get the direct dependencies only (default).
150
154
151
155
Returns
152
156
-------
@@ -349,14 +353,16 @@ def tool_valid(tool: str) -> bool:
349
353
return True
350
354
351
355
@staticmethod
352
- def resolve_dependencies (main_ctx : Any , sbom_path : str ) -> dict [str , DependencyInfo ]:
356
+ def resolve_dependencies (main_ctx : Any , sbom_path : str , recursive : bool = False ) -> dict [str , DependencyInfo ]:
353
357
"""Resolve the dependencies of the main target repo.
354
358
355
359
Parameters
356
360
----------
357
361
main_ctx : Any (AnalyzeContext)
358
362
The context of object of the target repository.
359
- sbom_path: str
363
+ recursive : bool
364
+ If True, perform transitive dependency resolution. Default: False.
365
+ sbom_path : str
360
366
The path to the SBOM.
361
367
362
368
Returns
@@ -397,7 +403,11 @@ def resolve_dependencies(main_ctx: Any, sbom_path: str) -> dict[str, DependencyI
397
403
if sbom_path :
398
404
logger .info ("Getting the dependencies from the SBOM defined at %s." , sbom_path )
399
405
400
- deps_resolved = dep_analyzer .get_deps_from_sbom (sbom_path , main_ctx .component )
406
+ deps_resolved = dep_analyzer .get_deps_from_sbom (
407
+ sbom_path ,
408
+ main_ctx .component ,
409
+ recursive = recursive ,
410
+ )
401
411
402
412
# Use repo finder to find more repositories to analyze.
403
413
if defaults .getboolean ("repofinder" , "find_repos" ):
@@ -456,7 +466,11 @@ def resolve_dependencies(main_ctx: Any, sbom_path: str) -> dict[str, DependencyI
456
466
457
467
# We collect the generated SBOM as a best effort, even if the build exits with errors.
458
468
# TODO: add improvements to help the SBOM build succeed as much as possible.
459
- deps_resolved |= dep_analyzer .collect_dependencies (str (working_dir ), main_ctx .component )
469
+ deps_resolved |= dep_analyzer .collect_dependencies (
470
+ str (working_dir ),
471
+ main_ctx .component ,
472
+ recursive = recursive ,
473
+ )
460
474
461
475
logger .info ("Stored dependency resolver log for %s to %s." , dep_analyzer .tool_name , log_path )
462
476
@@ -719,7 +733,9 @@ def convert_components_to_artifacts(
719
733
720
734
return latest_deps
721
735
722
- def get_deps_from_sbom (self , sbom_path : str | Path , target_component : Component ) -> dict [str , DependencyInfo ]:
736
+ def get_deps_from_sbom (
737
+ self , sbom_path : str | Path , target_component : Component , recursive : bool = False
738
+ ) -> dict [str , DependencyInfo ]:
723
739
"""Get the dependencies from a provided SBOM.
724
740
725
741
Parameters
@@ -728,6 +744,8 @@ def get_deps_from_sbom(self, sbom_path: str | Path, target_component: Component)
728
744
The path to the SBOM file.
729
745
target_component: Component
730
746
The analyzed target software component.
747
+ recursive: bool
748
+ Set to False to get the direct dependencies only (default).
731
749
732
750
Returns
733
751
-------
@@ -737,11 +755,7 @@ def get_deps_from_sbom(self, sbom_path: str | Path, target_component: Component)
737
755
self .get_dep_components (
738
756
target_component = target_component ,
739
757
root_bom_path = Path (sbom_path ),
740
- recursive = defaults .getboolean (
741
- "dependency.resolver" ,
742
- "recursive" ,
743
- fallback = False ,
744
- ),
758
+ recursive = recursive ,
745
759
)
746
760
)
747
761
@@ -753,7 +767,9 @@ def __init__(self) -> None:
753
767
"""Initialize the dependency analyzer instance."""
754
768
super ().__init__ (resources_path = "" , file_name = "" , tool_name = "" , tool_version = "" )
755
769
756
- def collect_dependencies (self , dir_path : str , target_component : Component ) -> dict [str , DependencyInfo ]:
770
+ def collect_dependencies (
771
+ self , dir_path : str , target_component : Component , recursive : bool = False
772
+ ) -> dict [str , DependencyInfo ]:
757
773
"""Process the dependency JSON files and collect direct dependencies.
758
774
759
775
Parameters
@@ -762,6 +778,8 @@ def collect_dependencies(self, dir_path: str, target_component: Component) -> di
762
778
Local path to the target repo.
763
779
target_component: Component
764
780
The analyzed target software component.
781
+ recursive: bool
782
+ Set to False to get the direct dependencies only (default).
765
783
766
784
Returns
767
785
-------
0 commit comments