2424from licensedcode .detection import get_detected_license_expression
2525from licensedcode .detection import get_matches_from_detection_mappings
2626from licensedcode .detection import get_referenced_filenames
27- from licensedcode .detection import SCANCODE_LICENSEDB_URL
2827from licensedcode .detection import LicenseDetection
2928from licensedcode .detection import group_matches
3029from licensedcode .detection import process_detections
3130from licensedcode .detection import DetectionCategory
3231from licensedcode .detection import detections_from_license_detection_mappings
3332from licensedcode .detection import matches_from_license_match_mappings
3433from licensedcode .detection import UniqueDetection
34+ from licensedcode .detection import LicenseDetectionFromResult
35+ from licensedcode .licenses_reference import populate_license_references
3536from packagedcode .utils import combine_expressions
3637from scancode .api import SCANCODE_LICENSEDB_URL
3738
@@ -64,11 +65,13 @@ class LicenseScanner(ScanPlugin):
6465 ('license_detections' , attr .ib (default = attr .Factory (list ))),
6566 ('license_clues' , attr .ib (default = attr .Factory (list ))),
6667 ('percentage_of_license_text' , attr .ib (default = 0 )),
67- ('for_licenses ' , attr .ib (default = attr .Factory (list ))),
68+ ('for_license_detections ' , attr .ib (default = attr .Factory (list ))),
6869 ])
6970
7071 codebase_attributes = dict (
71- licenses = attr .ib (default = attr .Factory (list )),
72+ license_detections = attr .ib (default = attr .Factory (list )),
73+ license_references = attr .ib (default = attr .Factory (list )),
74+ license_rule_references = attr .ib (default = attr .Factory (list ))
7275 )
7376
7477 sort_order = 2
@@ -209,28 +212,30 @@ def process_codebase(self, codebase, **kwargs):
209212 f'after : { license_expressions_after } '
210213 )
211214
212- populate_for_licenses_in_resources (
215+ populate_for_license_detections_in_resources (
213216 codebase = codebase ,
214217 detections = unique_license_detections ,
215218 )
216- codebase .attributes .licenses .extend ([
219+ codebase .attributes .license_detections .extend ([
217220 unique_detection .to_dict ()
218221 for unique_detection in unique_license_detections
219222 ])
220223
224+ populate_license_references (codebase )
221225
222- def populate_for_licenses_in_resources (codebase , detections ):
226+
227+ def populate_for_license_detections_in_resources (codebase , detections ):
223228
224229 for detection in detections :
225230 if TRACE :
226231 logger_debug (
227- f'populate_for_licenses_in_resources :' ,
232+ f'populate_for_license_detections_in_resources :' ,
228233 f'for detection: { detection .license_expression } \n ' ,
229234 f'file paths: { detection .files } ' ,
230235 )
231236 for file_region in detection .files :
232237 resource = codebase .get_resource (path = file_region .path )
233- resource .for_licenses .append (detection .identifier )
238+ resource .for_license_detections .append (detection .identifier )
234239
235240
236241def collect_license_detections (codebase ):
@@ -243,7 +248,7 @@ def collect_license_detections(codebase):
243248
244249 if hasattr (codebase .root , 'license_detections' ):
245250 has_licenses = True
246-
251+
247252 all_license_detections = []
248253
249254 for resource in codebase .walk ():
@@ -346,16 +351,22 @@ def add_referenced_license_matches_for_detections(resource, codebase):
346351 if not resource .is_file :
347352 return
348353
349- license_detections = resource .license_detections
350- if not license_detections :
354+ license_detection_mappings = resource .license_detections
355+ if not license_detection_mappings :
351356 return
352357
353358 modified = False
354359
355- for detection in license_detections :
360+ for license_detection_mapping in license_detection_mappings :
361+
362+ license_detection_object = LicenseDetectionFromResult .from_license_detection_mapping (
363+ license_detection_mapping = license_detection_mapping ,
364+ file_path = resource .path ,
365+ )
356366 detection_modified = False
357- matches = detection ["matches" ]
358- referenced_filenames = get_referenced_filenames (matches )
367+ license_match_mappings = license_detection_mapping ["matches" ]
368+ referenced_filenames = get_referenced_filenames (license_detection_object .matches )
369+
359370 if not referenced_filenames :
360371 continue
361372
@@ -369,7 +380,7 @@ def add_referenced_license_matches_for_detections(resource, codebase):
369380 if referenced_resource and referenced_resource .license_detections :
370381 modified = True
371382 detection_modified = True
372- matches .extend (
383+ license_match_mappings .extend (
373384 get_matches_from_detection_mappings (
374385 license_detections = referenced_resource .license_detections
375386 )
@@ -379,12 +390,12 @@ def add_referenced_license_matches_for_detections(resource, codebase):
379390 continue
380391
381392 detection_log , license_expression = get_detected_license_expression (
382- matches = matches ,
393+ license_match_mappings = license_match_mappings ,
383394 analysis = DetectionCategory .UNKNOWN_FILE_REFERENCE_LOCAL .value ,
384395 post_scan = True ,
385396 )
386- detection ["license_expression" ] = str (license_expression )
387- detection ["detection_log" ] = detection_log
397+ license_detection_mapping ["license_expression" ] = str (license_expression )
398+ license_detection_mapping ["detection_log" ] = detection_log
388399
389400 if modified :
390401 license_expressions = [
0 commit comments