Skip to content

Commit

Permalink
Update: Add Licenses to packagae_summary test-case & minor refactoring
Browse files Browse the repository at this point in the history
…aboutcode-org#3862

Signed-off-by: swastik <swastkk@gmail.com>
  • Loading branch information
swastkk committed Jul 17, 2024
1 parent fa6ecce commit 0ba0468
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 15 deletions.
12 changes: 7 additions & 5 deletions src/summarycode/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ def compute_license_score(resources, is_codebase=False):
)

# Populating the Package Attributes
packageAttrs= PackageSummaryAttributes()
copyright_values = [copyright.get('copyright') for copyright in copyrights if copyright.get('copyright')]
joined_copyrights = ", ".join(copyright_values) if copyright_values else None

Expand All @@ -194,10 +193,13 @@ def compute_license_score(resources, is_codebase=False):
joined_other_license_expressions = ", ".join(other_license_expressions) if other_license_expressions else ""
if not joined_other_license_expressions:
joined_other_license_expressions = None
packageAttrs.copyright = joined_copyrights
packageAttrs.holder = joined_holders
packageAttrs.notice_text = joined_notice_text
packageAttrs.other_license_expression= joined_other_license_expressions

packageAttrs= PackageSummaryAttributes(
copyright = joined_copyrights,
holder = joined_holders,
notice_text = joined_notice_text,
other_license_expression= joined_other_license_expressions
)

other_license_detections = get_field_values_from_resources(
resources=resources,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright [2024] [Author]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2024 <COPYRIGHT Author>

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Subject to the terms and conditions of this license, each copyright holder and contributor hereby grants to those receiving rights under this license a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except for failure to satisfy the conditions of this license) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer this software, where such license applies only to those patent claims, already acquired or hereafter acquired, licensable by such copyright holder or contributor that are necessarily infringed by:

(a) their Contribution(s) (the licensed copyrights of copyright holders and non-copyrightable additions of contributors, in source or binary form) alone; or

(b) combination of their Contribution(s) with the work of authorship to which such Contribution(s) was added by such copyright holder or contributor, if, at the time the Contribution is added, such addition causes such combination to be necessarily infringed. The patent license shall not apply to any other combinations which include the Contribution.

Except as expressly stated above, no rights or licenses from any copyright holder or contributor is granted under this license, whether expressly, by implication, estoppel or otherwise.

DISCLAIMER

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright [2024] [Author]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
220 changes: 210 additions & 10 deletions tests/packagedcode/data/package_summary/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"bug_tracking_url": "https://github.com/blakeembrey/change-case/issues",
"code_view_url": null,
"vcs_url": "git://github.com/blakeembrey/change-case.git",
"copyright": null,
"holder": null,
"copyright": "Copyright (c) 2014 Blake Embrey (hello@blakeembrey.com)",
"holder": "Blake Embrey",
"declared_license_expression": "mit",
"declared_license_expression_spdx": "MIT",
"license_detections": [
Expand All @@ -68,7 +68,7 @@
"identifier": "mit-a822f434-d61f-f2b1-c792-8b8cb9e7b9bf"
}
],
"other_license_expression": null,
"other_license_expression": "apache-2.0, bsd-plus-patent",
"other_license_expression_spdx": null,
"other_license_detections": [],
"extracted_license_statement": "- MIT\n",
Expand Down Expand Up @@ -138,8 +138,8 @@
"bug_tracking_url": "https://github.com/blakeembrey/change-case/issues",
"code_view_url": null,
"vcs_url": "git://github.com/blakeembrey/change-case.git",
"copyright": null,
"holder": null,
"copyright": "Copyright (c) 2014 Blake Embrey (hello@blakeembrey.com)",
"holder": "Blake Embrey",
"declared_license_expression": "mit",
"declared_license_expression_spdx": "MIT",
"license_detections": [
Expand All @@ -166,7 +166,7 @@
"identifier": "mit-a822f434-d61f-f2b1-c792-8b8cb9e7b9bf"
}
],
"other_license_expression": null,
"other_license_expression": "apache-2.0",
"other_license_expression_spdx": null,
"other_license_detections": [],
"extracted_license_statement": "- MIT\n",
Expand Down Expand Up @@ -234,8 +234,8 @@
"bug_tracking_url": "https://github.com/blakeembrey/change-case/issues",
"code_view_url": null,
"vcs_url": "git://github.com/blakeembrey/change-case.git",
"copyright": null,
"holder": null,
"copyright": "Copyright (c) 2014 Blake Embrey (hello@blakeembrey.com)",
"holder": "Blake Embrey",
"declared_license_expression": "mit",
"declared_license_expression_spdx": "MIT",
"license_detections": [
Expand Down Expand Up @@ -330,8 +330,8 @@
"bug_tracking_url": "https://github.com/blakeembrey/change-case/issues",
"code_view_url": null,
"vcs_url": "git://github.com/blakeembrey/change-case.git",
"copyright": null,
"holder": null,
"copyright": "Copyright (c) 2014 Blake Embrey (hello@blakeembrey.com)",
"holder": "Blake Embrey",
"declared_license_expression": "mit",
"declared_license_expression_spdx": "MIT",
"license_detections": [
Expand Down Expand Up @@ -29513,6 +29513,50 @@
}
],
"license_detections": [
{
"identifier": "apache_2_0-c4e30bcd-ccfd-bbc3-d2f1-196ab911e47d",
"license_expression": "apache-2.0",
"license_expression_spdx": "Apache-2.0",
"detection_count": 2,
"reference_matches": [
{
"license_expression": "apache-2.0",
"license_expression_spdx": "Apache-2.0",
"from_file": "change-case-change-case-5.4.4.zip-extract/change-case-change-case-5.4.4/packages/change-case/LICENSE",
"start_line": 3,
"end_line": 13,
"matcher": "2-aho",
"score": 100.0,
"matched_length": 85,
"match_coverage": 100.0,
"rule_relevance": 100,
"rule_identifier": "apache-2.0_7.RULE",
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/apache-2.0_7.RULE"
}
]
},
{
"identifier": "bsd_plus_patent-15234561-b715-ee5d-a8e8-83df580a00dc",
"license_expression": "bsd-plus-patent",
"license_expression_spdx": "BSD-2-Clause-Patent",
"detection_count": 1,
"reference_matches": [
{
"license_expression": "bsd-plus-patent",
"license_expression_spdx": "BSD-2-Clause-Patent",
"from_file": "change-case-change-case-5.4.4.zip-extract/change-case-change-case-5.4.4/packages/change-case/license.md",
"start_line": 3,
"end_line": 19,
"matcher": "2-aho",
"score": 100.0,
"matched_length": 375,
"match_coverage": 100.0,
"rule_relevance": 100,
"rule_identifier": "bsd-plus-patent.LICENSE",
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/bsd-plus-patent.LICENSE"
}
]
},
{
"identifier": "mit-3fce6ea2-8abd-6c6b-3ede-a37af7c6efee",
"license_expression": "mit",
Expand Down Expand Up @@ -57990,6 +58034,112 @@
"authors": [],
"scan_errors": []
},
{
"path": "change-case-change-case-5.4.4/packages/change-case/LICENSE",
"type": "file",
"package_data": [],
"for_packages": [
"pkg:npm/change-case@5.4.4?uuid=fixed-uid-done-for-testing-5642512d1758"
],
"is_legal": true,
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"detected_license_expression": "apache-2.0",
"detected_license_expression_spdx": "Apache-2.0",
"license_detections": [
{
"license_expression": "apache-2.0",
"license_expression_spdx": "Apache-2.0",
"matches": [
{
"license_expression": "apache-2.0",
"spdx_license_expression": "Apache-2.0",
"from_file": "change-case-change-case-5.4.4.zip-extract/change-case-change-case-5.4.4/packages/change-case/LICENSE",
"start_line": 3,
"end_line": 13,
"matcher": "2-aho",
"score": 100.0,
"matched_length": 85,
"match_coverage": 100.0,
"rule_relevance": 100,
"rule_identifier": "apache-2.0_7.RULE",
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/apache-2.0_7.RULE"
}
],
"identifier": "apache_2_0-c4e30bcd-ccfd-bbc3-d2f1-196ab911e47d"
}
],
"license_clues": [],
"percentage_of_license_text": 96.59,
"copyrights": [
{
"copyright": "Copyright 2024",
"start_line": 1,
"end_line": 1
}
],
"holders": [],
"authors": [],
"scan_errors": []
},
{
"path": "change-case-change-case-5.4.4/packages/change-case/license.md",
"type": "file",
"package_data": [],
"for_packages": [
"pkg:npm/change-case@5.4.4?uuid=fixed-uid-done-for-testing-5642512d1758"
],
"is_legal": true,
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"detected_license_expression": "bsd-plus-patent",
"detected_license_expression_spdx": "BSD-2-Clause-Patent",
"license_detections": [
{
"license_expression": "bsd-plus-patent",
"license_expression_spdx": "BSD-2-Clause-Patent",
"matches": [
{
"license_expression": "bsd-plus-patent",
"spdx_license_expression": "BSD-2-Clause-Patent",
"from_file": "change-case-change-case-5.4.4.zip-extract/change-case-change-case-5.4.4/packages/change-case/license.md",
"start_line": 3,
"end_line": 19,
"matcher": "2-aho",
"score": 100.0,
"matched_length": 375,
"match_coverage": 100.0,
"rule_relevance": 100,
"rule_identifier": "bsd-plus-patent.LICENSE",
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses/bsd-plus-patent.LICENSE"
}
],
"identifier": "bsd_plus_patent-15234561-b715-ee5d-a8e8-83df580a00dc"
}
],
"license_clues": [],
"percentage_of_license_text": 98.68,
"copyrights": [
{
"copyright": "Copyright (c) 2024 Redistribution",
"start_line": 1,
"end_line": 3
}
],
"holders": [
{
"holder": "Redistribution",
"start_line": 3,
"end_line": 3
}
],
"authors": [],
"scan_errors": []
},
{
"path": "change-case-change-case-5.4.4/packages/change-case/package.json",
"type": "file",
Expand Down Expand Up @@ -58280,6 +58430,56 @@
"authors": [],
"scan_errors": []
},
{
"path": "change-case-change-case-5.4.4/packages/sponge-case/LICENSE",
"type": "file",
"package_data": [],
"for_packages": [
"pkg:npm/sponge-case@2.0.3?uuid=fixed-uid-done-for-testing-5642512d1758"
],
"is_legal": true,
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"detected_license_expression": "apache-2.0",
"detected_license_expression_spdx": "Apache-2.0",
"license_detections": [
{
"license_expression": "apache-2.0",
"license_expression_spdx": "Apache-2.0",
"matches": [
{
"license_expression": "apache-2.0",
"spdx_license_expression": "Apache-2.0",
"from_file": "change-case-change-case-5.4.4.zip-extract/change-case-change-case-5.4.4/packages/sponge-case/LICENSE",
"start_line": 3,
"end_line": 13,
"matcher": "2-aho",
"score": 100.0,
"matched_length": 85,
"match_coverage": 100.0,
"rule_relevance": 100,
"rule_identifier": "apache-2.0_7.RULE",
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/apache-2.0_7.RULE"
}
],
"identifier": "apache_2_0-c4e30bcd-ccfd-bbc3-d2f1-196ab911e47d"
}
],
"license_clues": [],
"percentage_of_license_text": 96.59,
"copyrights": [
{
"copyright": "Copyright 2024",
"start_line": 1,
"end_line": 1
}
],
"holders": [],
"authors": [],
"scan_errors": []
},
{
"path": "change-case-change-case-5.4.4/packages/sponge-case/package.json",
"type": "file",
Expand Down

0 comments on commit 0ba0468

Please sign in to comment.