Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions scanpipe/pipelines/load_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,15 @@ def steps(cls):

def get_scan_json_input(self):
"""
Locates a JSON scan input from a project's input/ directory.
Locates all the ScanCode JSON scan inputs from a project's input/
directory. This includes all files with a .json extension.
"""
inputs = list(self.project.inputs(pattern="*.json"))
if len(inputs) != 1:
raise Exception("Only 1 JSON input file supported")
self.input_location = str(inputs[0].absolute())
self.input_locations = [str(i.absolute()) for i in inputs]

def build_inventory_from_scan(self):
"""
Processes a given JSON scan input to populate codebase resources and packages.
Processes JSON scan inputs to populate codebase resources and packages.
"""
project = self.project
scanned_codebase = scancode.get_virtual_codebase(project, self.input_location)
scancode.create_codebase_resources(project, scanned_codebase)
scancode.create_discovered_packages(project, scanned_codebase)
for input_location in self.input_locations:
scancode.load_inventory_from_scan(self.project, input_location)
5 changes: 1 addition & 4 deletions scanpipe/pipelines/scan_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ def build_inventory_from_scan(self):
"""
Processes the JSON scan results to determine resources and packages.
"""
project = self.project
scanned_codebase = scancode.get_virtual_codebase(project, str(self.scan_output))
scancode.create_codebase_resources(project, scanned_codebase)
scancode.create_discovered_packages(project, scanned_codebase)
scancode.load_inventory_from_scan(self.project, str(self.scan_output))

def make_summary_from_scan_results(self):
"""
Expand Down
10 changes: 10 additions & 0 deletions scanpipe/pipes/scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,13 @@ def make_results_summary(project, scan_results_location):
summary["key_files_packages"] = key_files_packages

return summary


def load_inventory_from_scan(project, input_location):
"""
Processes a given JSON scan input at ``input_location`` to populate codebase
resources and packages in ``project``.
"""
scanned_codebase = get_virtual_codebase(project, input_location)
create_codebase_resources(project, scanned_codebase)
create_discovered_packages(project, scanned_codebase)
4 changes: 2 additions & 2 deletions scanpipe/tests/test_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ def test_scanpipe_scan_package_pipeline_integration_test(self):
run = project1.add_pipeline(pipeline_name)
pipeline = run.make_pipeline_instance()

exitcode, _ = pipeline.execute()
self.assertEqual(0, exitcode)
exitcode, output = pipeline.execute()
self.assertEqual(0, exitcode, msg=output)

self.assertEqual(4, project1.codebaseresources.count())
self.assertEqual(1, project1.discoveredpackages.count())
Expand Down