Skip to content

Commit 31074d2

Browse files
committed
Change license holder consolidation logic
* If we are in a directory with no majority, we check the child directories if they have any majorities and return those * This prevents us from reported the same majority thing as we come up the codebase * Update tests Signed-off-by: Jono Yang <jyang@nexb.com>
1 parent a9cf4d2 commit 31074d2

9 files changed

Lines changed: 623 additions & 77 deletions

File tree

plugins/scancode-consolidate-scan/src/plugin_consolidate/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,16 @@ def get_license_holders_consolidated_components(codebase):
319319
resource.extra_data['origin_summary_holders'] = majority_holders
320320
resource.extra_data['origin_summary_count'] = top_count
321321
resource.save(codebase)
322-
323-
c = create_license_holders_consolidated_component(resource, codebase)
324-
if c:
325-
yield c
326-
327-
# TODO: stop if you have a majority but the parent doesnt have it
322+
else:
323+
# If there is no majority, we see if any of our child directories had majorities
324+
for child in children:
325+
if not (child.extra_data.get('origin_summary_license_expression')
326+
and child.extra_data.get('origin_summary_holders')
327+
and child.extra_data.get('origin_summary_count')):
328+
continue
329+
c = create_license_holders_consolidated_component(child, codebase)
330+
if c:
331+
yield c
328332

329333
# Yield a Component for root if there is a majority
330334
c = create_license_holders_consolidated_component(root, codebase)

plugins/scancode-consolidate-scan/tests/data/plugin_consolidate/clear-summary-expected.json

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,6 @@
3030
"consolidated_copyright": "Copyright (c) the apache software foundation",
3131
"other_license_expression": null,
3232
"other_holders": []
33-
},
34-
{
35-
"type": "license-holders",
36-
"identifier": "the_apache_software_foundation_2",
37-
"core_license_expression": "apache-2.0",
38-
"core_holders": [
39-
"the apache software foundation"
40-
],
41-
"consolidated_copyright": "Copyright (c) the apache software foundation",
42-
"other_license_expression": null,
43-
"other_holders": []
4433
}
4534
],
4635
"consolidated_packages": [],
@@ -70,8 +59,7 @@
7059
"authors": [],
7160
"packages": [],
7261
"consolidated_to": [
73-
"the_apache_software_foundation_1",
74-
"the_apache_software_foundation_2"
62+
"the_apache_software_foundation_1"
7563
],
7664
"files_count": 4,
7765
"dirs_count": 0,
@@ -150,8 +138,7 @@
150138
"authors": [],
151139
"packages": [],
152140
"consolidated_to": [
153-
"the_apache_software_foundation_1",
154-
"the_apache_software_foundation_2"
141+
"the_apache_software_foundation_1"
155142
],
156143
"files_count": 0,
157144
"dirs_count": 0,
@@ -230,8 +217,7 @@
230217
"authors": [],
231218
"packages": [],
232219
"consolidated_to": [
233-
"the_apache_software_foundation_1",
234-
"the_apache_software_foundation_2"
220+
"the_apache_software_foundation_1"
235221
],
236222
"files_count": 0,
237223
"dirs_count": 0,
@@ -310,8 +296,7 @@
310296
"authors": [],
311297
"packages": [],
312298
"consolidated_to": [
313-
"the_apache_software_foundation_1",
314-
"the_apache_software_foundation_2"
299+
"the_apache_software_foundation_1"
315300
],
316301
"files_count": 0,
317302
"dirs_count": 0,

plugins/scancode-consolidate-scan/tests/data/plugin_consolidate/component-package-expected.json

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
{
44
"tool_name": "scancode-toolkit",
55
"options": {
6-
"input": [
7-
"plugins/scancode-consolidate-scan/tests/data/plugin_consolidate/component-package/"
8-
],
6+
"input": "<path>",
7+
"--consolidate": true,
98
"--copyright": true,
109
"--info": true,
11-
"--json-pp": "/home/jono/component-package.json",
10+
"--json": "<file>",
1211
"--license": true,
1312
"--package": true
1413
},
@@ -18,23 +17,6 @@
1817
"extra_data": {
1918
"files_count": 7
2019
}
21-
},
22-
{
23-
"tool_name": "scancode-toolkit",
24-
"options": {
25-
"input": "<path>",
26-
"--consolidate": true,
27-
"--from-json": [
28-
true
29-
],
30-
"--json": "<file>"
31-
},
32-
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
33-
"message": null,
34-
"errors": [],
35-
"extra_data": {
36-
"files_count": 7
37-
}
3820
}
3921
],
4022
"consolidated_components": [

0 commit comments

Comments
 (0)