66import logging
77import os
88import json
9- from fosslight_util .constant import LOGGER_NAME
9+ from fosslight_util .constant import LOGGER_NAME , FOSSLIGHT_DEPENDENCY
1010from fosslight_util .oss_item import ScannerItem
1111from typing import List
1212
@@ -20,22 +20,27 @@ def write_scancodejson(output_dir: str, output_filename: str, oss_list: List[Sca
2020 json_output ['summary' ] = {}
2121 json_output ['license_detections' ] = []
2222 json_output ['files' ] = []
23+ json_output ['dependencies' ] = []
2324
24- for file_items in oss_list .file_items .values ():
25+ for scanner , file_items in oss_list .file_items .items ():
2526 for fi in file_items :
26- if fi .exclude :
27- continue
28- if fi .oss_items and (all (oss_item .exclude for oss_item in fi .oss_items )):
29- continue
30- if not fi .source_name_or_path :
31- fi .source_name_or_path = EMPTY_FILE_PATH
32- json_output ['files' ] = add_item_in_files (fi , json_output ['files' ])
27+ if scanner == FOSSLIGHT_DEPENDENCY :
28+ json_output ['dependencies' ] = add_item_in_deps (fi , json_output ['dependencies' ])
29+ else :
30+ if fi .exclude :
31+ continue
32+ if fi .oss_items and (all (oss_item .exclude for oss_item in fi .oss_items )):
33+ continue
34+ if not fi .source_name_or_path :
35+ fi .source_name_or_path = EMPTY_FILE_PATH
36+ json_output ['files' ] = add_item_in_files (fi , json_output ['files' ])
3337
3438 with open (os .path .join (output_dir , output_filename ), 'w' ) as f :
3539 json .dump (json_output , f , sort_keys = False , indent = 4 )
3640
3741
38- def append_oss_item_in_filesitem (oss_items , files_item ):
42+ def get_oss_item_list (oss_items ):
43+ scan_oss_items = []
3944 for oi in oss_items :
4045 if oi .exclude :
4146 continue
@@ -46,9 +51,9 @@ def append_oss_item_in_filesitem(oss_items, files_item):
4651 oss_item ['copyright' ] = oi .copyright
4752 oss_item ['download_location' ] = oi .download_location
4853 oss_item ['comment' ] = oi .comment
49- files_item [ 'oss' ] .append (oss_item )
54+ scan_oss_items .append (oss_item )
5055
51- return files_item
56+ return scan_oss_items
5257
5358
5459def add_item_in_files (file_item , files_list ):
@@ -57,8 +62,20 @@ def add_item_in_files(file_item, files_list):
5762 files_item ['name' ] = os .path .basename (file_item .source_name_or_path )
5863 files_item ['is_binary' ] = file_item .is_binary
5964 files_item ['base_name' ], files_item ['extension' ] = os .path .splitext (os .path .basename (file_item .source_name_or_path ))
60- files_item ['oss' ] = []
61- files_item = append_oss_item_in_filesitem ( file_item . oss_items , files_item )
65+ files_item ['oss' ] = get_oss_item_list ( file_item . oss_items )
66+
6267 files_list .append (files_item )
6368
6469 return files_list
70+
71+
72+ def add_item_in_deps (file_item , deps_list ):
73+ deps_item = {}
74+ deps_item ['purl' ] = file_item .purl
75+ deps_item ['scope' ] = 'dependencies'
76+ deps_item ['depends_on' ] = file_item .depends_on
77+ deps_item ['oss' ] = get_oss_item_list (file_item .oss_items )
78+
79+ deps_list .append (deps_item )
80+
81+ return deps_list
0 commit comments