Skip to content

Commit

Permalink
model: Use an unsorted set for storing authors
Browse files Browse the repository at this point in the history
Continuing the story from [1], only sort authors on serialization.

[1]: #6244

Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
  • Loading branch information
sschuberth committed Jan 2, 2023
1 parent 2d29748 commit 691ef43
Show file tree
Hide file tree
Showing 30 changed files with 77 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions analyzer/src/main/kotlin/managers/Bower.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> =
sortedSetOf<String>().apply {
private fun parseAuthors(node: JsonNode): Set<String> =
mutableSetOf<String>().apply {
node["pkgMeta"]["authors"]?.mapNotNull { authorNode ->
when {
authorNode.isObject -> authorNode["name"]?.textValue()
Expand Down
4 changes: 2 additions & 2 deletions analyzer/src/main/kotlin/managers/Bundler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class Bundler(
name = workingDir.name,
version = "",
homepageUrl = "",
authors = sortedSetOf(),
authors = emptySet(),
declaredLicenses = sortedSetOf(),
description = "",
runtimeDependencies = emptySet(),
Expand Down Expand Up @@ -394,7 +394,7 @@ internal data class GemSpec(
val name: String,
val version: String,
val homepageUrl: String,
val authors: SortedSet<String>,
val authors: Set<String>,
val declaredLicenses: SortedSet<String>,
val description: String,
val runtimeDependencies: Set<String>,
Expand Down
4 changes: 2 additions & 2 deletions analyzer/src/main/kotlin/managers/Cargo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,5 @@ private fun getResolvedVersion(
/**
* Parse information about authors from the given [node] with package metadata.
*/
private fun parseAuthors(node: JsonNode?): SortedSet<String> =
node?.mapNotNullTo(sortedSetOf()) { parseAuthorString(it.textValue()) } ?: sortedSetOf()
private fun parseAuthors(node: JsonNode?): Set<String> =
node?.mapNotNullTo(mutableSetOf()) { parseAuthorString(it.textValue()) } ?: emptySet()
8 changes: 4 additions & 4 deletions analyzer/src/main/kotlin/managers/Carthage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -189,7 +189,7 @@ class Carthage(
name = vcsHost?.getProject(projectUrl).orEmpty(),
version = revision
),
authors = sortedSetOf(),
authors = emptySet(),
declaredLicenses = sortedSetOf(),
description = "",
homepageUrl = projectUrl.removeSuffix(".git"),
Expand All @@ -213,7 +213,7 @@ class Carthage(
name = fileUrl.substringAfterLast("/"),
version = revision
),
authors = sortedSetOf(),
authors = emptySet(),
declaredLicenses = sortedSetOf(),
description = "",
homepageUrl = "",
Expand All @@ -231,7 +231,7 @@ class Carthage(
name = id.substringAfterLast("/").removeSuffix(".json"),
version = revision
),
authors = sortedSetOf(),
authors = emptySet(),
declaredLicenses = sortedSetOf(),
description = "",
homepageUrl = "",
Expand Down
4 changes: 2 additions & 2 deletions analyzer/src/main/kotlin/managers/CocoaPods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class CocoaPods(
version = ""
),
definitionFilePath = VersionControlSystem.getPathInfo(definitionFile).path,
authors = sortedSetOf(),
authors = emptySet(),
declaredLicenses = sortedSetOf(),
vcs = VcsInfo.EMPTY,
vcsProcessed = processProjectVcs(workingDir),
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions analyzer/src/main/kotlin/managers/Conan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> =
parseAuthorString(node["author"]?.textValue(), '<', '(')?.let { sortedSetOf(it) } ?: sortedSetOf()
private fun parseAuthors(node: JsonNode): Set<String> =
parseAuthorString(node["author"]?.textValue(), '<', '(')?.let { setOf(it) } ?: emptySet()
}
4 changes: 2 additions & 2 deletions analyzer/src/main/kotlin/managers/GoDep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class GoDep(

val pkg = Package(
id = Identifier("Go", "", name, normalizeModuleVersion(version)),
authors = sortedSetOf(),
authors = emptySet(),
declaredLicenses = sortedSetOf(),
description = "",
homepageUrl = "",
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions analyzer/src/main/kotlin/managers/GoMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = "",
Expand Down
2 changes: 1 addition & 1 deletion analyzer/src/main/kotlin/managers/Gradle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions analyzer/src/main/kotlin/managers/Pub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ class Pub(
var rawName = ""
var homepageUrl = ""
var vcs = VcsInfo.EMPTY
var authors: SortedSet<String> = sortedSetOf<String>()
var authors = mutableSetOf<String>()

when {
pkgInfoFromLockFile["source"].textValueOrEmpty() == "path" -> {
Expand Down Expand Up @@ -672,8 +672,8 @@ class Pub(
/**
* Extract information about package authors from the given [pubspec].
*/
private fun parseAuthors(pubspec: JsonNode): SortedSet<String> =
(listOfNotNull(pubspec["author"]) + pubspec["authors"]?.toList().orEmpty()).mapNotNullTo(sortedSetOf()) {
private fun parseAuthors(pubspec: JsonNode): MutableSet<String> =
(setOfNotNull(pubspec["author"]) + pubspec["authors"]?.toSet().orEmpty()).mapNotNullTo(mutableSetOf()) {
parseAuthorString(it.textValue())
}

Expand Down
12 changes: 6 additions & 6 deletions analyzer/src/main/kotlin/managers/SpdxDocumentFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
private fun String?.wrapPresentInSet(): Set<String> {
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()
}

/**
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion analyzer/src/main/kotlin/managers/Stack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions analyzer/src/main/kotlin/managers/Yarn2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -742,6 +741,6 @@ class Yarn2(
val homepage: String = "",
val downloadUrl: String = "",
val hash: Hash = Hash.NONE,
val author: SortedSet<String> = emptySet<String>().toSortedSet()
val author: Set<String> = emptySet()
)
}
4 changes: 2 additions & 2 deletions analyzer/src/main/kotlin/managers/utils/NpmSupport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ private fun getYarnWorkspaceSubmodules(definitionFiles: Set<File>): Set<File> {
* 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<String> =
sortedSetOf<String>().apply {
fun parseNpmAuthors(json: JsonNode): Set<String> =
mutableSetOf<String>().apply {
json["author"]?.let { authorNode ->
when {
authorNode.isObject -> authorNode["name"]?.textValue()
Expand Down
4 changes: 2 additions & 2 deletions analyzer/src/main/kotlin/managers/utils/NuGetSupport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,11 @@ private fun parseLicenses(spec: PackageSpec?): SortedSet<String> {
/**
* Parse information about the authors of a package from the given [spec].
*/
private fun parseAuthors(spec: PackageSpec?): SortedSet<String> =
private fun parseAuthors(spec: PackageSpec?): Set<String> =
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.
Expand Down
6 changes: 3 additions & 3 deletions analyzer/src/main/kotlin/managers/utils/PythonInspector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -332,8 +332,8 @@ internal fun List<PythonInspector.Package>.toOrtPackages(): Set<Package> =
)
}

private fun List<PythonInspector.Party>.toAuthors(): SortedSet<String> =
filter { it.role == "author" }.mapNotNullTo(sortedSetOf()) { party ->
private fun List<PythonInspector.Party>.toAuthors(): Set<String> =
filter { it.role == "author" }.mapNotNullTo(mutableSetOf()) { party ->
buildString {
party.name?.let { append(it) }
party.email?.let {
Expand Down
2 changes: 1 addition & 1 deletion analyzer/src/test/kotlin/managers/BundlerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
7 changes: 5 additions & 2 deletions model/src/main/kotlin/Package.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,7 +63,8 @@ data class Package(
* The set of authors declared for this package.
*/
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
val authors: SortedSet<String> = sortedSetOf(),
@JsonSerialize(converter = StringSortedSetConverter::class)
val authors: Set<String> = emptySet(),

/**
* The set of licenses declared for this package. This does not necessarily correspond to the licenses as detected
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions model/src/main/kotlin/PackageCurationData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -54,7 +52,7 @@ data class PackageCurationData(
/**
* The set of authors of the package.
*/
val authors: SortedSet<String>? = null,
val authors: Set<String>? = null,

/**
* The concluded license as an [SpdxExpression]. It can be used to override the [declared][Package.declaredLicenses]
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 691ef43

Please sign in to comment.