From a8001f67644d7663d1202e82bfea07c26b9d18b3 Mon Sep 17 00:00:00 2001 From: Keshav Priyadarshi Date: Fri, 5 Jul 2024 18:55:32 +0530 Subject: [PATCH 1/3] Consolidate Swift package assembly - Consolidate Swift package assembly into a single BaseSwiftDatafileHandler Signed-off-by: Keshav Priyadarshi --- src/packagedcode/swift.py | 284 +++++++++++++++++--------------------- 1 file changed, 125 insertions(+), 159 deletions(-) diff --git a/src/packagedcode/swift.py b/src/packagedcode/swift.py index 1fd08a00cc1..e76a3d9f4ae 100644 --- a/src/packagedcode/swift.py +++ b/src/packagedcode/swift.py @@ -47,7 +47,129 @@ def logger_debug(*args): return logger.debug(" ".join(isinstance(a, str) and a or repr(a) for a in args)) -class SwiftShowDependenciesDepLockHandler(models.DatafileHandler): +class BaseSwiftDatafileHandler(models.DatafileHandler): + @classmethod + def assemble(cls, package_data, resource, codebase, package_adder): + swift_manifest_resource = None + swift_show_dependencies_resource = None + swift_resolved_package_resource = None + processed_package = None + add_datafile_paths = [] + add_datasource_ids = [] + processed_dependencies = [] + + for r in resource.siblings(codebase): + if r.name in ("Package.swift.json", "Package.swift.deplock"): + swift_manifest_resource = r + elif r.name in ("Package.resolved", ".package.resolved"): + swift_resolved_package_resource = r + elif r.name == "swift-show-dependencies.deplock": + swift_show_dependencies_resource = r + + # If only Package.resolved is available then yield all dependency as package. + if ( + not swift_manifest_resource + and not swift_show_dependencies_resource + and resource.name in ("Package.resolved", ".package.resolved") + ): + processed_package = package_data + processed_dependencies = package_data.dependencies + # If no manifest but have dependency graph from `deplock` then use it construct top-level package. + elif ( + not swift_manifest_resource + and resource.name == "swift-show-dependencies.deplock" + ): + processed_package = package_data + processed_dependencies = package_data.dependencies + # If manifest is available then use the manifest for to construct top-level package. + elif swift_manifest_resource and resource.name in ( + "Package.swift.json", + "Package.swift.deplock", + ): + processed_dependencies = package_data.dependencies + # Dependencies from `swift-show-dependencies.deplock` supersedes dependencies from other datafiles. + if swift_show_dependencies_resource: + swift_show_dependencies_package_data = models.PackageData.from_dict( + swift_show_dependencies_resource.package_data[0] + ) + processed_dependencies = ( + swift_show_dependencies_package_data.dependencies + ) + # Use dependencies from `Package.resolved` when `swift-show-dependencies.deplock` is not present. + elif swift_resolved_package_resource: + swift_resolved_package_data = ( + swift_resolved_package_resource.package_data + ) + + resolved_dependencies = [] + for package in swift_resolved_package_data: + version = package.get("version") + name = package.get("name") + + purl = PackageURL( + type=cls.default_package_type, name=name, version=version + ) + resolved_dependencies.append( + models.DependentPackage( + purl=purl.to_string(), + scope="dependencies", + is_runtime=True, + is_optional=False, + is_resolved=True, + extracted_requirement=version, + ) + ) + + for dependency in processed_dependencies[:]: + dependency_purl = PackageURL.from_string(dependency.purl) + + if dependency_purl.name == name: + processed_dependencies.remove(dependency) + + processed_dependencies.extend(resolved_dependencies) + + processed_package = package_data + if swift_show_dependencies_resource: + add_datafile_paths.append(swift_show_dependencies_resource.path) + add_datasource_ids.append( + SwiftShowDependenciesDepLockHandler.datasource_id + ) + elif swift_resolved_package_resource: + add_datafile_paths.append(swift_resolved_package_resource.path) + add_datasource_ids.append(SwiftPackageResolvedHandler.datasource_id) + + if processed_package and processed_package.purl: + package = models.Package.from_package_data( + package_data=processed_package, + datafile_path=resource.path, + ) + + package.datafile_paths.extend(add_datafile_paths) + package.datasource_ids.extend(add_datasource_ids) + + package.populate_license_fields() + yield package + + parent = resource.parent(codebase) + cls.assign_package_to_resources( + package=package, + resource=parent, + codebase=codebase, + package_adder=package_adder, + ) + + if processed_dependencies: + yield from models.Dependency.from_dependent_packages( + dependent_packages=processed_dependencies, + datafile_path=resource.path, + datasource_id=processed_package.datasource_id, + package_uid=package.package_uid, + ) + + yield resource + + +class SwiftShowDependenciesDepLockHandler(BaseSwiftDatafileHandler): datasource_id = "swift_package_show_dependencies" path_patterns = ("*/swift-show-dependencies.deplock",) default_package_type = "swift" @@ -86,32 +208,8 @@ def parse(cls, location, package_only=False): yield cls._parse(swift_dependency_relation, package_only) - @classmethod - def assemble( - cls, package_data, resource, codebase, package_adder=models.add_to_package - ): - siblings = resource.siblings(codebase) - swift_manifest_resource = [ - r - for r in siblings - if r.name in ("Package.swift.json", "Package.swift.deplock") - ] - - # Skip the assembly if the Swift manifest is present. - # SwiftManifestJsonHandler's assembly will take care of the - # dependencies from swift-show-dependencies.deplock file. - if swift_manifest_resource: - return [] - - yield from super(SwiftShowDependenciesDepLockHandler, cls).assemble( - package_data=package_data, - resource=resource, - codebase=codebase, - package_adder=package_adder, - ) - -class SwiftManifestJsonHandler(models.DatafileHandler): +class SwiftManifestJsonHandler(BaseSwiftDatafileHandler): datasource_id = "swift_package_manifest_json" path_patterns = ("*/Package.swift.json", "*/Package.swift.deplock") default_package_type = "swift" @@ -149,116 +247,8 @@ def parse(cls, location, package_only=False): yield cls._parse(swift_manifest, package_only) - @classmethod - def assemble( - cls, - package_data, - resource, - codebase, - package_adder=models.add_to_package, - ): - """ - Use the dependencies from `Package.resolved` to create the - top-level package with resolved dependencies. - """ - siblings = resource.siblings(codebase) - processed_dependencies = [] - swift_resolved_package_resource = [ - r for r in siblings if r.name == "Package.resolved" - ] - - swift_show_dependencies_resources = [ - r for r in siblings if r.name == "swift-show-dependencies.deplock" - ] - - if swift_show_dependencies_resources: - swift_show_dependencies_resource = swift_show_dependencies_resources[0] - swift_show_dependencies_package_data = ( - swift_show_dependencies_resource.package_data - ) - - # Dependencies from `swift-show-dependencies.deplock` supersede dependencies from other datafiles. - processed_dependencies = swift_show_dependencies_package_data[0][ - "dependencies" - ] - processed_dependencies = [ - models.DependentPackage.from_dict(i) for i in processed_dependencies - ] - - # Use dependencies from `Package.resolved` when `swift-show-dependencies.deplock` is not present. - else: - dependencies_from_manifest = package_data.dependencies - - if swift_resolved_package_resource: - swift_resolved_package_resource = swift_resolved_package_resource[0] - swift_resolved_package_data = ( - swift_resolved_package_resource.package_data - ) - - for package in swift_resolved_package_data: - version = package.get("version") - name = package.get("name") - - purl = PackageURL( - type=cls.default_package_type, name=name, version=version - ) - processed_dependencies.append( - models.DependentPackage( - purl=purl.to_string(), - scope="dependencies", - is_runtime=True, - is_optional=False, - is_resolved=True, - extracted_requirement=version, - ) - ) - - for dependency in dependencies_from_manifest[:]: - dependency_purl = PackageURL.from_string(dependency.purl) - - if dependency_purl.name == name: - dependencies_from_manifest.remove(dependency) - processed_dependencies.extend(dependencies_from_manifest) - - datafile_path = resource.path - if package_data.purl: - package = models.Package.from_package_data( - package_data=package_data, - datafile_path=datafile_path, - ) - - if swift_show_dependencies_resources: - package.datafile_paths.append(swift_show_dependencies_resource.path) - package.datasource_ids.append( - SwiftShowDependenciesDepLockHandler.datasource_id - ) - elif swift_resolved_package_resource: - package.datafile_paths.append(swift_resolved_package_resource.path) - package.datasource_ids.append(SwiftPackageResolvedHandler.datasource_id) - - package.populate_license_fields() - yield package - - parent = resource.parent(codebase) - cls.assign_package_to_resources( - package=package, - resource=parent, - codebase=codebase, - package_adder=package_adder, - ) - - if processed_dependencies: - yield from models.Dependency.from_dependent_packages( - dependent_packages=processed_dependencies, - datafile_path=datafile_path, - datasource_id=package_data.datasource_id, - package_uid=package.package_uid, - ) - yield resource - - -class SwiftPackageResolvedHandler(models.DatafileHandler): +class SwiftPackageResolvedHandler(BaseSwiftDatafileHandler): datasource_id = "swift_package_resolved" path_patterns = ("*/Package.resolved", "*/.package.resolved") default_package_type = "swift" @@ -282,30 +272,6 @@ def parse(cls, location, package_only=False): if resolved_doc_version == 1: yield from packages_from_resolved_v1(package_resolved) - @classmethod - def assemble( - cls, package_data, resource, codebase, package_adder=models.add_to_package - ): - siblings = resource.siblings(codebase) - swift_manifest_resource = [ - r - for r in siblings - if r.name in ("Package.swift.json", "Package.swift.deplock") - ] - - # Skip the assembly if the ``Package.swift.json`` manifest is present. - # SwiftManifestJsonHandler's assembly will take care of the resolved - # dependencies from Package.resolved file. - if swift_manifest_resource: - return [] - - yield from super(SwiftPackageResolvedHandler, cls).assemble( - package_data=package_data, - resource=resource, - codebase=codebase, - package_adder=package_adder, - ) - def packages_from_resolved_v2_and_v3(package_resolved): pinned = package_resolved.get("pins", []) From a1f5fa043a4eb57141557fec6b3a2595b2409474 Mon Sep 17 00:00:00 2001 From: Keshav Priyadarshi Date: Fri, 5 Jul 2024 21:11:19 +0530 Subject: [PATCH 2/3] Add test for isolated swift-show-dependencies.deplock Signed-off-by: Keshav Priyadarshi --- .../fastlane_resolved_v1/Package.resolved | 37 +- .../swift-show-dependencies.deplock | 65 ++ ...fastlane-resolved-v1-package-expected.json | 105 ++- ...t-vercelui-show-dependencies-expected.json | 889 ++++++++++++++++++ tests/packagedcode/test_swift.py | 23 +- 5 files changed, 1101 insertions(+), 18 deletions(-) create mode 100644 tests/packagedcode/data/swift/packages/vercelui_show_dependencies/swift-show-dependencies.deplock create mode 100644 tests/packagedcode/data/swift/swift-vercelui-show-dependencies-expected.json diff --git a/tests/packagedcode/data/swift/packages/fastlane_resolved_v1/Package.resolved b/tests/packagedcode/data/swift/packages/fastlane_resolved_v1/Package.resolved index 91aa2bec40f..657bdf9f950 100644 --- a/tests/packagedcode/data/swift/packages/fastlane_resolved_v1/Package.resolved +++ b/tests/packagedcode/data/swift/packages/fastlane_resolved_v1/Package.resolved @@ -1,16 +1,25 @@ { - "object": { - "pins": [ - { - "package": "SwiftShell", - "repositoryURL": "https://github.com/kareman/SwiftShell", - "state": { - "branch": null, - "revision": "99680b2efc7c7dbcace1da0b3979d266f02e213c", - "version": "5.1.0" - } - } - ] - }, - "version": 1 + "object":{ + "pins":[ + { + "package":"SwiftShell", + "repositoryURL":"https://github.com/kareman/SwiftShell", + "state":{ + "branch":null, + "revision":"99680b2efc7c7dbcace1da0b3979d266f02e213c", + "version":"5.1.0" + } + }, + { + "package":"swift-atomics", + "repositoryURL":"https://github.com/apple/swift-atomics.git", + "state":{ + "branch":null, + "revision":"6c89474e62719ddcc1e9614989fff2f68208fe10", + "version":"1.1.0" + } + } + ] + }, + "version":1 } \ No newline at end of file diff --git a/tests/packagedcode/data/swift/packages/vercelui_show_dependencies/swift-show-dependencies.deplock b/tests/packagedcode/data/swift/packages/vercelui_show_dependencies/swift-show-dependencies.deplock new file mode 100644 index 00000000000..a714d1d31c8 --- /dev/null +++ b/tests/packagedcode/data/swift/packages/vercelui_show_dependencies/swift-show-dependencies.deplock @@ -0,0 +1,65 @@ +{ + "identity":"vercelui", + "name":"VercelUI", + "url":"/workspace/vercel/VercelUI", + "version":"unspecified", + "path":"/workspace/vercel/VercelUI", + "dependencies":[ + { + "identity":"vercel", + "name":"Vercel", + "url":"https://github.com/swift-cloud/Vercel", + "version":"1.15.2", + "path":"/workspace/vercel/VercelUI/.build/checkouts/Vercel", + "dependencies":[ + { + "identity":"vapor", + "name":"vapor", + "url":"https://github.com/vapor/vapor", + "version":"4.79.0", + "path":"/workspace/vercel/VercelUI/.build/checkouts/vapor", + "dependencies":[ + { + "identity":"async-http-client", + "name":"async-http-client", + "url":"https://github.com/swift-server/async-http-client.git", + "version":"1.19.0", + "path":"/workspace/vercel/VercelUI/.build/checkouts/async-http-client", + "dependencies":[ + { + "identity":"swift-nio", + "name":"swift-nio", + "url":"https://github.com/apple/swift-nio.git", + "version":"2.58.0", + "path":"/workspace/vercel/VercelUI/.build/checkouts/swift-nio", + "dependencies":[ + { + "identity":"swift-atomics", + "name":"swift-atomics", + "url":"https://github.com/apple/swift-atomics.git", + "version":"1.1.0", + "path":"/workspace/vercel/VercelUI/.build/checkouts/swift-atomics", + "dependencies":[ + + ] + } + ] + }, + { + "identity":"swift-atomics", + "name":"swift-atomics", + "url":"https://github.com/apple/swift-atomics.git", + "version":"1.1.0", + "path":"/workspace/vercel/VercelUI/.build/checkouts/swift-atomics", + "dependencies":[ + + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/tests/packagedcode/data/swift/swift-fastlane-resolved-v1-package-expected.json b/tests/packagedcode/data/swift/swift-fastlane-resolved-v1-package-expected.json index 7e171a4099f..479f0d9f8eb 100644 --- a/tests/packagedcode/data/swift/swift-fastlane-resolved-v1-package-expected.json +++ b/tests/packagedcode/data/swift/swift-fastlane-resolved-v1-package-expected.json @@ -47,6 +47,54 @@ "swift_package_resolved" ], "purl": "pkg:swift/github.com/kareman/SwiftShell@5.1.0" + }, + { + "type": "swift", + "namespace": "github.com/apple", + "name": "swift-atomics", + "version": "1.1.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "swift", + "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": [], + "is_private": false, + "is_virtual": false, + "extra_data": {}, + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "package_uid": "pkg:swift/github.com/apple/swift-atomics@1.1.0?uuid=fixed-uid-done-for-testing-5642512d1758", + "datafile_paths": [ + "Package.resolved" + ], + "datasource_ids": [ + "swift_package_resolved" + ], + "purl": "pkg:swift/github.com/apple/swift-atomics@1.1.0" } ], "dependencies": [], @@ -98,10 +146,55 @@ "api_data_url": null, "datasource_id": "swift_package_resolved", "purl": "pkg:swift/github.com/kareman/SwiftShell@5.1.0" + }, + { + "type": "swift", + "namespace": "github.com/apple", + "name": "swift-atomics", + "version": "1.1.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "swift", + "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": "swift_package_resolved", + "purl": "pkg:swift/github.com/apple/swift-atomics@1.1.0" } ], "for_packages": [ - "pkg:swift/github.com/kareman/SwiftShell@5.1.0?uuid=fixed-uid-done-for-testing-5642512d1758" + "pkg:swift/github.com/kareman/SwiftShell@5.1.0?uuid=fixed-uid-done-for-testing-5642512d1758", + "pkg:swift/github.com/apple/swift-atomics@1.1.0?uuid=fixed-uid-done-for-testing-5642512d1758" ], "scan_errors": [] }, @@ -109,14 +202,20 @@ "path": "src", "type": "directory", "package_data": [], - "for_packages": [], + "for_packages": [ + "pkg:swift/github.com/kareman/SwiftShell@5.1.0?uuid=fixed-uid-done-for-testing-5642512d1758", + "pkg:swift/github.com/apple/swift-atomics@1.1.0?uuid=fixed-uid-done-for-testing-5642512d1758" + ], "scan_errors": [] }, { "path": "src/mapbox.swift", "type": "file", "package_data": [], - "for_packages": [], + "for_packages": [ + "pkg:swift/github.com/kareman/SwiftShell@5.1.0?uuid=fixed-uid-done-for-testing-5642512d1758", + "pkg:swift/github.com/apple/swift-atomics@1.1.0?uuid=fixed-uid-done-for-testing-5642512d1758" + ], "scan_errors": [] } ] diff --git a/tests/packagedcode/data/swift/swift-vercelui-show-dependencies-expected.json b/tests/packagedcode/data/swift/swift-vercelui-show-dependencies-expected.json new file mode 100644 index 00000000000..7ccab546fa7 --- /dev/null +++ b/tests/packagedcode/data/swift/swift-vercelui-show-dependencies-expected.json @@ -0,0 +1,889 @@ +{ + "packages": [ + { + "type": "swift", + "namespace": null, + "name": "VercelUI", + "version": null, + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": [], + "is_private": false, + "is_virtual": false, + "extra_data": {}, + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "package_uid": "pkg:swift/VercelUI?uuid=fixed-uid-done-for-testing-5642512d1758", + "datafile_paths": [ + "swift-show-dependencies.deplock" + ], + "datasource_ids": [ + "swift_package_show_dependencies" + ], + "purl": "pkg:swift/VercelUI" + } + ], + "dependencies": [ + { + "purl": "pkg:swift/github.com/swift-cloud/Vercel@1.15.2", + "extracted_requirement": "1.15.2", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": { + "type": "swift", + "namespace": "github.com/swift-cloud", + "name": "Vercel", + "version": "1.15.2", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [ + { + "purl": "pkg:swift/github.com/vapor/vapor@4.79.0", + "extracted_requirement": "4.79.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {}, + "dependency_uid": "pkg:swift/github.com/swift-cloud/Vercel@1.15.2?uuid=fixed-uid-done-for-testing-5642512d1758", + "for_package_uid": "pkg:swift/VercelUI?uuid=fixed-uid-done-for-testing-5642512d1758", + "datafile_path": "swift-show-dependencies.deplock", + "datasource_id": "swift_package_show_dependencies" + }, + { + "purl": "pkg:swift/github.com/vapor/vapor@4.79.0", + "extracted_requirement": "4.79.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": false, + "resolved_package": { + "type": "swift", + "namespace": "github.com/vapor", + "name": "vapor", + "version": "4.79.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [ + { + "purl": "pkg:swift/github.com/swift-server/async-http-client@1.19.0", + "extracted_requirement": "1.19.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {}, + "dependency_uid": "pkg:swift/github.com/vapor/vapor@4.79.0?uuid=fixed-uid-done-for-testing-5642512d1758", + "for_package_uid": "pkg:swift/VercelUI?uuid=fixed-uid-done-for-testing-5642512d1758", + "datafile_path": "swift-show-dependencies.deplock", + "datasource_id": "swift_package_show_dependencies" + }, + { + "purl": "pkg:swift/github.com/swift-server/async-http-client@1.19.0", + "extracted_requirement": "1.19.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": false, + "resolved_package": { + "type": "swift", + "namespace": "github.com/swift-server", + "name": "async-http-client", + "version": "1.19.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [ + { + "purl": "pkg:swift/github.com/apple/swift-nio@2.58.0", + "extracted_requirement": "2.58.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + }, + { + "purl": "pkg:swift/github.com/apple/swift-atomics@1.1.0", + "extracted_requirement": "1.1.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {}, + "dependency_uid": "pkg:swift/github.com/swift-server/async-http-client@1.19.0?uuid=fixed-uid-done-for-testing-5642512d1758", + "for_package_uid": "pkg:swift/VercelUI?uuid=fixed-uid-done-for-testing-5642512d1758", + "datafile_path": "swift-show-dependencies.deplock", + "datasource_id": "swift_package_show_dependencies" + }, + { + "purl": "pkg:swift/github.com/apple/swift-nio@2.58.0", + "extracted_requirement": "2.58.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": false, + "resolved_package": { + "type": "swift", + "namespace": "github.com/apple", + "name": "swift-nio", + "version": "2.58.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [ + { + "purl": "pkg:swift/github.com/apple/swift-atomics@1.1.0", + "extracted_requirement": "1.1.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {}, + "dependency_uid": "pkg:swift/github.com/apple/swift-nio@2.58.0?uuid=fixed-uid-done-for-testing-5642512d1758", + "for_package_uid": "pkg:swift/VercelUI?uuid=fixed-uid-done-for-testing-5642512d1758", + "datafile_path": "swift-show-dependencies.deplock", + "datasource_id": "swift_package_show_dependencies" + }, + { + "purl": "pkg:swift/github.com/apple/swift-atomics@1.1.0", + "extracted_requirement": "1.1.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": false, + "resolved_package": { + "type": "swift", + "namespace": "github.com/apple", + "name": "swift-atomics", + "version": "1.1.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {}, + "dependency_uid": "pkg:swift/github.com/apple/swift-atomics@1.1.0?uuid=fixed-uid-done-for-testing-5642512d1758", + "for_package_uid": "pkg:swift/VercelUI?uuid=fixed-uid-done-for-testing-5642512d1758", + "datafile_path": "swift-show-dependencies.deplock", + "datasource_id": "swift_package_show_dependencies" + }, + { + "purl": "pkg:swift/github.com/apple/swift-atomics@1.1.0", + "extracted_requirement": "1.1.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": false, + "resolved_package": { + "type": "swift", + "namespace": "github.com/apple", + "name": "swift-atomics", + "version": "1.1.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {}, + "dependency_uid": "pkg:swift/github.com/apple/swift-atomics@1.1.0?uuid=fixed-uid-done-for-testing-5642512d1758", + "for_package_uid": "pkg:swift/VercelUI?uuid=fixed-uid-done-for-testing-5642512d1758", + "datafile_path": "swift-show-dependencies.deplock", + "datasource_id": "swift_package_show_dependencies" + } + ], + "files": [ + { + "path": "swift-show-dependencies.deplock", + "type": "file", + "package_data": [ + { + "type": "swift", + "namespace": null, + "name": "VercelUI", + "version": null, + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": [ + { + "purl": "pkg:swift/github.com/swift-cloud/Vercel@1.15.2", + "extracted_requirement": "1.15.2", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": { + "type": "swift", + "namespace": "github.com/swift-cloud", + "name": "Vercel", + "version": "1.15.2", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [ + { + "purl": "pkg:swift/github.com/vapor/vapor@4.79.0", + "extracted_requirement": "4.79.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {} + }, + { + "purl": "pkg:swift/github.com/vapor/vapor@4.79.0", + "extracted_requirement": "4.79.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": false, + "resolved_package": { + "type": "swift", + "namespace": "github.com/vapor", + "name": "vapor", + "version": "4.79.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [ + { + "purl": "pkg:swift/github.com/swift-server/async-http-client@1.19.0", + "extracted_requirement": "1.19.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {} + }, + { + "purl": "pkg:swift/github.com/swift-server/async-http-client@1.19.0", + "extracted_requirement": "1.19.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": false, + "resolved_package": { + "type": "swift", + "namespace": "github.com/swift-server", + "name": "async-http-client", + "version": "1.19.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [ + { + "purl": "pkg:swift/github.com/apple/swift-nio@2.58.0", + "extracted_requirement": "2.58.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + }, + { + "purl": "pkg:swift/github.com/apple/swift-atomics@1.1.0", + "extracted_requirement": "1.1.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {} + }, + { + "purl": "pkg:swift/github.com/apple/swift-nio@2.58.0", + "extracted_requirement": "2.58.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": false, + "resolved_package": { + "type": "swift", + "namespace": "github.com/apple", + "name": "swift-nio", + "version": "2.58.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [ + { + "purl": "pkg:swift/github.com/apple/swift-atomics@1.1.0", + "extracted_requirement": "1.1.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {} + }, + { + "purl": "pkg:swift/github.com/apple/swift-atomics@1.1.0", + "extracted_requirement": "1.1.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": false, + "resolved_package": { + "type": "swift", + "namespace": "github.com/apple", + "name": "swift-atomics", + "version": "1.1.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {} + }, + { + "purl": "pkg:swift/github.com/apple/swift-atomics@1.1.0", + "extracted_requirement": "1.1.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": false, + "resolved_package": { + "type": "swift", + "namespace": "github.com/apple", + "name": "swift-atomics", + "version": "1.1.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {} + } + ], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies", + "purl": "pkg:swift/VercelUI" + } + ], + "for_packages": [ + "pkg:swift/VercelUI?uuid=fixed-uid-done-for-testing-5642512d1758" + ], + "scan_errors": [] + } + ] +} \ No newline at end of file diff --git a/tests/packagedcode/test_swift.py b/tests/packagedcode/test_swift.py index f4e1337edef..40181dd8431 100644 --- a/tests/packagedcode/test_swift.py +++ b/tests/packagedcode/test_swift.py @@ -102,7 +102,7 @@ def test_package_scan_swift_end_to_end_full_mapboxmaps_resolved_only(self): expected_file, result_file, remove_uuid=True, regen=REGEN_TEST_FIXTURES ) - def test_package_scan_swift_end_to_end_full_vercelui_resolved_only(self): + def test_package_scan_swift_end_to_end_full_vercelui(self): test_dir = self.get_test_loc("packages/vercelui") result_file = self.get_temp_file("json") expected_file = self.get_test_loc( @@ -122,3 +122,24 @@ def test_package_scan_swift_end_to_end_full_vercelui_resolved_only(self): check_json_scan( expected_file, result_file, remove_uuid=True, regen=REGEN_TEST_FIXTURES ) + + def test_package_scan_swift_end_to_end_full_vercelui_show_dependencies_only(self): + test_dir = self.get_test_loc("packages/vercelui_show_dependencies") + result_file = self.get_temp_file("json") + expected_file = self.get_test_loc( + "swift-vercelui-show-dependencies-expected.json" + ) + run_scan_click( + [ + "--package", + "--strip-root", + "--processes", + "-1", + test_dir, + "--json", + result_file, + ] + ) + check_json_scan( + expected_file, result_file, remove_uuid=True, regen=REGEN_TEST_FIXTURES + ) From 61eb4c47510cee520afa3c0bc36b4e8b18c61bea Mon Sep 17 00:00:00 2001 From: Keshav Priyadarshi Date: Fri, 5 Jul 2024 21:29:27 +0530 Subject: [PATCH 3/3] Improve test coverage for Swift datafile handlers Signed-off-by: Keshav Priyadarshi --- src/packagedcode/swift.py | 2 +- ...elui-show-dependencies-parse-expected.json | 424 ++++++++++++++++++ tests/packagedcode/test_swift.py | 32 +- 3 files changed, 454 insertions(+), 4 deletions(-) create mode 100644 tests/packagedcode/data/swift/swift-vercelui-show-dependencies-parse-expected.json diff --git a/src/packagedcode/swift.py b/src/packagedcode/swift.py index e76a3d9f4ae..10d2d917007 100644 --- a/src/packagedcode/swift.py +++ b/src/packagedcode/swift.py @@ -81,7 +81,7 @@ def assemble(cls, package_data, resource, codebase, package_adder): ): processed_package = package_data processed_dependencies = package_data.dependencies - # If manifest is available then use the manifest for to construct top-level package. + # If manifest is available then use the manifest to construct top-level package. elif swift_manifest_resource and resource.name in ( "Package.swift.json", "Package.swift.deplock", diff --git a/tests/packagedcode/data/swift/swift-vercelui-show-dependencies-parse-expected.json b/tests/packagedcode/data/swift/swift-vercelui-show-dependencies-parse-expected.json new file mode 100644 index 00000000000..53688c57dfe --- /dev/null +++ b/tests/packagedcode/data/swift/swift-vercelui-show-dependencies-parse-expected.json @@ -0,0 +1,424 @@ +[ + { + "type": "swift", + "namespace": null, + "name": "VercelUI", + "version": null, + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": [ + { + "purl": "pkg:swift/github.com/swift-cloud/Vercel@1.15.2", + "extracted_requirement": "1.15.2", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": { + "type": "swift", + "namespace": "github.com/swift-cloud", + "name": "Vercel", + "version": "1.15.2", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [ + { + "purl": "pkg:swift/github.com/vapor/vapor@4.79.0", + "extracted_requirement": "4.79.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {} + }, + { + "purl": "pkg:swift/github.com/vapor/vapor@4.79.0", + "extracted_requirement": "4.79.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": false, + "resolved_package": { + "type": "swift", + "namespace": "github.com/vapor", + "name": "vapor", + "version": "4.79.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [ + { + "purl": "pkg:swift/github.com/swift-server/async-http-client@1.19.0", + "extracted_requirement": "1.19.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {} + }, + { + "purl": "pkg:swift/github.com/swift-server/async-http-client@1.19.0", + "extracted_requirement": "1.19.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": false, + "resolved_package": { + "type": "swift", + "namespace": "github.com/swift-server", + "name": "async-http-client", + "version": "1.19.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [ + { + "purl": "pkg:swift/github.com/apple/swift-nio@2.58.0", + "extracted_requirement": "2.58.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + }, + { + "purl": "pkg:swift/github.com/apple/swift-atomics@1.1.0", + "extracted_requirement": "1.1.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {} + }, + { + "purl": "pkg:swift/github.com/apple/swift-nio@2.58.0", + "extracted_requirement": "2.58.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": false, + "resolved_package": { + "type": "swift", + "namespace": "github.com/apple", + "name": "swift-nio", + "version": "2.58.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [ + { + "purl": "pkg:swift/github.com/apple/swift-atomics@1.1.0", + "extracted_requirement": "1.1.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": true, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {} + }, + { + "purl": "pkg:swift/github.com/apple/swift-atomics@1.1.0", + "extracted_requirement": "1.1.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": false, + "resolved_package": { + "type": "swift", + "namespace": "github.com/apple", + "name": "swift-atomics", + "version": "1.1.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {} + }, + { + "purl": "pkg:swift/github.com/apple/swift-atomics@1.1.0", + "extracted_requirement": "1.1.0", + "scope": "dependencies", + "is_runtime": false, + "is_optional": false, + "is_resolved": true, + "is_direct": false, + "resolved_package": { + "type": "swift", + "namespace": "github.com/apple", + "name": "swift-atomics", + "version": "1.1.0", + "qualifiers": {}, + "subpath": null, + "primary_language": "Swift", + "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": true, + "extra_data": {}, + "dependencies": [], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies" + }, + "extra_data": {} + } + ], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "swift_package_show_dependencies", + "purl": "pkg:swift/VercelUI" + } +] \ No newline at end of file diff --git a/tests/packagedcode/test_swift.py b/tests/packagedcode/test_swift.py index 40181dd8431..c4000de0d85 100644 --- a/tests/packagedcode/test_swift.py +++ b/tests/packagedcode/test_swift.py @@ -19,6 +19,24 @@ class TestSwiftHandler(PackageTester): test_data_dir = os.path.join(os.path.dirname(__file__), "data/swift") + def test_swift_manifest_json_dump_is_datafile(self): + test_file = self.get_test_loc( + "packages/mapboxmaps_manifest_and_resolved/Package.swift.json" + ) + assert swift.SwiftManifestJsonHandler.is_datafile(test_file) + + def test_swift_package_resolved_is_datafile(self): + test_file = self.get_test_loc( + "packages/mapboxmaps_manifest_and_resolved/Package.resolved" + ) + assert swift.SwiftPackageResolvedHandler.is_datafile(test_file) + + def test_swift_show_dependencies_deplock_is_datafile(self): + test_file = self.get_test_loc( + "packages/vercelui/swift-show-dependencies.deplock" + ) + assert swift.SwiftShowDependenciesDepLockHandler.is_datafile(test_file) + def test_parse_for_mapboxmaps_manifest(self): test_file = self.get_test_loc( "packages/mapboxmaps_manifest_and_resolved/Package.swift.json" @@ -35,6 +53,16 @@ def test_parse_for_mapboxmaps_resolved(self): packages = swift.SwiftPackageResolvedHandler.parse(test_file) self.check_packages_data(packages, expected_loc, regen=REGEN_TEST_FIXTURES) + def test_parse_for_show_dependencies_deplock(self): + test_file = self.get_test_loc( + "packages/vercelui/swift-show-dependencies.deplock" + ) + expected_loc = self.get_test_loc( + "swift-vercelui-show-dependencies-parse-expected.json" + ) + packages = swift.SwiftShowDependenciesDepLockHandler.parse(test_file) + self.check_packages_data(packages, expected_loc, regen=REGEN_TEST_FIXTURES) + class TestSwiftEndtoEnd(PackageTester): test_data_dir = os.path.join(os.path.dirname(__file__), "data/swift") @@ -105,9 +133,7 @@ def test_package_scan_swift_end_to_end_full_mapboxmaps_resolved_only(self): def test_package_scan_swift_end_to_end_full_vercelui(self): test_dir = self.get_test_loc("packages/vercelui") result_file = self.get_temp_file("json") - expected_file = self.get_test_loc( - "swift-vercelui-expected.json" - ) + expected_file = self.get_test_loc("swift-vercelui-expected.json") run_scan_click( [ "--package",