From e4704aee6e8cbd3dbbe4d074fa23deb74dbf3b8f Mon Sep 17 00:00:00 2001 From: Stefan Oltmann Date: Sat, 25 May 2024 19:19:43 +0200 Subject: [PATCH] Update to Kotlin 2.0 (#100) Also other dependencies have been updated --- .gitignore | 1 + README.md | 4 +- build.gradle.kts | 46 ++++++++----------- detekt.yml | 8 ++-- .../com/ashampoo/kim/model/PhotoMetadata.kt | 41 ++++++++--------- .../ashampoo/kim/common/KotlinIoExtensions.kt | 1 - .../com/ashampoo/kim/ResourcePath.wasmWasi.kt | 18 ++++++++ 7 files changed, 63 insertions(+), 56 deletions(-) create mode 100644 src/wasmWasiTest/kotlin/com/ashampoo/kim/ResourcePath.wasmWasi.kt diff --git a/.gitignore b/.gitignore index a61dd6f8..cd33360e 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ /.idea/uiDesigner.xml /.idea/vcs.xml /.idea/workspace.xml +/.kotlin/ /build/ /local.properties /src/commonTest/resources/com/ashampoo/kim/testdata/full/*.html diff --git a/README.md b/README.md index e781af77..1c698ed7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Kim - Kotlin Image Metadata -[![Kotlin](https://img.shields.io/badge/kotlin-1.9.24-blue.svg?logo=kotlin)](httpw://kotlinlang.org) +[![Kotlin](https://img.shields.io/badge/kotlin-2.0.0-blue.svg?logo=kotlin)](httpw://kotlinlang.org) ![JVM](https://img.shields.io/badge/-JVM-gray.svg?style=flat) ![Android](https://img.shields.io/badge/-Android-gray.svg?style=flat) ![iOS](https://img.shields.io/badge/-iOS-gray.svg?style=flat) @@ -39,7 +39,7 @@ of Ashampoo Photo Organizer, which, in turn, is driven by user community feedbac ## Installation ``` -implementation("com.ashampoo:kim:0.18.2") +implementation("com.ashampoo:kim:0.18.3") ``` For the targets `wasmJs` & `js` you also need to specify this: diff --git a/build.gradle.kts b/build.gradle.kts index c6951b04..9e57a87b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl plugins { - kotlin("multiplatform") version "1.9.24" + kotlin("multiplatform") version "2.0.0" id("com.android.library") version "8.2.2" id("maven-publish") id("signing") @@ -24,11 +24,11 @@ repositories { val productName: String = "Ashampoo Kim" -val ktorVersion: String = "2.3.10" +val ktorVersion: String = "2.3.11" val xmpCoreVersion: String = "1.3.0" -val dateTimeVersion: String = "0.5.0" +val dateTimeVersion: String = "0.6.0" val testRessourcesVersion: String = "0.4.0" -val kotlinxIoVersion: String = "0.3.4" +val kotlinxIoVersion: String = "0.3.5" description = productName group = "com.ashampoo" @@ -170,20 +170,14 @@ kotlin { } } - js { - // nodejs() - } + js() @OptIn(ExperimentalWasmDsl::class) - wasmJs { - // All tests reading from files fail, because kotlinx-io - // has no Path support for WASM (yet?). - // nodejs() - } + wasmJs() -// Note: Missing support in kotlinx-datetime -// @OptIn(ExperimentalWasmDsl::class) -// wasmWasi() + // WASI support is planned for kotlinx-datetime v0.7 + // @OptIn(ExperimentalWasmDsl::class) + // wasmWasi() @Suppress("UnusedPrivateMember") // False positive val commonMain by sourceSets.getting { @@ -198,7 +192,7 @@ kotlin { } } - @Suppress("UnusedPrivateMember", "UNUSED_VARIABLE") // False positive + @Suppress("UnusedPrivateMember") // False positive val commonTest by sourceSets.getting { dependencies { @@ -268,31 +262,31 @@ kotlin { dependsOn(ktorMain) } - @Suppress("UnusedPrivateMember", "UNUSED_VARIABLE") // False positive + @Suppress("UnusedPrivateMember") // False positive val jvmMain by sourceSets.getting { dependsOn(commonMain) dependsOn(ktorMain) } - @Suppress("UnusedPrivateMember", "UNUSED_VARIABLE") // False positive + @Suppress("UnusedPrivateMember") // False positive val androidMain by sourceSets.getting { dependsOn(commonMain) dependsOn(ktorMain) } - @Suppress("UnusedPrivateMember", "UNUSED_VARIABLE") // False positive + @Suppress("UnusedPrivateMember") // False positive val winMain by sourceSets.getting { dependsOn(posixMain) } - @Suppress("UnusedPrivateMember", "UNUSED_VARIABLE") // False positive + @Suppress("UnusedPrivateMember") // False positive val linuxX64Main by sourceSets.getting { dependsOn(posixMain) } - @Suppress("UnusedPrivateMember", "UNUSED_VARIABLE") // False positive + @Suppress("UnusedPrivateMember") // False positive val linuxArm64Main by sourceSets.getting { dependsOn(posixMain) } @@ -303,7 +297,7 @@ kotlin { val macosX64Main by sourceSets.getting val macosArm64Main by sourceSets.getting - @Suppress("UnusedPrivateMember", "UNUSED_VARIABLE") // False positive + @Suppress("UnusedPrivateMember") // False positive val appleMain by sourceSets.creating { dependsOn(commonMain) @@ -323,7 +317,7 @@ kotlin { val macosX64Test by sourceSets.getting val macosArm64Test by sourceSets.getting - @Suppress("UnusedPrivateMember", "UNUSED_VARIABLE") // False positive + @Suppress("UnusedPrivateMember") // False positive val appleTest by sourceSets.creating { dependsOn(commonTest) @@ -335,20 +329,20 @@ kotlin { macosArm64Test.dependsOn(this) } - @Suppress("UnusedPrivateMember", "UNUSED_VARIABLE") // False positive + @Suppress("UnusedPrivateMember") // False positive val jsMain by sourceSets.getting { dependsOn(commonMain) dependencies { - implementation(npm("pako", "2.1.0")) + api(npm("pako", "2.1.0")) } } val wasmJsMain by sourceSets.getting // val wasmWasiMain by sourceSets.getting - @Suppress("UnusedPrivateMember", "UNUSED_VARIABLE") // False positive + @Suppress("UnusedPrivateMember") // False positive val wasmMain by sourceSets.creating { dependsOn(commonMain) diff --git a/detekt.yml b/detekt.yml index c06db502..88108b2c 100644 --- a/detekt.yml +++ b/detekt.yml @@ -130,7 +130,7 @@ complexity: active: true threshold: 600 LongMethod: - active: true + active: false threshold: 60 LongParameterList: active: false # already checked by SonarQube @@ -609,10 +609,10 @@ style: ignoreActualFunction: true excludedFunctions: [ ] LoopWithTooManyJumpStatements: - active: true + active: false maxJumpCount: 1 MagicNumber: - active: true + active: false excludes: [ '**/commonTest/**', '**/jvmTest/**' ] ignoreNumbers: - '-1' @@ -730,7 +730,7 @@ style: UnnecessaryLet: active: true UnnecessaryParentheses: - active: true + active: false allowForUnclearPrecedence: false UntilInsteadOfRangeTo: active: true diff --git a/src/commonMain/kotlin/com/ashampoo/kim/model/PhotoMetadata.kt b/src/commonMain/kotlin/com/ashampoo/kim/model/PhotoMetadata.kt index c305af63..4d425a78 100644 --- a/src/commonMain/kotlin/com/ashampoo/kim/model/PhotoMetadata.kt +++ b/src/commonMain/kotlin/com/ashampoo/kim/model/PhotoMetadata.kt @@ -17,10 +17,6 @@ package com.ashampoo.kim.model import com.ashampoo.kim.common.PhotoValueFormatter import com.ashampoo.xmp.XMPRegionArea -import kotlinx.datetime.Instant -import kotlinx.datetime.LocalDateTime -import kotlinx.datetime.TimeZone -import kotlinx.datetime.toLocalDateTime /** * Represents a high-level summary of image metadata extracted from raw ImageMetadata. @@ -68,34 +64,33 @@ public data class PhotoMetadata( ) { - val takenDateLocalDateTime: LocalDateTime? = takenDate?.let { - Instant.fromEpochMilliseconds(takenDate).toLocalDateTime(TimeZone.currentSystemDefault()) - } - - val megaPixelCount: Int = if (widthPx == null || heightPx == null) - 0 - else - (widthPx * heightPx).div(PhotoValueFormatter.MEGA_PIXEL_COUNT) + val megaPixelCount: Int + get() = if (widthPx == null || heightPx == null) + 0 + else + (widthPx * heightPx).div(PhotoValueFormatter.MEGA_PIXEL_COUNT) - val locationDisplay: String? = - location?.displayString ?: gpsCoordinates?.let { gpsCoordinates.displayString } + val locationDisplay: String? + get() = location?.displayString ?: gpsCoordinates?.let { gpsCoordinates.displayString } - val cameraName: String? = - PhotoValueFormatter.createCameraOrLensName(cameraMake, cameraModel) + val cameraName: String? + get() = PhotoValueFormatter.createCameraOrLensName(cameraMake, cameraModel) - val lensName: String? = - PhotoValueFormatter.createModifiedLensName( + val lensName: String? + get() = PhotoValueFormatter.createModifiedLensName( cameraName = cameraName, lensName = PhotoValueFormatter.createCameraOrLensName(lensMake, lensModel) ) - val cameraAndLensName: String? = PhotoValueFormatter.createCameraAndLensName( - cameraName = cameraName, - lensName = lensName - ) + val cameraAndLensName: String? + get() = PhotoValueFormatter.createCameraAndLensName( + cameraName = cameraName, + lensName = lensName + ) @Suppress("DataClassContainsFunctions") - public fun isEmpty(): Boolean = this == emptyPhotoMetadata + public fun isEmpty(): Boolean = + this == emptyPhotoMetadata /** * Combine the current metadata with the given one, diff --git a/src/ktorMain/kotlin/com/ashampoo/kim/common/KotlinIoExtensions.kt b/src/ktorMain/kotlin/com/ashampoo/kim/common/KotlinIoExtensions.kt index 506d8ed1..eb0876e2 100644 --- a/src/ktorMain/kotlin/com/ashampoo/kim/common/KotlinIoExtensions.kt +++ b/src/ktorMain/kotlin/com/ashampoo/kim/common/KotlinIoExtensions.kt @@ -56,4 +56,3 @@ public fun Path.exists(): Boolean = public fun Path.list(): Collection = SystemFileSystem.list(this) - diff --git a/src/wasmWasiTest/kotlin/com/ashampoo/kim/ResourcePath.wasmWasi.kt b/src/wasmWasiTest/kotlin/com/ashampoo/kim/ResourcePath.wasmWasi.kt new file mode 100644 index 00000000..7e6377d9 --- /dev/null +++ b/src/wasmWasiTest/kotlin/com/ashampoo/kim/ResourcePath.wasmWasi.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2024 Ashampoo GmbH & Co. KG + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.ashampoo.kim + +actual fun getPathForResource(path: String): String = path