From 5457ed0aea1bd96301288388a4773ebc0d853ceb Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Tue, 20 Feb 2024 15:38:01 +0100 Subject: [PATCH 1/3] build(Gradle): Use older syntax for an enum's `entries` This avoids the need for `KotlinCompile` task configuration here. Signed-off-by: Sebastian Schuberth --- buildSrc/build.gradle.kts | 14 -------------- .../main/kotlin/ort-kotlin-conventions.gradle.kts | 2 +- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index aa064cf49e958..9c8d90328d744 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -20,8 +20,6 @@ import org.gradle.accessors.dm.LibrariesForLibs import org.jetbrains.kotlin.gradle.dsl.JvmTarget -import org.jetbrains.kotlin.gradle.dsl.KotlinVersion -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile private val Project.libs: LibrariesForLibs get() = extensions.getByType() @@ -56,15 +54,3 @@ tasks.withType().configureEach { sourceCompatibility = maxKotlinJvmTarget.target targetCompatibility = maxKotlinJvmTarget.target } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlin.ExperimentalStdlibApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - languageVersion = KotlinVersion.KOTLIN_1_9 - jvmTarget = maxKotlinJvmTarget - } -} diff --git a/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts b/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts index bae251389e051..863951bd3a2f1 100644 --- a/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts @@ -114,7 +114,7 @@ detekt { val javaVersion = JavaVersion.current() val maxKotlinJvmTarget = runCatching { JvmTarget.fromTarget(javaVersion.majorVersion) } - .getOrDefault(JvmTarget.entries.max()) + .getOrDefault(enumValues().max()) val mergeDetektReportsTaskName = "mergeDetektReports" val mergeDetektReports = if (rootProject.tasks.findByName(mergeDetektReportsTaskName) != null) { From 5bf01bd9d27e699142f5d50a9a946ee03beaaf17 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Tue, 20 Feb 2024 15:21:13 +0100 Subject: [PATCH 2/3] build(Gradle): Use conventions to opt-in to `ExperimentalSerializationApi` This reduces code duplication and bundles `-opt-in` arguments. Note that the manual task configuration needs to stay for projects that do not use the plugin, but whose tests use experimental serialization API directly, like `ScanOssResultParserTest`. Signed-off-by: Sebastian Schuberth --- .../main/kotlin/ort-kotlin-conventions.gradle.kts | 13 ++++++++----- clients/clearly-defined/build.gradle.kts | 12 ------------ clients/nexus-iq/build.gradle.kts | 12 ------------ clients/osv/build.gradle.kts | 12 ------------ clients/scanoss/build.gradle.kts | 12 ------------ clients/vulnerable-code/build.gradle.kts | 12 ------------ evaluator/build.gradle.kts | 12 ------------ plugins/advisors/osv/build.gradle.kts | 12 ------------ plugins/package-managers/cargo/build.gradle.kts | 12 ------------ plugins/package-managers/go/build.gradle.kts | 12 ------------ plugins/package-managers/nuget/build.gradle.kts | 12 ------------ plugins/package-managers/python/build.gradle.kts | 12 ------------ plugins/package-managers/swiftpm/build.gradle.kts | 12 ------------ plugins/reporters/ctrlx/build.gradle.kts | 12 ------------ plugins/reporters/gitlab/build.gradle.kts | 12 ------------ plugins/reporters/trustsource/build.gradle.kts | 12 ------------ plugins/scanners/askalono/build.gradle.kts | 12 ------------ plugins/scanners/boyterlc/build.gradle.kts | 12 ------------ plugins/scanners/licensee/build.gradle.kts | 12 ------------ plugins/scanners/scancode/build.gradle.kts | 12 ------------ scanner/build.gradle.kts | 12 ------------ 21 files changed, 8 insertions(+), 245 deletions(-) diff --git a/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts b/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts index 863951bd3a2f1..2e0165e75a8ff 100644 --- a/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts @@ -157,11 +157,14 @@ tasks.withType().configureEach { } tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlin.contracts.ExperimentalContracts", - "-opt-in=kotlin.io.path.ExperimentalPathApi", - "-opt-in=kotlin.time.ExperimentalTime" - ) + val hasSerialization = plugins.hasPlugin(libs.plugins.kotlinSerialization.get().pluginId) + + val customCompilerArgs = buildList { + add("-opt-in=kotlin.contracts.ExperimentalContracts") + add("-opt-in=kotlin.io.path.ExperimentalPathApi") + add("-opt-in=kotlin.time.ExperimentalTime") + if (hasSerialization) add("-opt-in=kotlinx.serialization.ExperimentalSerializationApi") + } compilerOptions { allWarningsAsErrors = true diff --git a/clients/clearly-defined/build.gradle.kts b/clients/clearly-defined/build.gradle.kts index acda81dbbee4c..9e5d139a01390 100644 --- a/clients/clearly-defined/build.gradle.kts +++ b/clients/clearly-defined/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -36,13 +34,3 @@ dependencies { implementation(libs.retrofit.converter.kotlinxSerialization) implementation(libs.retrofit.converter.scalars) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/clients/nexus-iq/build.gradle.kts b/clients/nexus-iq/build.gradle.kts index 1f27aad953848..b48245d519dff 100644 --- a/clients/nexus-iq/build.gradle.kts +++ b/clients/nexus-iq/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -34,13 +32,3 @@ dependencies { implementation(libs.bundles.kotlinxSerialization) implementation(libs.retrofit.converter.kotlinxSerialization) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/clients/osv/build.gradle.kts b/clients/osv/build.gradle.kts index 7a3ade65cdbcc..232f5b45b2729 100644 --- a/clients/osv/build.gradle.kts +++ b/clients/osv/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -37,13 +35,3 @@ dependencies { testImplementation(libs.kotest.assertions.json) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/clients/scanoss/build.gradle.kts b/clients/scanoss/build.gradle.kts index bd6dd2e8aa659..fc18d89d7ef31 100644 --- a/clients/scanoss/build.gradle.kts +++ b/clients/scanoss/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -36,13 +34,3 @@ dependencies { testImplementation(libs.wiremock) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/clients/vulnerable-code/build.gradle.kts b/clients/vulnerable-code/build.gradle.kts index e05fd01b7d2d9..3ddb7d4640e08 100644 --- a/clients/vulnerable-code/build.gradle.kts +++ b/clients/vulnerable-code/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -34,13 +32,3 @@ dependencies { implementation(libs.bundles.kotlinxSerialization) implementation(libs.retrofit.converter.kotlinxSerialization) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/evaluator/build.gradle.kts b/evaluator/build.gradle.kts index 2d081e37f7e48..c8fff6d475659 100644 --- a/evaluator/build.gradle.kts +++ b/evaluator/build.gradle.kts @@ -19,8 +19,6 @@ import de.undercouch.gradle.tasks.download.Download -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -45,16 +43,6 @@ dependencies { testImplementation(libs.mockk) } -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} - tasks.register("updateOsadlMatrix") { description = "Download the OSADL matrix in JSON format and add it as a resource." group = "OSADL" diff --git a/plugins/advisors/osv/build.gradle.kts b/plugins/advisors/osv/build.gradle.kts index d4621bbbfe9de..5234720c6e8f4 100644 --- a/plugins/advisors/osv/build.gradle.kts +++ b/plugins/advisors/osv/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -35,13 +33,3 @@ dependencies { implementation(libs.cvssCalculator) implementation(libs.bundles.kotlinxSerialization) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/plugins/package-managers/cargo/build.gradle.kts b/plugins/package-managers/cargo/build.gradle.kts index 0d9bebbda4cd8..beab1e135dacb 100644 --- a/plugins/package-managers/cargo/build.gradle.kts +++ b/plugins/package-managers/cargo/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -47,13 +45,3 @@ dependencies { funTestImplementation(testFixtures(projects.analyzer)) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/plugins/package-managers/go/build.gradle.kts b/plugins/package-managers/go/build.gradle.kts index 0d9bebbda4cd8..beab1e135dacb 100644 --- a/plugins/package-managers/go/build.gradle.kts +++ b/plugins/package-managers/go/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -47,13 +45,3 @@ dependencies { funTestImplementation(testFixtures(projects.analyzer)) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/plugins/package-managers/nuget/build.gradle.kts b/plugins/package-managers/nuget/build.gradle.kts index 3d51bae330922..a2fde988bbd36 100644 --- a/plugins/package-managers/nuget/build.gradle.kts +++ b/plugins/package-managers/nuget/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -41,13 +39,3 @@ dependencies { funTestImplementation(testFixtures(projects.analyzer)) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/plugins/package-managers/python/build.gradle.kts b/plugins/package-managers/python/build.gradle.kts index 4f6fa759ffa05..3ab1adefa129f 100644 --- a/plugins/package-managers/python/build.gradle.kts +++ b/plugins/package-managers/python/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -46,13 +44,3 @@ dependencies { funTestImplementation(testFixtures(projects.analyzer)) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/plugins/package-managers/swiftpm/build.gradle.kts b/plugins/package-managers/swiftpm/build.gradle.kts index 4f6fa759ffa05..3ab1adefa129f 100644 --- a/plugins/package-managers/swiftpm/build.gradle.kts +++ b/plugins/package-managers/swiftpm/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -46,13 +44,3 @@ dependencies { funTestImplementation(testFixtures(projects.analyzer)) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/plugins/reporters/ctrlx/build.gradle.kts b/plugins/reporters/ctrlx/build.gradle.kts index 3bacc555c0ced..49ff7411ee526 100644 --- a/plugins/reporters/ctrlx/build.gradle.kts +++ b/plugins/reporters/ctrlx/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -38,13 +36,3 @@ dependencies { funTestImplementation(testFixtures(projects.reporter)) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/plugins/reporters/gitlab/build.gradle.kts b/plugins/reporters/gitlab/build.gradle.kts index b303544bd246e..7b1b5cb96cc47 100644 --- a/plugins/reporters/gitlab/build.gradle.kts +++ b/plugins/reporters/gitlab/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -37,13 +35,3 @@ dependencies { implementation(libs.bundles.kotlinxSerialization) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/plugins/reporters/trustsource/build.gradle.kts b/plugins/reporters/trustsource/build.gradle.kts index de2939a489f6e..6571d8f15fa90 100644 --- a/plugins/reporters/trustsource/build.gradle.kts +++ b/plugins/reporters/trustsource/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -42,13 +40,3 @@ dependencies { funTestImplementation(libs.kotest.assertions.json) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/plugins/scanners/askalono/build.gradle.kts b/plugins/scanners/askalono/build.gradle.kts index 02cd0716c1ae2..0040c4de9f8dc 100644 --- a/plugins/scanners/askalono/build.gradle.kts +++ b/plugins/scanners/askalono/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -35,13 +33,3 @@ dependencies { funTestApi(testFixtures(projects.scanner)) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/plugins/scanners/boyterlc/build.gradle.kts b/plugins/scanners/boyterlc/build.gradle.kts index 02cd0716c1ae2..0040c4de9f8dc 100644 --- a/plugins/scanners/boyterlc/build.gradle.kts +++ b/plugins/scanners/boyterlc/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -35,13 +33,3 @@ dependencies { funTestApi(testFixtures(projects.scanner)) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/plugins/scanners/licensee/build.gradle.kts b/plugins/scanners/licensee/build.gradle.kts index 02cd0716c1ae2..0040c4de9f8dc 100644 --- a/plugins/scanners/licensee/build.gradle.kts +++ b/plugins/scanners/licensee/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -35,13 +33,3 @@ dependencies { funTestApi(testFixtures(projects.scanner)) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/plugins/scanners/scancode/build.gradle.kts b/plugins/scanners/scancode/build.gradle.kts index 67205fc728490..ca100b0834ce0 100644 --- a/plugins/scanners/scancode/build.gradle.kts +++ b/plugins/scanners/scancode/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply precompiled plugins. id("ort-library-conventions") @@ -45,13 +43,3 @@ dependencies { testImplementation(libs.mockk) } - -tasks.withType().configureEach { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} diff --git a/scanner/build.gradle.kts b/scanner/build.gradle.kts index f9e3e14e2d935..7fa96372d873d 100644 --- a/scanner/build.gradle.kts +++ b/scanner/build.gradle.kts @@ -17,8 +17,6 @@ * License-Filename: LICENSE */ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { // Apply core plugins. `java-test-fixtures` @@ -57,13 +55,3 @@ dependencies { testFixturesImplementation(libs.kotest.assertions.core) testFixturesImplementation(libs.kotest.runner.junit5) } - -tasks.named("compileTestKotlin") { - val customCompilerArgs = listOf( - "-opt-in=kotlinx.serialization.ExperimentalSerializationApi" - ) - - compilerOptions { - freeCompilerArgs.addAll(customCompilerArgs) - } -} From cef953178d249e4b8bd9fb86f903b523f4a037e8 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Tue, 20 Feb 2024 15:02:03 +0100 Subject: [PATCH 3/3] refactor: Use Kotlin's Base64-encoding Use Kotlin's built-in functionality as much as possible for portability. Signed-off-by: Sebastian Schuberth --- .../kotlin/ort-kotlin-conventions.gradle.kts | 1 + .../src/main/kotlin/Extensions.kt | 19 +++++++++---------- model/src/main/kotlin/Hash.kt | 7 ++++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts b/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts index 2e0165e75a8ff..07fe1fe6b4aa5 100644 --- a/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts @@ -161,6 +161,7 @@ tasks.withType().configureEach { val customCompilerArgs = buildList { add("-opt-in=kotlin.contracts.ExperimentalContracts") + add("-opt-in=kotlin.io.encoding.ExperimentalEncodingApi") add("-opt-in=kotlin.io.path.ExperimentalPathApi") add("-opt-in=kotlin.time.ExperimentalTime") if (hasSerialization) add("-opt-in=kotlinx.serialization.ExperimentalSerializationApi") diff --git a/clients/fossid-webapp/src/main/kotlin/Extensions.kt b/clients/fossid-webapp/src/main/kotlin/Extensions.kt index 2c22a7d4a3998..54fd0a0f6a53b 100644 --- a/clients/fossid-webapp/src/main/kotlin/Extensions.kt +++ b/clients/fossid-webapp/src/main/kotlin/Extensions.kt @@ -22,7 +22,8 @@ package org.ossreviewtoolkit.clients.fossid import java.io.File -import java.util.Base64 + +import kotlin.io.encoding.Base64 import okio.buffer import okio.sink @@ -41,8 +42,6 @@ internal const val SCAN_GROUP = "scans" private const val FILES_AND_FOLDERS_GROUP = "files_and_folders" private const val PROJECT_GROUP = "projects" -private val base64Encoder = Base64.getEncoder() - /** * Verify that a request for the given [operation] was successful. [operation] is a free label describing the operation. * If [withDataCheck] is true, also the payload data is checked, otherwise that check is skipped. @@ -260,7 +259,7 @@ suspend fun FossIdRestService.listSnippets( scanCode: String, path: String ): PolymorphicResponseBody { - val base64Path = base64Encoder.encodeToString(path.toByteArray()) + val base64Path = Base64.encode(path.toByteArray()) return listSnippets( PostRequestBody( "get_fossid_results", @@ -285,7 +284,7 @@ suspend fun FossIdRestService.listMatchedLines( path: String, snippetId: Int ): EntityResponseBody { - val base64Path = base64Encoder.encodeToString(path.toByteArray()) + val base64Path = Base64.encode(path.toByteArray()) return listMatchedLines( PostRequestBody( "get_matched_lines", @@ -463,7 +462,7 @@ suspend fun FossIdRestService.markAsIdentified( path: String, isDirectory: Boolean ): EntityResponseBody { - val base64Path = base64Encoder.encodeToString(path.toByteArray()) + val base64Path = Base64.encode(path.toByteArray()) val directoryFlag = if (isDirectory) "1" else "0" return markAsIdentified( PostRequestBody( @@ -488,7 +487,7 @@ suspend fun FossIdRestService.unmarkAsIdentified( path: String, isDirectory: Boolean ): EntityResponseBody { - val base64Path = base64Encoder.encodeToString(path.toByteArray()) + val base64Path = Base64.encode(path.toByteArray()) val directoryFlag = if (isDirectory) "1" else "0" return unmarkAsIdentified( PostRequestBody( @@ -515,7 +514,7 @@ suspend fun FossIdRestService.addLicenseIdentification( identificationOn: LicenseMatchType, isDirectory: Boolean ): EntityResponseBody { - val base64Path = base64Encoder.encodeToString(path.toByteArray()) + val base64Path = Base64.encode(path.toByteArray()) val directoryFlag = if (isDirectory) "1" else "0" return addLicenseIdentification( PostRequestBody( @@ -552,7 +551,7 @@ suspend fun FossIdRestService.addComponentIdentification( isDirectory: Boolean, preserveExistingIdentifications: Boolean = true ): EntityResponseBody { - val base64Path = base64Encoder.encodeToString(path.toByteArray()) + val base64Path = Base64.encode(path.toByteArray()) val directoryFlag = if (isDirectory) "1" else "0" val preserveExistingIdentificationsFlag = if (preserveExistingIdentifications) "1" else "0" return addComponentIdentification( @@ -587,7 +586,7 @@ suspend fun FossIdRestService.addFileComment( isImportant: Boolean = false, includeInReport: Boolean = false ): EntityResponseBody { - val base64Path = base64Encoder.encodeToString(path.toByteArray()) + val base64Path = Base64.encode(path.toByteArray()) val isImportantFlag = if (isImportant) "1" else "0" val includeInReportFlag = if (includeInReport) "1" else "0" return addFileComment( diff --git a/model/src/main/kotlin/Hash.kt b/model/src/main/kotlin/Hash.kt index f529067dc6a64..4f5b6df55b2d2 100644 --- a/model/src/main/kotlin/Hash.kt +++ b/model/src/main/kotlin/Hash.kt @@ -23,7 +23,8 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize import com.fasterxml.jackson.databind.util.StdConverter import java.io.File -import java.util.Base64 + +import kotlin.io.encoding.Base64 import org.ossreviewtoolkit.utils.common.decodeHex import org.ossreviewtoolkit.utils.common.encodeHex @@ -59,7 +60,7 @@ data class Hash( // Support Subresource Integrity (SRI) hashes, see // https://w3c.github.io/webappsec-subresource-integrity/ Hash( - value = Base64.getDecoder().decode(splitValue.last()).encodeHex(), + value = Base64.decode(splitValue.last()).encodeHex(), algorithm = HashAlgorithm.fromString(splitValue.first()) ) } else { @@ -82,7 +83,7 @@ data class Hash( /** * Return the hash in Support Subresource Integrity (SRI) format. */ - fun toSri() = algorithm.name.lowercase() + "-" + Base64.getEncoder().encodeToString(value.decodeHex()) + fun toSri() = algorithm.name.lowercase() + "-" + Base64.encode(value.decodeHex()) /** * Verify that the [file] matches this hash.