Skip to content

Commit bb1d846

Browse files
committed
Add consolidate_other_copyright
* Use proper test data as it appears in the real world * Reorder attributes on Consolidation * Update comments Signed-off-by: Jono Yang <jyang@nexb.com>
1 parent f418d1b commit bb1d846

36 files changed

Lines changed: 512 additions & 298 deletions

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ class Consolidation(object):
7575
# TODO: Add file counts for proper accounting
7676
identifier = attr.ib(default=None)
7777
core_license_expression = attr.ib(default=None)
78-
core_holders = attr.ib(default=attr.Factory(list))
79-
consolidated_copyright = attr.ib(default=None)
8078
other_license_expression = attr.ib(default=None)
79+
consolidated_core_copyright = attr.ib(default=None)
80+
consolidated_other_copyright = attr.ib(default=None)
81+
core_holders = attr.ib(default=attr.Factory(list))
8182
other_holders = attr.ib(default=attr.Factory(list))
8283
resources = attr.ib(default=attr.Factory(list))
8384

@@ -86,15 +87,22 @@ def dict_fields(attr, value):
8687
if attr.name in ('resources', ):
8788
return False
8889
return True
89-
self.consolidated_copyright = self.consolidate_copyright()
90+
self.consolidated_core_copyright = self.consolidate_core_copyright()
91+
self.consolidated_other_copyright = self.consolidate_other_copyright()
9092
return attr.asdict(self, filter=dict_fields, dict_factory=OrderedDict)
9193

92-
def consolidate_copyright(self):
94+
def consolidate_core_copyright(self):
9395
# TODO: Verify and test that we are generating detectable copyrights
9496
holders = list(self.core_holders) + list(self.other_holders)
9597
if holders:
9698
return 'Copyright (c) {}'.format(', '.join(holders))
9799

100+
def consolidate_other_copyright(self):
101+
# TODO: Verify and test that we are generating detectable copyrights
102+
other_holders = list(self.other_holders)
103+
if other_holders:
104+
return 'Copyright (c) {}'.format(', '.join(other_holders))
105+
98106

99107
@attr.s
100108
class ConsolidatedComponent(object):
@@ -250,11 +258,11 @@ def get_consolidated_packages(codebase):
250258
simplified_discovered_license_expression = None
251259

252260
c = Consolidation(
253-
resources=package_resources,
254261
core_license_expression=package_license_expression,
255-
core_holders=sorted(set(package_holders)),
256262
other_license_expression=simplified_discovered_license_expression,
257-
other_holders=sorted(set(discovered_holders))
263+
core_holders=sorted(set(package_holders)),
264+
other_holders=sorted(set(discovered_holders)),
265+
resources=package_resources,
258266
)
259267
yield ConsolidatedPackage(
260268
package=package,
@@ -365,9 +373,9 @@ def create_license_holders_consolidated_component(resource, codebase):
365373
component_resources = get_consolidated_component_resources(resource, codebase)
366374
if component_resources:
367375
c = Consolidation(
368-
resources=component_resources,
369376
core_license_expression=license_expression,
370-
core_holders=holders
377+
core_holders=holders,
378+
resources=component_resources,
371379
)
372380
return ConsolidatedComponent(
373381
type='license-holders',
@@ -417,9 +425,9 @@ def combine_license_holders_consolidated_components(components):
417425
component_resources.extend(component.consolidation.resources)
418426
component_holders, component_license_expression = origin_translation_table[origin_key]
419427
c = Consolidation(
420-
resources=component_resources,
421428
core_license_expression=component_license_expression,
422-
core_holders=component_holders
429+
core_holders=component_holders,
430+
resources=component_resources,
423431
)
424432
yield ConsolidatedComponent(
425433
type='license-holders',

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

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
"type": "license-holders",
2525
"identifier": "the_apache_software_foundation_1",
2626
"core_license_expression": "apache-2.0",
27+
"other_license_expression": null,
28+
"consolidated_core_copyright": "Copyright (c) The Apache Software Foundation",
29+
"consolidated_other_copyright": null,
2730
"core_holders": [
28-
"the apache software foundation"
31+
"The Apache Software Foundation"
2932
],
30-
"consolidated_copyright": "Copyright (c) the apache software foundation",
31-
"other_license_expression": null,
3233
"other_holders": []
3334
}
3435
],
@@ -63,7 +64,7 @@
6364
],
6465
"files_count": 4,
6566
"dirs_count": 0,
66-
"size_count": 177,
67+
"size_count": 200,
6768
"scan_errors": []
6869
},
6970
{
@@ -72,9 +73,9 @@
7273
"name": "src1",
7374
"base_name": "src1",
7475
"extension": "",
75-
"size": 52,
76-
"sha1": "c3205a52b29c4d6a8b9d30acfbf8190aecd41492",
77-
"md5": "40e0b73c327d10cb3f42e23d300380b0",
76+
"size": 56,
77+
"sha1": "f3eae084a5690638fd1ada38e653a94179f14263",
78+
"md5": "7e0e8162de50e718e248ccd7a2d2cb65",
7879
"mime_type": "text/plain",
7980
"file_type": "ASCII text",
8081
"programming_language": null,
@@ -123,14 +124,14 @@
123124
],
124125
"holders": [
125126
{
126-
"value": "the apache software foundation",
127+
"value": "The Apache Software Foundation",
127128
"start_line": 1,
128129
"end_line": 2
129130
}
130131
],
131132
"copyrights": [
132133
{
133-
"value": "copyright the apache software foundation",
134+
"value": "Copyright (c) The Apache Software Foundation",
134135
"start_line": 1,
135136
"end_line": 2
136137
}
@@ -151,9 +152,9 @@
151152
"name": "src2",
152153
"base_name": "src2",
153154
"extension": "",
154-
"size": 52,
155-
"sha1": "c3205a52b29c4d6a8b9d30acfbf8190aecd41492",
156-
"md5": "40e0b73c327d10cb3f42e23d300380b0",
155+
"size": 56,
156+
"sha1": "f3eae084a5690638fd1ada38e653a94179f14263",
157+
"md5": "7e0e8162de50e718e248ccd7a2d2cb65",
157158
"mime_type": "text/plain",
158159
"file_type": "ASCII text",
159160
"programming_language": null,
@@ -202,14 +203,14 @@
202203
],
203204
"holders": [
204205
{
205-
"value": "the apache software foundation",
206+
"value": "The Apache Software Foundation",
206207
"start_line": 1,
207208
"end_line": 2
208209
}
209210
],
210211
"copyrights": [
211212
{
212-
"value": "copyright the apache software foundation",
213+
"value": "Copyright (c) The Apache Software Foundation",
213214
"start_line": 1,
214215
"end_line": 2
215216
}
@@ -230,9 +231,9 @@
230231
"name": "src3",
231232
"base_name": "src3",
232233
"extension": "",
233-
"size": 52,
234-
"sha1": "c3205a52b29c4d6a8b9d30acfbf8190aecd41492",
235-
"md5": "40e0b73c327d10cb3f42e23d300380b0",
234+
"size": 56,
235+
"sha1": "f3eae084a5690638fd1ada38e653a94179f14263",
236+
"md5": "7e0e8162de50e718e248ccd7a2d2cb65",
236237
"mime_type": "text/plain",
237238
"file_type": "ASCII text",
238239
"programming_language": null,
@@ -281,14 +282,14 @@
281282
],
282283
"holders": [
283284
{
284-
"value": "the apache software foundation",
285+
"value": "The Apache Software Foundation",
285286
"start_line": 1,
286287
"end_line": 2
287288
}
288289
],
289290
"copyrights": [
290291
{
291-
"value": "copyright the apache software foundation",
292+
"value": "Copyright (c) The Apache Software Foundation",
292293
"start_line": 1,
293294
"end_line": 2
294295
}
@@ -309,9 +310,9 @@
309310
"name": "src4",
310311
"base_name": "src4",
311312
"extension": "",
312-
"size": 21,
313-
"sha1": "4db983fe0ab8117f9b74c50a8a7f3a045ae57284",
314-
"md5": "0aa9f7cb419649708faee0d981acbf47",
313+
"size": 32,
314+
"sha1": "9d75736fe41651abebb509da45380299d93fbafd",
315+
"md5": "55abb8def9f0ecedeca243349fbb9b62",
315316
"mime_type": "text/plain",
316317
"file_type": "ASCII text",
317318
"programming_language": null,
@@ -321,18 +322,53 @@
321322
"is_media": false,
322323
"is_source": false,
323324
"is_script": false,
324-
"licenses": [],
325-
"license_expressions": [],
325+
"licenses": [
326+
{
327+
"key": "gpl-2.0",
328+
"score": 80.0,
329+
"name": "GNU General Public License 2.0",
330+
"short_name": "GPL 2.0",
331+
"category": "Copyleft",
332+
"is_exception": false,
333+
"owner": "Free Software Foundation (FSF)",
334+
"homepage_url": "http://www.gnu.org/licenses/gpl-2.0.html",
335+
"text_url": "http://www.gnu.org/licenses/gpl-2.0.txt",
336+
"reference_url": "https://enterprise.dejacode.com/urn/urn:dje:license:gpl-2.0",
337+
"spdx_license_key": "GPL-2.0-only",
338+
"spdx_url": "https://spdx.org/licenses/GPL-2.0-only",
339+
"start_line": 2,
340+
"end_line": 2,
341+
"matched_rule": {
342+
"identifier": "gpl-2.0_52.RULE",
343+
"license_expression": "gpl-2.0",
344+
"licenses": [
345+
"gpl-2.0"
346+
],
347+
"is_license_text": false,
348+
"is_license_notice": false,
349+
"is_license_reference": true,
350+
"is_license_tag": false,
351+
"matcher": "2-aho",
352+
"rule_length": 3,
353+
"matched_length": 3,
354+
"match_coverage": 100.0,
355+
"rule_relevance": 80.0
356+
}
357+
}
358+
],
359+
"license_expressions": [
360+
"gpl-2.0"
361+
],
326362
"holders": [
327363
{
328-
"value": "me inc",
364+
"value": "IBM Corp.",
329365
"start_line": 1,
330366
"end_line": 2
331367
}
332368
],
333369
"copyrights": [
334370
{
335-
"value": "copyright me inc",
371+
"value": "Copyright (c) IBM Corp.",
336372
"start_line": 1,
337373
"end_line": 2
338374
}

0 commit comments

Comments
 (0)