24
24
from licensedcode .detection import get_detected_license_expression
25
25
from licensedcode .detection import get_matches_from_detection_mappings
26
26
from licensedcode .detection import get_referenced_filenames
27
- from licensedcode .detection import SCANCODE_LICENSEDB_URL
28
27
from licensedcode .detection import LicenseDetection
29
28
from licensedcode .detection import group_matches
30
29
from licensedcode .detection import process_detections
31
30
from licensedcode .detection import DetectionCategory
32
31
from licensedcode .detection import detections_from_license_detection_mappings
33
32
from licensedcode .detection import matches_from_license_match_mappings
34
33
from licensedcode .detection import UniqueDetection
34
+ from licensedcode .detection import LicenseDetectionFromResult
35
+ from licensedcode .licenses_reference import populate_license_references
35
36
from packagedcode .utils import combine_expressions
36
37
from scancode .api import SCANCODE_LICENSEDB_URL
37
38
@@ -64,11 +65,13 @@ class LicenseScanner(ScanPlugin):
64
65
('license_detections' , attr .ib (default = attr .Factory (list ))),
65
66
('license_clues' , attr .ib (default = attr .Factory (list ))),
66
67
('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 ))),
68
69
])
69
70
70
71
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 ))
72
75
)
73
76
74
77
sort_order = 2
@@ -209,28 +212,30 @@ def process_codebase(self, codebase, **kwargs):
209
212
f'after : { license_expressions_after } '
210
213
)
211
214
212
- populate_for_licenses_in_resources (
215
+ populate_for_license_detections_in_resources (
213
216
codebase = codebase ,
214
217
detections = unique_license_detections ,
215
218
)
216
- codebase .attributes .licenses .extend ([
219
+ codebase .attributes .license_detections .extend ([
217
220
unique_detection .to_dict ()
218
221
for unique_detection in unique_license_detections
219
222
])
220
223
224
+ populate_license_references (codebase )
221
225
222
- def populate_for_licenses_in_resources (codebase , detections ):
226
+
227
+ def populate_for_license_detections_in_resources (codebase , detections ):
223
228
224
229
for detection in detections :
225
230
if TRACE :
226
231
logger_debug (
227
- f'populate_for_licenses_in_resources :' ,
232
+ f'populate_for_license_detections_in_resources :' ,
228
233
f'for detection: { detection .license_expression } \n ' ,
229
234
f'file paths: { detection .files } ' ,
230
235
)
231
236
for file_region in detection .files :
232
237
resource = codebase .get_resource (path = file_region .path )
233
- resource .for_licenses .append (detection .identifier )
238
+ resource .for_license_detections .append (detection .identifier )
234
239
235
240
236
241
def collect_license_detections (codebase ):
@@ -243,7 +248,7 @@ def collect_license_detections(codebase):
243
248
244
249
if hasattr (codebase .root , 'license_detections' ):
245
250
has_licenses = True
246
-
251
+
247
252
all_license_detections = []
248
253
249
254
for resource in codebase .walk ():
@@ -346,16 +351,22 @@ def add_referenced_license_matches_for_detections(resource, codebase):
346
351
if not resource .is_file :
347
352
return
348
353
349
- license_detections = resource .license_detections
350
- if not license_detections :
354
+ license_detection_mappings = resource .license_detections
355
+ if not license_detection_mappings :
351
356
return
352
357
353
358
modified = False
354
359
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
+ )
356
366
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
+
359
370
if not referenced_filenames :
360
371
continue
361
372
@@ -369,7 +380,7 @@ def add_referenced_license_matches_for_detections(resource, codebase):
369
380
if referenced_resource and referenced_resource .license_detections :
370
381
modified = True
371
382
detection_modified = True
372
- matches .extend (
383
+ license_match_mappings .extend (
373
384
get_matches_from_detection_mappings (
374
385
license_detections = referenced_resource .license_detections
375
386
)
@@ -379,12 +390,12 @@ def add_referenced_license_matches_for_detections(resource, codebase):
379
390
continue
380
391
381
392
detection_log , license_expression = get_detected_license_expression (
382
- matches = matches ,
393
+ license_match_mappings = license_match_mappings ,
383
394
analysis = DetectionCategory .UNKNOWN_FILE_REFERENCE_LOCAL .value ,
384
395
post_scan = True ,
385
396
)
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
388
399
389
400
if modified :
390
401
license_expressions = [
0 commit comments