Skip to content

Commit

Permalink
Fix package resource assign bug for jar manifests
Browse files Browse the repository at this point in the history
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
  • Loading branch information
AyanSinhaMahapatra committed Nov 14, 2024
1 parent 824163f commit cb808a2
Show file tree
Hide file tree
Showing 9 changed files with 366 additions and 10 deletions.
11 changes: 7 additions & 4 deletions src/packagedcode/maven.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def assemble(cls, package_data, resource, codebase, package_adder=models.add_to_
yield from models.DatafileHandler.assemble(package_data, resource, codebase)
return

if not package_data.purl:
return

datafile_path = resource.path

# This order is important as we want pom.xml to be used for package
Expand Down Expand Up @@ -116,11 +119,11 @@ def assemble(cls, package_data, resource, codebase, package_adder=models.add_to_
parent_resource=parent_resource,
)
elif manifests and not pom_xmls:
yield from JavaJarManifestHandlerMixin.assemble(package_data, resource, codebase)
yield from JavaJarManifestHandlerMixin.assemble(package_data, resource, codebase, package_adder)
elif pom_xmls and not manifests:
yield from MavenPomXmlHandlerMixin.assemble(package_data, resource, codebase)
yield from MavenPomXmlHandlerMixin.assemble(package_data, resource, codebase, package_adder)
else:
yield from models.DatafileHandler.assemble(package_data, resource, codebase)
yield from models.DatafileHandler.assemble(package_data, resource, codebase, package_adder)


class JavaJarManifestHandler(MavenBasePackageHandler):
Expand Down Expand Up @@ -149,7 +152,7 @@ def assign_package_to_resources(cls, package, resource, codebase, package_adder)
# we want to root of the jar, two levels up
parent = resource.parent(codebase)
if parent:
parent = resource.parent(codebase)
parent = parent.parent(codebase)
if parent:
models.DatafileHandler.assign_package_to_resources(
package,
Expand Down
5 changes: 5 additions & 0 deletions src/packagedcode/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,11 @@ def assign_package_to_resources(cls, package, resource, codebase, package_adder=
# NOTE: we do not attach files to the Package level. Instead we
# update `for_packages` of a codebase resource.
package_uid = package.package_uid
if resource.path.endswith("-extract"):
archive_resource_path = resource.path.rstrip("-extract")
archive_resource = codebase.get_resource(archive_resource_path)
package_adder(package_uid, archive_resource, codebase)

if resource and package_uid:
package_adder(package_uid, resource, codebase)
for res in resource.walk(codebase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@
"path": "jackson-dataformat-xml-2.13.5",
"type": "directory",
"package_data": [],
"for_packages": [],
"for_packages": [
"pkg:jar/[email protected]?uuid=fixed-uid-done-for-testing-5642512d1758"
],
"detected_license_expression": null,
"detected_license_expression_spdx": null,
"license_detections": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,319 @@
{
"packages": [
{
"type": "jar",
"namespace": null,
"name": "spring-web",
"version": "5.3.20",
"qualifiers": {},
"subpath": null,
"primary_language": null,
"description": null,
"release_date": null,
"parties": [],
"keywords": [],
"homepage_url": null,
"download_url": null,
"size": null,
"sha1": null,
"md5": null,
"sha256": null,
"sha512": null,
"bug_tracking_url": null,
"code_view_url": null,
"vcs_url": null,
"copyright": null,
"holder": null,
"declared_license_expression": "apache-2.0",
"declared_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",
"license_expression_spdx": "Apache-2.0",
"from_file": "spring-web-5.3.20-jar/spring-web-5.3.20.jar-extract/META-INF/notice.txt",
"start_line": 4,
"end_line": 6,
"matcher": "2-aho",
"score": 100.0,
"matched_length": 27,
"match_coverage": 100.0,
"rule_relevance": 100,
"rule_identifier": "apache-2.0_701.RULE",
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/apache-2.0_701.RULE"
}
],
"detection_log": [],
"identifier": "apache_2_0-dda7c7b6-8825-2c52-d55b-46f66d469baa"
}
],
"other_license_expression": null,
"other_license_expression_spdx": null,
"other_license_detections": [],
"extracted_license_statement": null,
"notice_text": null,
"source_packages": [],
"is_private": false,
"is_virtual": false,
"extra_data": {},
"repository_homepage_url": null,
"repository_download_url": null,
"api_data_url": null,
"package_uid": "pkg:jar/[email protected]?uuid=fixed-uid-done-for-testing-5642512d1758",
"datafile_paths": [
"spring-web-5.3.20-jar/spring-web-5.3.20.jar-extract/META-INF/MANIFEST.MF"
],
"datasource_ids": [
"java_jar_manifest"
],
"purl": "pkg:jar/[email protected]"
}
],
"dependencies": [],
"license_detections": [
{
"identifier": "apache_2_0-dda7c7b6-8825-2c52-d55b-46f66d469baa",
"license_expression": "apache-2.0",
"license_expression_spdx": "Apache-2.0",
"detection_count": 2,
"detection_log": [],
"reference_matches": [
{
"license_expression": "apache-2.0",
"license_expression_spdx": "Apache-2.0",
"from_file": "spring-web-5.3.20-jar/spring-web-5.3.20.jar-extract/META-INF/notice.txt",
"start_line": 4,
"end_line": 6,
"matcher": "2-aho",
"score": 100.0,
"matched_length": 27,
"match_coverage": 100.0,
"rule_relevance": 100,
"rule_identifier": "apache-2.0_701.RULE",
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/apache-2.0_701.RULE"
}
]
}
],
"files": [
{
"path": "spring-web-5.3.20-jar",
"type": "directory",
"package_data": [],
"for_packages": [],
"detected_license_expression": null,
"detected_license_expression_spdx": null,
"license_detections": [],
"license_clues": [],
"percentage_of_license_text": 0,
"scan_errors": []
},
{
"path": "spring-web-5.3.20-jar/spring-web-5.3.20.jar",
"type": "file",
"package_data": [
{
"type": "jar",
"namespace": null,
"name": null,
"version": null,
"qualifiers": {},
"subpath": null,
"primary_language": null,
"description": null,
"release_date": null,
"parties": [],
"keywords": [],
"homepage_url": null,
"download_url": null,
"size": null,
"sha1": null,
"md5": null,
"sha256": null,
"sha512": null,
"bug_tracking_url": null,
"code_view_url": null,
"vcs_url": null,
"copyright": null,
"holder": null,
"declared_license_expression": null,
"declared_license_expression_spdx": null,
"license_detections": [],
"other_license_expression": null,
"other_license_expression_spdx": null,
"other_license_detections": [],
"extracted_license_statement": null,
"notice_text": null,
"source_packages": [],
"file_references": [],
"is_private": false,
"is_virtual": false,
"extra_data": {},
"dependencies": [],
"repository_homepage_url": null,
"repository_download_url": null,
"api_data_url": null,
"datasource_id": "java_jar",
"purl": null
}
],
"for_packages": [],
"detected_license_expression": null,
"detected_license_expression_spdx": null,
"license_detections": [],
"license_clues": [],
"percentage_of_license_text": 0,
"scan_errors": []
},
{
"path": "spring-web-5.3.20-jar/spring-web-5.3.20.jar-extract",
"type": "directory",
"package_data": [],
"for_packages": [
"pkg:jar/[email protected]?uuid=fixed-uid-done-for-testing-5642512d1758"
],
"detected_license_expression": null,
"detected_license_expression_spdx": null,
"license_detections": [],
"license_clues": [],
"percentage_of_license_text": 0,
"scan_errors": []
},
{
"path": "spring-web-5.3.20-jar/spring-web-5.3.20.jar-extract/META-INF",
"type": "directory",
"package_data": [],
"for_packages": [
"pkg:jar/[email protected]?uuid=fixed-uid-done-for-testing-5642512d1758"
],
"detected_license_expression": null,
"detected_license_expression_spdx": null,
"license_detections": [],
"license_clues": [],
"percentage_of_license_text": 0,
"scan_errors": []
},
{
"path": "spring-web-5.3.20-jar/spring-web-5.3.20.jar-extract/META-INF/MANIFEST.MF",
"type": "file",
"package_data": [
{
"type": "jar",
"namespace": null,
"name": "spring-web",
"version": "5.3.20",
"qualifiers": {},
"subpath": null,
"primary_language": null,
"description": "",
"release_date": null,
"parties": [],
"keywords": [],
"homepage_url": null,
"download_url": null,
"size": null,
"sha1": null,
"md5": null,
"sha256": null,
"sha512": null,
"bug_tracking_url": null,
"code_view_url": null,
"vcs_url": null,
"copyright": null,
"holder": null,
"declared_license_expression": "apache-2.0",
"declared_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",
"license_expression_spdx": "Apache-2.0",
"from_file": "spring-web-5.3.20-jar/spring-web-5.3.20.jar-extract/META-INF/notice.txt",
"start_line": 4,
"end_line": 6,
"matcher": "2-aho",
"score": 100.0,
"matched_length": 27,
"match_coverage": 100.0,
"rule_relevance": 100,
"rule_identifier": "apache-2.0_701.RULE",
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/apache-2.0_701.RULE"
}
],
"detection_log": [],
"identifier": "apache_2_0-dda7c7b6-8825-2c52-d55b-46f66d469baa"
}
],
"other_license_expression": null,
"other_license_expression_spdx": null,
"other_license_detections": [],
"extracted_license_statement": null,
"notice_text": null,
"source_packages": [],
"file_references": [],
"is_private": false,
"is_virtual": false,
"extra_data": {},
"dependencies": [],
"repository_homepage_url": null,
"repository_download_url": null,
"api_data_url": null,
"datasource_id": "java_jar_manifest",
"purl": "pkg:jar/[email protected]"
}
],
"for_packages": [
"pkg:jar/[email protected]?uuid=fixed-uid-done-for-testing-5642512d1758"
],
"detected_license_expression": null,
"detected_license_expression_spdx": null,
"license_detections": [],
"license_clues": [],
"percentage_of_license_text": 0,
"scan_errors": []
},
{
"path": "spring-web-5.3.20-jar/spring-web-5.3.20.jar-extract/META-INF/notice.txt",
"type": "file",
"package_data": [],
"for_packages": [
"pkg:jar/[email protected]?uuid=fixed-uid-done-for-testing-5642512d1758"
],
"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",
"license_expression_spdx": "Apache-2.0",
"from_file": "spring-web-5.3.20-jar/spring-web-5.3.20.jar-extract/META-INF/notice.txt",
"start_line": 4,
"end_line": 6,
"matcher": "2-aho",
"score": 100.0,
"matched_length": 27,
"match_coverage": 100.0,
"rule_relevance": 100,
"rule_identifier": "apache-2.0_701.RULE",
"rule_url": "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/rules/apache-2.0_701.RULE"
}
],
"detection_log": [],
"identifier": "apache_2_0-dda7c7b6-8825-2c52-d55b-46f66d469baa"
}
],
"license_clues": [],
"percentage_of_license_text": 71.05,
"scan_errors": []
}
]
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Manifest-Version: 1.0
Implementation-Title: spring-web
Automatic-Module-Name: spring.web
Implementation-Version: 5.3.20
Created-By: 1.8.0_332 (Oracle Corporation)

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Spring Framework 5.3.20
Copyright (c) 2002-2022 Pivotal, Inc.

This product is licensed to you under the Apache License, Version 2.0
(the "License"). You may not use this product except in compliance with
the License.
Loading

0 comments on commit cb808a2

Please sign in to comment.