Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ks3 upgrade #8417

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clients/clearly-defined/src/main/kotlin/Curation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions clients/clearly-defined/src/main/kotlin/Definition.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion clients/nexus-iq/src/main/kotlin/NexusIqService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion clients/osv/src/main/kotlin/Model.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clients/osv/src/main/kotlin/OsvApiClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions plugins/reporters/gitlab/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ dependencies {
implementation(projects.utils.spdxUtils)

implementation(libs.bundles.kotlinxSerialization)
implementation(libs.bundles.ks3)
}
33 changes: 11 additions & 22 deletions plugins/reporters/gitlab/src/main/kotlin/GitLabLicenseModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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<License>,

/**
* The list of all dependencies.
*/
@Serializable(SortedDependenciesCollectionSerializer::class)
@Suppress("SERIALIZER_TYPE_INCOMPATIBLE")
@Serializable(SortedDependenciesListSerializer::class)
val dependencies: List<Dependency>
) {
@Serializable
Expand Down Expand Up @@ -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<String>
)
}

private class SortedDependenciesCollectionSerializer :
KSerializer<Collection<GitLabLicenseModel.Dependency>> by sortedCollectionSerializer(
private class SortedDependenciesListSerializer :
KSerializer<List<GitLabLicenseModel.Dependency>> by sortedListSerializer(
compareBy({ it.packageManager }, { it.name }, { it.version })
)

private class SortedLicenseCollectionSerializer :
KSerializer<Collection<GitLabLicenseModel.License>> by sortedCollectionSerializer(compareBy { it.id })

private class SortedStringCollectionSerializer :
KSerializer<Collection<String>> by sortedCollectionSerializer(compareBy { it })
private class SortedLicenseSetSerializer :
KSerializer<Set<GitLabLicenseModel.License>> by sortedSetSerializer(compareBy { it.id })

private inline fun <reified T> sortedCollectionSerializer(comparator: Comparator<in T>): KSerializer<Collection<T>> {
val delegate = serializer<Collection<T>>()
return object : KSerializer<Collection<T>> by delegate {
override fun serialize(encoder: Encoder, value: Collection<T>) =
delegate.serialize(encoder, value.sortedWith(comparator))
}
}
private class SortedStringSetSerializer : KSerializer<Set<String>> by sortedSetSerializer(compareBy { it })
Loading