From 691ef4342fd2699963e04a3c5517070f76021508 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Mon, 2 Jan 2023 12:54:28 +0100 Subject: [PATCH] model: Use an unsorted set for storing `authors` Continuing the story from [1], only sort authors on serialization. [1]: https://github.com/oss-review-toolkit/ort/pull/6244 Signed-off-by: Sebastian Schuberth --- .../kotlin/managers/SpdxDocumentFileFunTest.kt | 6 +++--- analyzer/src/main/kotlin/managers/Bower.kt | 4 ++-- analyzer/src/main/kotlin/managers/Bundler.kt | 4 ++-- analyzer/src/main/kotlin/managers/Cargo.kt | 4 ++-- analyzer/src/main/kotlin/managers/Carthage.kt | 8 ++++---- analyzer/src/main/kotlin/managers/CocoaPods.kt | 4 ++-- analyzer/src/main/kotlin/managers/Conan.kt | 4 ++-- analyzer/src/main/kotlin/managers/GoDep.kt | 4 ++-- analyzer/src/main/kotlin/managers/GoMod.kt | 4 ++-- analyzer/src/main/kotlin/managers/Gradle.kt | 2 +- analyzer/src/main/kotlin/managers/Pub.kt | 6 +++--- .../src/main/kotlin/managers/SpdxDocumentFile.kt | 12 ++++++------ analyzer/src/main/kotlin/managers/Stack.kt | 2 +- analyzer/src/main/kotlin/managers/Yarn2.kt | 3 +-- .../src/main/kotlin/managers/utils/NpmSupport.kt | 4 ++-- .../main/kotlin/managers/utils/NuGetSupport.kt | 4 ++-- .../kotlin/managers/utils/PythonInspector.kt | 6 +++--- analyzer/src/test/kotlin/managers/BundlerTest.kt | 2 +- model/src/main/kotlin/Package.kt | 7 +++++-- model/src/main/kotlin/PackageCurationData.kt | 6 ++---- model/src/main/kotlin/Project.kt | 7 +++++-- .../licenses/DefaultLicenseInfoProvider.kt | 2 +- model/src/main/kotlin/licenses/LicenseInfo.kt | 4 +--- .../src/main/kotlin/utils/SortedSetConverters.kt | 4 ++++ model/src/test/kotlin/PackageCurationDataTest.kt | 6 +++--- model/src/test/kotlin/PackageCurationTest.kt | 16 ++++++++-------- model/src/test/kotlin/PackageTest.kt | 6 +++--- .../kotlin/licenses/LicenseInfoResolverTest.kt | 3 +-- model/src/test/kotlin/licenses/TestData.kt | 4 ++-- .../test/kotlin/scanners/fossid/FossIdTest.kt | 2 +- 30 files changed, 77 insertions(+), 73 deletions(-) diff --git a/analyzer/src/funTest/kotlin/managers/SpdxDocumentFileFunTest.kt b/analyzer/src/funTest/kotlin/managers/SpdxDocumentFileFunTest.kt index 3bc31f824ae73..da77a9ad6058e 100644 --- a/analyzer/src/funTest/kotlin/managers/SpdxDocumentFileFunTest.kt +++ b/analyzer/src/funTest/kotlin/managers/SpdxDocumentFileFunTest.kt @@ -103,7 +103,7 @@ class SpdxDocumentFileFunTest : WordSpec({ id = curlId, cpe = "cpe:2.3:a:http:curl:7.70.0:*:*:*:*:*:*:*", definitionFilePath = vcsDir.getPathToRoot(curlPackageFile), - authors = sortedSetOf("Daniel Stenberg (daniel@haxx.se)"), + authors = setOf("Daniel Stenberg (daniel@haxx.se)"), declaredLicenses = sortedSetOf("curl"), vcs = VcsInfo( type = VcsType.GIT, @@ -124,7 +124,7 @@ class SpdxDocumentFileFunTest : WordSpec({ id = opensslId, cpe = "cpe:2.3:a:a-name:openssl:1.1.1g:*:*:*:*:*:*:*", definitionFilePath = vcsDir.getPathToRoot(opensslPackageFile), - authors = sortedSetOf("OpenSSL Development Team"), + authors = setOf("OpenSSL Development Team"), declaredLicenses = sortedSetOf("Apache-2.0"), vcs = VcsInfo( type = VcsType.GIT, @@ -145,7 +145,7 @@ class SpdxDocumentFileFunTest : WordSpec({ id = zlibId, cpe = "cpe:/a:compress:zlib:1.2.11:::en-us", definitionFilePath = vcsDir.getPathToRoot(zlibPackageFile), - authors = sortedSetOf("Jean-loup Gailly", "Mark Adler"), + authors = setOf("Jean-loup Gailly", "Mark Adler"), declaredLicenses = sortedSetOf("Zlib"), vcs = VcsInfo( type = VcsType.GIT, diff --git a/analyzer/src/main/kotlin/managers/Bower.kt b/analyzer/src/main/kotlin/managers/Bower.kt index 30bb2832de67d..582ae9636cf8a 100644 --- a/analyzer/src/main/kotlin/managers/Bower.kt +++ b/analyzer/src/main/kotlin/managers/Bower.kt @@ -101,8 +101,8 @@ class Bower( * there are two formats to specify the authors of a package (similar to NPM). The difference is that the * strings or objects are inside an array. */ - private fun parseAuthors(node: JsonNode): SortedSet = - sortedSetOf().apply { + private fun parseAuthors(node: JsonNode): Set = + mutableSetOf().apply { node["pkgMeta"]["authors"]?.mapNotNull { authorNode -> when { authorNode.isObject -> authorNode["name"]?.textValue() diff --git a/analyzer/src/main/kotlin/managers/Bundler.kt b/analyzer/src/main/kotlin/managers/Bundler.kt index ef3d9bd22ef62..8f5e99f18cd9a 100644 --- a/analyzer/src/main/kotlin/managers/Bundler.kt +++ b/analyzer/src/main/kotlin/managers/Bundler.kt @@ -319,7 +319,7 @@ class Bundler( name = workingDir.name, version = "", homepageUrl = "", - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = sortedSetOf(), description = "", runtimeDependencies = emptySet(), @@ -394,7 +394,7 @@ internal data class GemSpec( val name: String, val version: String, val homepageUrl: String, - val authors: SortedSet, + val authors: Set, val declaredLicenses: SortedSet, val description: String, val runtimeDependencies: Set, diff --git a/analyzer/src/main/kotlin/managers/Cargo.kt b/analyzer/src/main/kotlin/managers/Cargo.kt index 1b15510cd8552..85439e7d63546 100644 --- a/analyzer/src/main/kotlin/managers/Cargo.kt +++ b/analyzer/src/main/kotlin/managers/Cargo.kt @@ -345,5 +345,5 @@ private fun getResolvedVersion( /** * Parse information about authors from the given [node] with package metadata. */ -private fun parseAuthors(node: JsonNode?): SortedSet = - node?.mapNotNullTo(sortedSetOf()) { parseAuthorString(it.textValue()) } ?: sortedSetOf() +private fun parseAuthors(node: JsonNode?): Set = + node?.mapNotNullTo(mutableSetOf()) { parseAuthorString(it.textValue()) } ?: emptySet() diff --git a/analyzer/src/main/kotlin/managers/Carthage.kt b/analyzer/src/main/kotlin/managers/Carthage.kt index e0081e26113b0..7f6a3cb00878c 100644 --- a/analyzer/src/main/kotlin/managers/Carthage.kt +++ b/analyzer/src/main/kotlin/managers/Carthage.kt @@ -81,7 +81,7 @@ class Carthage( version = projectInfo.revision.orEmpty() ), definitionFilePath = VersionControlSystem.getPathInfo(definitionFile).path, - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = sortedSetOf(), vcs = VcsInfo.EMPTY, vcsProcessed = processProjectVcs(workingDir, VcsInfo.EMPTY), @@ -189,7 +189,7 @@ class Carthage( name = vcsHost?.getProject(projectUrl).orEmpty(), version = revision ), - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = sortedSetOf(), description = "", homepageUrl = projectUrl.removeSuffix(".git"), @@ -213,7 +213,7 @@ class Carthage( name = fileUrl.substringAfterLast("/"), version = revision ), - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = sortedSetOf(), description = "", homepageUrl = "", @@ -231,7 +231,7 @@ class Carthage( name = id.substringAfterLast("/").removeSuffix(".json"), version = revision ), - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = sortedSetOf(), description = "", homepageUrl = "", diff --git a/analyzer/src/main/kotlin/managers/CocoaPods.kt b/analyzer/src/main/kotlin/managers/CocoaPods.kt index 935f658354f35..c21c0b26ab3b6 100644 --- a/analyzer/src/main/kotlin/managers/CocoaPods.kt +++ b/analyzer/src/main/kotlin/managers/CocoaPods.kt @@ -159,7 +159,7 @@ class CocoaPods( version = "" ), definitionFilePath = VersionControlSystem.getPathInfo(definitionFile).path, - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = sortedSetOf(), vcs = VcsInfo.EMPTY, vcsProcessed = processProjectVcs(workingDir), @@ -185,7 +185,7 @@ class CocoaPods( return Package( id = id, - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = podspec.license.takeUnless { it.isEmpty() }?.let { sortedSetOf(it) } ?: sortedSetOf(), description = podspec.summary, homepageUrl = podspec.homepage, diff --git a/analyzer/src/main/kotlin/managers/Conan.kt b/analyzer/src/main/kotlin/managers/Conan.kt index 782f8a248dcd2..be1ba25962acb 100644 --- a/analyzer/src/main/kotlin/managers/Conan.kt +++ b/analyzer/src/main/kotlin/managers/Conan.kt @@ -462,6 +462,6 @@ class Conan( * Parse information about the package author from the given JSON [node]. If present, return a set containing the * author name; otherwise, return an empty set. */ - private fun parseAuthors(node: JsonNode): SortedSet = - parseAuthorString(node["author"]?.textValue(), '<', '(')?.let { sortedSetOf(it) } ?: sortedSetOf() + private fun parseAuthors(node: JsonNode): Set = + parseAuthorString(node["author"]?.textValue(), '<', '(')?.let { setOf(it) } ?: emptySet() } diff --git a/analyzer/src/main/kotlin/managers/GoDep.kt b/analyzer/src/main/kotlin/managers/GoDep.kt index fde371208c4e2..1d7279dad1ebc 100644 --- a/analyzer/src/main/kotlin/managers/GoDep.kt +++ b/analyzer/src/main/kotlin/managers/GoDep.kt @@ -135,7 +135,7 @@ class GoDep( val pkg = Package( id = Identifier("Go", "", name, normalizeModuleVersion(version)), - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = sortedSetOf(), description = "", homepageUrl = "", @@ -174,7 +174,7 @@ class GoDep( version = projectVcs.revision ), definitionFilePath = VersionControlSystem.getPathInfo(definitionFile).path, - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = sortedSetOf(), vcs = VcsInfo.EMPTY, vcsProcessed = projectVcs, diff --git a/analyzer/src/main/kotlin/managers/GoMod.kt b/analyzer/src/main/kotlin/managers/GoMod.kt index 5a1aee6406b71..b8516b1965c20 100644 --- a/analyzer/src/main/kotlin/managers/GoMod.kt +++ b/analyzer/src/main/kotlin/managers/GoMod.kt @@ -133,7 +133,7 @@ class GoMod( version = projectVcs.revision ), definitionFilePath = VersionControlSystem.getPathInfo(definitionFile).path, - authors = sortedSetOf(), // Go mod doesn't support author information. + authors = emptySet(), // Go mod doesn't support author information. declaredLicenses = sortedSetOf(), // Go mod doesn't support declared licenses. vcs = projectVcs, vcsProcessed = projectVcs, @@ -305,7 +305,7 @@ class GoMod( return Package( id = toId(), - authors = sortedSetOf(), // Go mod doesn't support author information. + authors = emptySet(), // Go mod doesn't support author information. declaredLicenses = sortedSetOf(), // Go mod doesn't support declared licenses. description = "", homepageUrl = "", diff --git a/analyzer/src/main/kotlin/managers/Gradle.kt b/analyzer/src/main/kotlin/managers/Gradle.kt index 92962f3129a09..4ae202c39644b 100644 --- a/analyzer/src/main/kotlin/managers/Gradle.kt +++ b/analyzer/src/main/kotlin/managers/Gradle.kt @@ -258,7 +258,7 @@ class Gradle( val project = Project( id = projectId, definitionFilePath = VersionControlSystem.getPathInfo(definitionFile).path, - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = sortedSetOf(), vcs = VcsInfo.EMPTY, vcsProcessed = processProjectVcs(definitionFile.parentFile), diff --git a/analyzer/src/main/kotlin/managers/Pub.kt b/analyzer/src/main/kotlin/managers/Pub.kt index 5991d61152080..6baaffe445328 100644 --- a/analyzer/src/main/kotlin/managers/Pub.kt +++ b/analyzer/src/main/kotlin/managers/Pub.kt @@ -473,7 +473,7 @@ class Pub( var rawName = "" var homepageUrl = "" var vcs = VcsInfo.EMPTY - var authors: SortedSet = sortedSetOf() + var authors = mutableSetOf() when { pkgInfoFromLockFile["source"].textValueOrEmpty() == "path" -> { @@ -672,8 +672,8 @@ class Pub( /** * Extract information about package authors from the given [pubspec]. */ -private fun parseAuthors(pubspec: JsonNode): SortedSet = - (listOfNotNull(pubspec["author"]) + pubspec["authors"]?.toList().orEmpty()).mapNotNullTo(sortedSetOf()) { +private fun parseAuthors(pubspec: JsonNode): MutableSet = + (setOfNotNull(pubspec["author"]) + pubspec["authors"]?.toSet().orEmpty()).mapNotNullTo(mutableSetOf()) { parseAuthorString(it.textValue()) } diff --git a/analyzer/src/main/kotlin/managers/SpdxDocumentFile.kt b/analyzer/src/main/kotlin/managers/SpdxDocumentFile.kt index a25e639c6c30d..3c3c7e86720ff 100644 --- a/analyzer/src/main/kotlin/managers/SpdxDocumentFile.kt +++ b/analyzer/src/main/kotlin/managers/SpdxDocumentFile.kt @@ -199,20 +199,20 @@ private fun String.sanitize(): String = replace(':', ' ').collapseWhitespace() /** * Wrap any "present" SPDX value in a sorted set, or return an empty sorted set otherwise. */ -private fun String?.wrapPresentInSortedSet(): SortedSet { +private fun String?.wrapPresentInSet(): Set { if (SpdxConstants.isPresent(this)) { withoutPrefix(SpdxConstants.PERSON)?.let { persons -> // In case of a person, allow a comma-separated list of persons. - return persons.split(',').mapTo(sortedSetOf()) { it.trim() } + return persons.split(',').mapTo(mutableSetOf()) { it.trim() } } // Do not split an organization like "Acme, Inc." by comma. withoutPrefix(SpdxConstants.ORGANIZATION)?.let { - return sortedSetOf(it) + return setOf(it) } } - return sortedSetOf() + return setOf() } /** @@ -315,7 +315,7 @@ class SpdxDocumentFile( id = id, purl = locateExternalReference(SpdxExternalReference.Type.Purl) ?: id.toPurl(), cpe = locateCpe(), - authors = originator.wrapPresentInSortedSet(), + authors = originator.wrapPresentInSet(), declaredLicenses = sortedSetOf(licenseDeclared), concludedLicense = getConcludedLicense(), description = packageDescription, @@ -516,7 +516,7 @@ class SpdxDocumentFile( id = projectPackage.toIdentifier(), cpe = projectPackage.locateCpe(), definitionFilePath = VersionControlSystem.getPathInfo(definitionFile).path, - authors = projectPackage.originator.wrapPresentInSortedSet(), + authors = projectPackage.originator.wrapPresentInSet(), declaredLicenses = sortedSetOf(projectPackage.licenseDeclared), vcs = processProjectVcs(definitionFile.parentFile, VcsInfo.EMPTY), homepageUrl = projectPackage.homepage.mapNotPresentToEmpty(), diff --git a/analyzer/src/main/kotlin/managers/Stack.kt b/analyzer/src/main/kotlin/managers/Stack.kt index 6eec70f429826..7e24a48abc709 100644 --- a/analyzer/src/main/kotlin/managers/Stack.kt +++ b/analyzer/src/main/kotlin/managers/Stack.kt @@ -349,7 +349,7 @@ class Stack( .split(',') .map(String::trim) .filter(String::isNotEmpty) - .mapTo(sortedSetOf(), ::parseAuthorString), + .mapNotNullTo(mutableSetOf(), ::parseAuthorString), declaredLicenses = map["license"]?.let { sortedSetOf(it) } ?: sortedSetOf(), description = map["description"].orEmpty(), homepageUrl = homepageUrl, diff --git a/analyzer/src/main/kotlin/managers/Yarn2.kt b/analyzer/src/main/kotlin/managers/Yarn2.kt index e813cf03537b0..1534fa4e1f6e2 100644 --- a/analyzer/src/main/kotlin/managers/Yarn2.kt +++ b/analyzer/src/main/kotlin/managers/Yarn2.kt @@ -28,7 +28,6 @@ import com.fasterxml.jackson.module.kotlin.readValues import com.vdurmont.semver4j.Requirement import java.io.File -import java.util.SortedSet import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async @@ -742,6 +741,6 @@ class Yarn2( val homepage: String = "", val downloadUrl: String = "", val hash: Hash = Hash.NONE, - val author: SortedSet = emptySet().toSortedSet() + val author: Set = emptySet() ) } diff --git a/analyzer/src/main/kotlin/managers/utils/NpmSupport.kt b/analyzer/src/main/kotlin/managers/utils/NpmSupport.kt index e25c6535f5954..add698c5ca08f 100644 --- a/analyzer/src/main/kotlin/managers/utils/NpmSupport.kt +++ b/analyzer/src/main/kotlin/managers/utils/NpmSupport.kt @@ -324,8 +324,8 @@ private fun getYarnWorkspaceSubmodules(definitionFiles: Set): Set { * https://docs.npmjs.com/files/package.json#people-fields-author-contributors, there are two formats to * specify the author of a package: An object with multiple properties or a single string. */ -fun parseNpmAuthors(json: JsonNode): SortedSet = - sortedSetOf().apply { +fun parseNpmAuthors(json: JsonNode): Set = + mutableSetOf().apply { json["author"]?.let { authorNode -> when { authorNode.isObject -> authorNode["name"]?.textValue() diff --git a/analyzer/src/main/kotlin/managers/utils/NuGetSupport.kt b/analyzer/src/main/kotlin/managers/utils/NuGetSupport.kt index ce45bb95a94ae..fd328ee1f2edc 100644 --- a/analyzer/src/main/kotlin/managers/utils/NuGetSupport.kt +++ b/analyzer/src/main/kotlin/managers/utils/NuGetSupport.kt @@ -339,11 +339,11 @@ private fun parseLicenses(spec: PackageSpec?): SortedSet { /** * Parse information about the authors of a package from the given [spec]. */ -private fun parseAuthors(spec: PackageSpec?): SortedSet = +private fun parseAuthors(spec: PackageSpec?): Set = spec?.metadata?.authors?.split(',', ';').orEmpty() .map(String::trim) .filterNot(String::isEmpty) - .toSortedSet() + .toSet() /** * Try to find a .nuspec file for the given [definitionFile]. The file is looked up in the same directory. diff --git a/analyzer/src/main/kotlin/managers/utils/PythonInspector.kt b/analyzer/src/main/kotlin/managers/utils/PythonInspector.kt index 5c79e04bb1b3d..d2fbc81daa4be 100644 --- a/analyzer/src/main/kotlin/managers/utils/PythonInspector.kt +++ b/analyzer/src/main/kotlin/managers/utils/PythonInspector.kt @@ -202,7 +202,7 @@ internal fun PythonInspector.Result.toOrtProject( return Project( id = id, definitionFilePath = VersionControlSystem.getPathInfo(definitionFile).path, - authors = projectData?.parties?.toAuthors() ?: sortedSetOf(), + authors = projectData?.parties?.toAuthors() ?: emptySet(), declaredLicenses = projectData?.declaredLicense?.getDeclaredLicenses() ?: sortedSetOf(), vcs = VcsInfo.EMPTY, vcsProcessed = PackageManager.processProjectVcs(definitionFile.parentFile, VcsInfo.EMPTY, homepageUrl), @@ -332,8 +332,8 @@ internal fun List.toOrtPackages(): Set = ) } -private fun List.toAuthors(): SortedSet = - filter { it.role == "author" }.mapNotNullTo(sortedSetOf()) { party -> +private fun List.toAuthors(): Set = + filter { it.role == "author" }.mapNotNullTo(mutableSetOf()) { party -> buildString { party.name?.let { append(it) } party.email?.let { diff --git a/analyzer/src/test/kotlin/managers/BundlerTest.kt b/analyzer/src/test/kotlin/managers/BundlerTest.kt index a4b6ba1528669..481cc413e7dec 100644 --- a/analyzer/src/test/kotlin/managers/BundlerTest.kt +++ b/analyzer/src/test/kotlin/managers/BundlerTest.kt @@ -66,7 +66,7 @@ class BundlerTest : WordSpec({ name = "rspec", version = "3.7.0", homepageUrl = "http://github.com/rspec", - authors = sortedSetOf("Steven Baker", "David Chelimsky", "Myron Marston"), + authors = setOf("Steven Baker", "David Chelimsky", "Myron Marston"), declaredLicenses = sortedSetOf("MIT"), description = "BDD for Ruby", runtimeDependencies = setOf("rspec-core", "rspec-expectations", "rspec-mocks"), diff --git a/model/src/main/kotlin/Package.kt b/model/src/main/kotlin/Package.kt index afcdefc2bf865..d3d480119ce2a 100644 --- a/model/src/main/kotlin/Package.kt +++ b/model/src/main/kotlin/Package.kt @@ -21,9 +21,11 @@ package org.ossreviewtoolkit.model import com.fasterxml.jackson.annotation.JsonAlias import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.databind.annotation.JsonSerialize import java.util.SortedSet +import org.ossreviewtoolkit.model.utils.StringSortedSetConverter import org.ossreviewtoolkit.model.utils.toPurl import org.ossreviewtoolkit.utils.ort.DeclaredLicenseProcessor import org.ossreviewtoolkit.utils.ort.ProcessedDeclaredLicense @@ -61,7 +63,8 @@ data class Package( * The set of authors declared for this package. */ @JsonInclude(JsonInclude.Include.NON_DEFAULT) - val authors: SortedSet = sortedSetOf(), + @JsonSerialize(converter = StringSortedSetConverter::class) + val authors: Set = emptySet(), /** * The set of licenses declared for this package. This does not necessarily correspond to the licenses as detected @@ -139,7 +142,7 @@ data class Package( val EMPTY = Package( id = Identifier.EMPTY, purl = "", - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = sortedSetOf(), declaredLicensesProcessed = ProcessedDeclaredLicense.EMPTY, concludedLicense = null, diff --git a/model/src/main/kotlin/PackageCurationData.kt b/model/src/main/kotlin/PackageCurationData.kt index 6b454353847a2..dff8e8a70a334 100644 --- a/model/src/main/kotlin/PackageCurationData.kt +++ b/model/src/main/kotlin/PackageCurationData.kt @@ -22,8 +22,6 @@ package org.ossreviewtoolkit.model import com.fasterxml.jackson.annotation.JsonAlias import com.fasterxml.jackson.annotation.JsonInclude -import java.util.SortedSet - import org.ossreviewtoolkit.utils.common.zip import org.ossreviewtoolkit.utils.ort.DeclaredLicenseProcessor import org.ossreviewtoolkit.utils.spdx.SpdxExpression @@ -54,7 +52,7 @@ data class PackageCurationData( /** * The set of authors of the package. */ - val authors: SortedSet? = null, + val authors: Set? = null, /** * The concluded license as an [SpdxExpression]. It can be used to override the [declared][Package.declaredLicenses] @@ -171,7 +169,7 @@ data class PackageCurationData( comment = setOfNotNull(comment, other.comment).joinToString("\n").takeIf { it.isNotEmpty() }, purl = purl ?: other.purl, cpe = cpe ?: other.cpe, - authors = (authors.orEmpty() + other.authors.orEmpty()).toSortedSet(), + authors = authors.orEmpty() + other.authors.orEmpty(), concludedLicense = setOfNotNull(concludedLicense, other.concludedLicense).reduce(SpdxExpression::and), description = description ?: other.description, homepageUrl = homepageUrl ?: other.homepageUrl, diff --git a/model/src/main/kotlin/Project.kt b/model/src/main/kotlin/Project.kt index 1169fb1d7322d..933d5f8eb2ce9 100644 --- a/model/src/main/kotlin/Project.kt +++ b/model/src/main/kotlin/Project.kt @@ -22,9 +22,11 @@ package org.ossreviewtoolkit.model import com.fasterxml.jackson.annotation.JsonIgnore import com.fasterxml.jackson.annotation.JsonInclude import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.databind.annotation.JsonSerialize import java.util.SortedSet +import org.ossreviewtoolkit.model.utils.StringSortedSetConverter import org.ossreviewtoolkit.utils.ort.DeclaredLicenseProcessor import org.ossreviewtoolkit.utils.ort.ProcessedDeclaredLicense import org.ossreviewtoolkit.utils.spdx.SpdxExpression @@ -58,7 +60,8 @@ data class Project( * The set of authors declared for this project. */ @JsonInclude(JsonInclude.Include.NON_DEFAULT) - val authors: SortedSet = sortedSetOf(), + @JsonSerialize(converter = StringSortedSetConverter::class) + val authors: Set = emptySet(), /** * The set of licenses declared for this project. This does not necessarily correspond to the licenses as detected @@ -112,7 +115,7 @@ data class Project( val EMPTY = Project( id = Identifier.EMPTY, definitionFilePath = "", - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = sortedSetOf(), declaredLicensesProcessed = ProcessedDeclaredLicense.EMPTY, vcs = VcsInfo.EMPTY, diff --git a/model/src/main/kotlin/licenses/DefaultLicenseInfoProvider.kt b/model/src/main/kotlin/licenses/DefaultLicenseInfoProvider.kt index c8319e2dca78b..98b5a2719904e 100644 --- a/model/src/main/kotlin/licenses/DefaultLicenseInfoProvider.kt +++ b/model/src/main/kotlin/licenses/DefaultLicenseInfoProvider.kt @@ -73,7 +73,7 @@ class DefaultLicenseInfoProvider( appliedCurations = curations.filter { it.curation.declaredLicenseMapping.isNotEmpty() } ) } ?: DeclaredLicenseInfo( - authors = sortedSetOf(), + authors = emptySet(), licenses = emptySet(), processed = ProcessedDeclaredLicense(null), appliedCurations = emptyList() diff --git a/model/src/main/kotlin/licenses/LicenseInfo.kt b/model/src/main/kotlin/licenses/LicenseInfo.kt index f89da720765a8..5f5b95bc70c5f 100644 --- a/model/src/main/kotlin/licenses/LicenseInfo.kt +++ b/model/src/main/kotlin/licenses/LicenseInfo.kt @@ -19,8 +19,6 @@ package org.ossreviewtoolkit.model.licenses -import java.util.SortedSet - import org.ossreviewtoolkit.model.CopyrightFinding import org.ossreviewtoolkit.model.Identifier import org.ossreviewtoolkit.model.LicenseFinding @@ -80,7 +78,7 @@ data class DeclaredLicenseInfo( /** * The set of authors. */ - val authors: SortedSet, + val authors: Set, /** * The unmodified set of declared licenses. diff --git a/model/src/main/kotlin/utils/SortedSetConverters.kt b/model/src/main/kotlin/utils/SortedSetConverters.kt index 64792d73c574f..d320b95f6cd26 100644 --- a/model/src/main/kotlin/utils/SortedSetConverters.kt +++ b/model/src/main/kotlin/utils/SortedSetConverters.kt @@ -31,4 +31,8 @@ class PackageSortedSetConverter : StdConverter, SortedSet> override fun convert(value: Set) = value.toSortedSet(compareBy { it.id }) } +class StringSortedSetConverter : StdConverter, SortedSet>() { + override fun convert(value: Set) = value.toSortedSet() +} + // TODO: Add more converters to get rid of Comparable implementations that just serve sorted output. diff --git a/model/src/test/kotlin/PackageCurationDataTest.kt b/model/src/test/kotlin/PackageCurationDataTest.kt index 9b9c89c9e61fc..22e25f7980b6f 100644 --- a/model/src/test/kotlin/PackageCurationDataTest.kt +++ b/model/src/test/kotlin/PackageCurationDataTest.kt @@ -29,7 +29,7 @@ class PackageCurationDataTest : WordSpec({ comment = "original", purl = "original", cpe = "original", - authors = sortedSetOf("original"), + authors = setOf("original"), concludedLicense = "original".toSpdx(), description = "original", homepageUrl = "original", @@ -56,7 +56,7 @@ class PackageCurationDataTest : WordSpec({ comment = "other", purl = "other", cpe = "other", - authors = sortedSetOf("other"), + authors = setOf("other"), concludedLicense = "other".toSpdx(), description = "other", homepageUrl = "other", @@ -109,7 +109,7 @@ class PackageCurationDataTest : WordSpec({ "keep existing original data" { original.merge(other) shouldBe original.copy( comment = "original\nother", - authors = sortedSetOf("original", "other"), + authors = setOf("original", "other"), concludedLicense = "original AND other".toSpdx(), declaredLicenseMapping = mapOf( "original" to "original".toSpdx(), diff --git a/model/src/test/kotlin/PackageCurationTest.kt b/model/src/test/kotlin/PackageCurationTest.kt index 3b0b39f5ac448..92249faa79867 100644 --- a/model/src/test/kotlin/PackageCurationTest.kt +++ b/model/src/test/kotlin/PackageCurationTest.kt @@ -40,7 +40,7 @@ class PackageCurationTest : WordSpec({ name = "hamcrest-core", version = "1.3" ), - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = sortedSetOf("license a", "license b"), description = "", homepageUrl = "", @@ -56,7 +56,7 @@ class PackageCurationTest : WordSpec({ data = PackageCurationData( purl = "pkg:maven/org.hamcrest/hamcrest-core@1.3#subpath=src/main/java/org/hamcrest/core", cpe = "cpe:2.3:a:apache:commons_io:2.8.0:rc2:*:*:*:*:*:*", - authors = sortedSetOf("author 1", "author 2"), + authors = setOf("author 1", "author 2"), declaredLicenseMapping = mapOf("license a" to "Apache-2.0".toSpdx()), concludedLicense = "license1 OR license2".toSpdx(), description = "description", @@ -115,7 +115,7 @@ class PackageCurationTest : WordSpec({ version = "1.3" ), cpe = "cpe:2.3:a:apache:commons_io:2.8.0:rc2:*:*:*:*:*:*", - authors = sortedSetOf("author 1", "author 2"), + authors = setOf("author 1", "author 2"), declaredLicenses = sortedSetOf("license a", "license b"), description = "description", homepageUrl = "homepageUrl", @@ -177,7 +177,7 @@ class PackageCurationTest : WordSpec({ name = "hamcrest-core", version = "1.3" ), - authors = sortedSetOf("author 1", "author 2"), + authors = setOf("author 1", "author 2"), declaredLicenses = sortedSetOf("license a", "license b"), description = "description", homepageUrl = "homepageUrl", @@ -217,7 +217,7 @@ class PackageCurationTest : WordSpec({ name = "hamcrest-core", version = "1.3" ), - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = sortedSetOf(), description = "", homepageUrl = "", @@ -251,7 +251,7 @@ class PackageCurationTest : WordSpec({ name = "hamcrest-core", version = "1.3" ), - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = sortedSetOf(), description = "", homepageUrl = "", @@ -281,7 +281,7 @@ class PackageCurationTest : WordSpec({ name = "hamcrest-core", version = "1.3" ), - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = sortedSetOf(), description = "", homepageUrl = "", @@ -376,7 +376,7 @@ class PackageCurationTest : WordSpec({ "accumulate the map entries and override the entries with same key" { val pkg = Package( id = Identifier("type", "namespace", "name", "version"), - authors = sortedSetOf(), + authors = emptySet(), declaredLicenses = sortedSetOf("license a", "license b", "license c"), description = "", homepageUrl = "", diff --git a/model/src/test/kotlin/PackageTest.kt b/model/src/test/kotlin/PackageTest.kt index 7c69056b621a5..eba9749332911 100644 --- a/model/src/test/kotlin/PackageTest.kt +++ b/model/src/test/kotlin/PackageTest.kt @@ -43,7 +43,7 @@ class PackageTest : StringSpec({ name = "name", version = "version" ), - authors = sortedSetOf("author"), + authors = setOf("author"), declaredLicenses = sortedSetOf("declared license"), description = "description", homepageUrl = "homepageUrl", @@ -61,7 +61,7 @@ class PackageTest : StringSpec({ name = "name", version = "version" ), - authors = sortedSetOf("other author"), + authors = setOf("other author"), declaredLicenses = sortedSetOf("other declared license"), description = "other description", homepageUrl = "other homepageUrl", @@ -92,7 +92,7 @@ class PackageTest : StringSpec({ name = "name", version = "version" ), - authors = sortedSetOf("author"), + authors = setOf("author"), declaredLicenses = sortedSetOf("declared license"), description = "description", homepageUrl = "homepageUrl", diff --git a/model/src/test/kotlin/licenses/LicenseInfoResolverTest.kt b/model/src/test/kotlin/licenses/LicenseInfoResolverTest.kt index 313a801553931..94c5fe52fbe56 100644 --- a/model/src/test/kotlin/licenses/LicenseInfoResolverTest.kt +++ b/model/src/test/kotlin/licenses/LicenseInfoResolverTest.kt @@ -36,7 +36,6 @@ import io.kotest.matchers.types.shouldBeTypeOf import java.io.File import java.lang.IllegalArgumentException -import java.util.SortedSet import org.ossreviewtoolkit.model.ArtifactProvenance import org.ossreviewtoolkit.model.CopyrightFinding @@ -675,7 +674,7 @@ private fun createResolver( private fun createLicenseInfo( id: Identifier, - authors: SortedSet = sortedSetOf(), + authors: Set = emptySet(), declaredLicenses: Set = emptySet(), detectedLicenses: List = emptyList(), concludedLicense: SpdxExpression? = null diff --git a/model/src/test/kotlin/licenses/TestData.kt b/model/src/test/kotlin/licenses/TestData.kt index bc817c9525730..0716f2d450fae 100644 --- a/model/src/test/kotlin/licenses/TestData.kt +++ b/model/src/test/kotlin/licenses/TestData.kt @@ -43,8 +43,8 @@ import org.ossreviewtoolkit.model.config.RepositoryConfiguration import org.ossreviewtoolkit.utils.ort.DeclaredLicenseProcessor import org.ossreviewtoolkit.utils.spdx.toSpdx -val authors = sortedSetOf("The Author", "The Other Author") -val projectAuthors = sortedSetOf("The Project Author") +val authors = setOf("The Author", "The Other Author") +val projectAuthors = setOf("The Project Author") val concludedLicense = "LicenseRef-a AND LicenseRef-b".toSpdx() val declaredLicenses = sortedSetOf("LicenseRef-a", "LicenseRef-b") diff --git a/scanner/src/test/kotlin/scanners/fossid/FossIdTest.kt b/scanner/src/test/kotlin/scanners/fossid/FossIdTest.kt index c6b05cfae3ba3..c8528e3096385 100644 --- a/scanner/src/test/kotlin/scanners/fossid/FossIdTest.kt +++ b/scanner/src/test/kotlin/scanners/fossid/FossIdTest.kt @@ -947,7 +947,7 @@ private fun createIdentifier(index: Int = 1): Identifier = * Create a test [Package] with the given [id] , [vcsInfo], and [authors]. */ private fun createPackage(id: Identifier, vcsInfo: VcsInfo, authors: Set = emptySet()): Package = - Package.EMPTY.copy(id = id, vcsProcessed = vcsInfo, authors = authors.toSortedSet()) + Package.EMPTY.copy(id = id, vcsProcessed = vcsInfo, authors = authors) /** * Generate the path to a test file based on the given [index].