From f06f3039a275d547142be29c74a2294283a9f72e Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Thu, 14 Mar 2024 13:18:11 +0100 Subject: [PATCH 1/2] deps: Upgrade the ks3 library to version 0.6.0 See [1]. Migrate from the deprecated "typealias" package to "typealiases" as part of the upgrade to avoid compiler warnings. [1]: https://github.com/Kantis/ks3/releases/tag/v0.6.0 Signed-off-by: Sebastian Schuberth --- clients/clearly-defined/src/main/kotlin/Curation.kt | 4 ++-- clients/clearly-defined/src/main/kotlin/Definition.kt | 4 ++-- clients/nexus-iq/src/main/kotlin/NexusIqService.kt | 2 +- clients/osv/src/main/kotlin/Model.kt | 2 +- clients/osv/src/main/kotlin/OsvApiClient.kt | 2 +- gradle/libs.versions.toml | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/clients/clearly-defined/src/main/kotlin/Curation.kt b/clients/clearly-defined/src/main/kotlin/Curation.kt index bdef3ef13afc7..30ca27e84469c 100644 --- a/clients/clearly-defined/src/main/kotlin/Curation.kt +++ b/clients/clearly-defined/src/main/kotlin/Curation.kt @@ -19,8 +19,8 @@ package org.ossreviewtoolkit.clients.clearlydefined -import io.ks3.java.`typealias`.FileAsString -import io.ks3.java.`typealias`.UriAsString +import io.ks3.java.typealiases.FileAsString +import io.ks3.java.typealiases.UriAsString import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonElement diff --git a/clients/clearly-defined/src/main/kotlin/Definition.kt b/clients/clearly-defined/src/main/kotlin/Definition.kt index ef7a63efbf492..1ed2c39868981 100644 --- a/clients/clearly-defined/src/main/kotlin/Definition.kt +++ b/clients/clearly-defined/src/main/kotlin/Definition.kt @@ -19,8 +19,8 @@ package org.ossreviewtoolkit.clients.clearlydefined -import io.ks3.java.`typealias`.FileAsString -import io.ks3.java.`typealias`.UriAsString +import io.ks3.java.typealiases.FileAsString +import io.ks3.java.typealiases.UriAsString import kotlinx.serialization.Serializable diff --git a/clients/nexus-iq/src/main/kotlin/NexusIqService.kt b/clients/nexus-iq/src/main/kotlin/NexusIqService.kt index 31eb83436c1b7..fa34ceac271a0 100644 --- a/clients/nexus-iq/src/main/kotlin/NexusIqService.kt +++ b/clients/nexus-iq/src/main/kotlin/NexusIqService.kt @@ -21,7 +21,7 @@ package org.ossreviewtoolkit.clients.nexusiq import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory -import io.ks3.java.`typealias`.UriAsString +import io.ks3.java.typealiases.UriAsString import java.util.UUID diff --git a/clients/osv/src/main/kotlin/Model.kt b/clients/osv/src/main/kotlin/Model.kt index ada7f251afdd0..a1097cf4a9f30 100644 --- a/clients/osv/src/main/kotlin/Model.kt +++ b/clients/osv/src/main/kotlin/Model.kt @@ -19,7 +19,7 @@ package org.ossreviewtoolkit.clients.osv -import io.ks3.java.`typealias`.InstantAsString +import io.ks3.java.typealiases.InstantAsString import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/clients/osv/src/main/kotlin/OsvApiClient.kt b/clients/osv/src/main/kotlin/OsvApiClient.kt index 62f33c48bec73..cec43779e8f47 100644 --- a/clients/osv/src/main/kotlin/OsvApiClient.kt +++ b/clients/osv/src/main/kotlin/OsvApiClient.kt @@ -21,7 +21,7 @@ package org.ossreviewtoolkit.clients.osv import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory -import io.ks3.java.`typealias`.InstantAsString +import io.ks3.java.typealiases.InstantAsString import java.util.concurrent.Executors diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 81ec5e1693460..cfffc3ff77b80 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -36,7 +36,7 @@ kotest = "5.8.1" kotlinxCoroutines = "1.8.0" kotlinxHtml = "0.11.0" kotlinxSerialization = "1.6.3" -ks3 = "0.5.0" +ks3 = "0.6.0" tomlkt = "0.3.7" ktor = "2.3.9" log4jApi = "2.23.1" From 8b40f1243b4c9606460c46360f25c6c408738fec Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Thu, 14 Mar 2024 14:23:35 +0100 Subject: [PATCH 2/2] refactor(gitlab-reporter): Use Ks3 serializers Reduce custom code by using the new sorted collection serializers from Ks3. Signed-off-by: Sebastian Schuberth --- plugins/reporters/gitlab/build.gradle.kts | 1 + .../src/main/kotlin/GitLabLicenseModel.kt | 33 +++++++------------ 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/plugins/reporters/gitlab/build.gradle.kts b/plugins/reporters/gitlab/build.gradle.kts index 7b1b5cb96cc47..7bcca528436f7 100644 --- a/plugins/reporters/gitlab/build.gradle.kts +++ b/plugins/reporters/gitlab/build.gradle.kts @@ -34,4 +34,5 @@ dependencies { implementation(projects.utils.spdxUtils) implementation(libs.bundles.kotlinxSerialization) + implementation(libs.bundles.ks3) } diff --git a/plugins/reporters/gitlab/src/main/kotlin/GitLabLicenseModel.kt b/plugins/reporters/gitlab/src/main/kotlin/GitLabLicenseModel.kt index 637b3f3f93ed8..5afb4110f9c2e 100644 --- a/plugins/reporters/gitlab/src/main/kotlin/GitLabLicenseModel.kt +++ b/plugins/reporters/gitlab/src/main/kotlin/GitLabLicenseModel.kt @@ -19,10 +19,11 @@ package org.ossreviewtoolkit.plugins.reporters.gitlab +import io.ks3.standard.sortedListSerializer +import io.ks3.standard.sortedSetSerializer + import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable -import kotlinx.serialization.encoding.Encoder -import kotlinx.serialization.serializer private const val GITLAB_LICENSE_SCANNING_SCHEMA_VERSION_MAJOR_MINOR = "2.1" @@ -42,15 +43,13 @@ internal data class GitLabLicenseModel( /** * The complete set of licenses referred to by [dependencies]. */ - @Serializable(SortedLicenseCollectionSerializer::class) - @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") + @Serializable(SortedLicenseSetSerializer::class) val licenses: Set, /** * The list of all dependencies. */ - @Serializable(SortedDependenciesCollectionSerializer::class) - @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") + @Serializable(SortedDependenciesListSerializer::class) val dependencies: List ) { @Serializable @@ -96,27 +95,17 @@ internal data class GitLabLicenseModel( /** * The declared licenses of this dependency. */ - @Serializable(SortedStringCollectionSerializer::class) - @Suppress("SERIALIZER_TYPE_INCOMPATIBLE") + @Serializable(SortedStringSetSerializer::class) val licenses: Set ) } -private class SortedDependenciesCollectionSerializer : - KSerializer> by sortedCollectionSerializer( +private class SortedDependenciesListSerializer : + KSerializer> by sortedListSerializer( compareBy({ it.packageManager }, { it.name }, { it.version }) ) -private class SortedLicenseCollectionSerializer : - KSerializer> by sortedCollectionSerializer(compareBy { it.id }) - -private class SortedStringCollectionSerializer : - KSerializer> by sortedCollectionSerializer(compareBy { it }) +private class SortedLicenseSetSerializer : + KSerializer> by sortedSetSerializer(compareBy { it.id }) -private inline fun sortedCollectionSerializer(comparator: Comparator): KSerializer> { - val delegate = serializer>() - return object : KSerializer> by delegate { - override fun serialize(encoder: Encoder, value: Collection) = - delegate.serialize(encoder, value.sortedWith(comparator)) - } -} +private class SortedStringSetSerializer : KSerializer> by sortedSetSerializer(compareBy { it })