From 0dbb4d3629f037a7ca2950dc0d7c3f0cf6de44c2 Mon Sep 17 00:00:00 2001 From: DatLag Date: Thu, 29 Feb 2024 14:22:04 +0100 Subject: [PATCH 1/3] mark library serializable --- aboutlibraries-core/build.gradle.kts | 1 + .../aboutlibraries/entity/Developer.kt | 8 ++++-- .../mikepenz/aboutlibraries/entity/Funding.kt | 8 ++++-- .../mikepenz/aboutlibraries/entity/Library.kt | 25 +++++++++++-------- .../mikepenz/aboutlibraries/entity/License.kt | 16 +++++++----- .../aboutlibraries/entity/Organization.kt | 8 ++++-- .../com/mikepenz/aboutlibraries/entity/Scm.kt | 10 +++++--- 7 files changed, 50 insertions(+), 26 deletions(-) diff --git a/aboutlibraries-core/build.gradle.kts b/aboutlibraries-core/build.gradle.kts index 5b057dadf..813f95309 100644 --- a/aboutlibraries-core/build.gradle.kts +++ b/aboutlibraries-core/build.gradle.kts @@ -7,6 +7,7 @@ plugins { id("com.android.library") id("org.jetbrains.dokka") id("com.vanniktech.maven.publish") + kotlin("plugin.serialization") version "1.9.22" } android { diff --git a/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Developer.kt b/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Developer.kt index 1b8d2715a..0a407f6a2 100644 --- a/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Developer.kt +++ b/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Developer.kt @@ -1,5 +1,8 @@ package com.mikepenz.aboutlibraries.entity +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + /** * Describes the [Developer] defined in the `pom.xml` file. * @@ -8,7 +11,8 @@ package com.mikepenz.aboutlibraries.entity * @param name of the developer * @param organisationUrl optional organisation url for the developer */ +@Serializable data class Developer( - val name: String?, - val organisationUrl: String? + @SerialName("name") val name: String?, + @SerialName("organisationUrl") val organisationUrl: String? ) \ No newline at end of file diff --git a/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Funding.kt b/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Funding.kt index 9e0dfdefa..d71e1c8c9 100644 --- a/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Funding.kt +++ b/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Funding.kt @@ -1,5 +1,8 @@ package com.mikepenz.aboutlibraries.entity +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + /** * Describes the [Funding] as defined by the dependency. * This is only supported for projects hosted for dependencies hosted on: https://github.com/mikepenz/AboutLibraries#special-repository-support @@ -8,7 +11,8 @@ package com.mikepenz.aboutlibraries.entity * @param platform name of the platform allowing to fund the project * @param url url pointing towards the location to fund the project */ +@Serializable data class Funding( - val platform: String, - val url: String + @SerialName("platform") val platform: String, + @SerialName("url") val url: String ) \ No newline at end of file diff --git a/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Library.kt b/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Library.kt index 0ba21e347..fff97ae2b 100644 --- a/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Library.kt +++ b/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Library.kt @@ -3,6 +3,8 @@ package com.mikepenz.aboutlibraries.entity import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableSet import kotlinx.collections.immutable.persistentSetOf +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable /** * Describes a complete [Library] element, specifying important information about a used dependency. @@ -18,18 +20,19 @@ import kotlinx.collections.immutable.persistentSetOf * @param licenses all identified licenses for this artifact * @param funding all identified funding opportunities for this artifact */ +@Serializable data class Library( - val uniqueId: String, - val artifactVersion: String?, - val name: String, - val description: String?, - val website: String?, - val developers: ImmutableList, - val organization: Organization?, - val scm: Scm?, - val licenses: ImmutableSet = persistentSetOf(), - val funding: ImmutableSet = persistentSetOf(), - val tag: String? = null, + @SerialName("uniqueId") val uniqueId: String, + @SerialName("artifactVersion") val artifactVersion: String?, + @SerialName("name") val name: String, + @SerialName("description") val description: String?, + @SerialName("website") val website: String?, + @SerialName("developers") val developers: ImmutableList, + @SerialName("organization") val organization: Organization?, + @SerialName("scm") val scm: Scm?, + @SerialName("licenses") val licenses: ImmutableSet = persistentSetOf(), + @SerialName("funding") val funding: ImmutableSet = persistentSetOf(), + @SerialName("tag") val tag: String? = null, ) { /** * defines the [uniqueId]:[artifactVersion] combined diff --git a/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/License.kt b/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/License.kt index cfd8fef10..0c4d28a84 100644 --- a/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/License.kt +++ b/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/License.kt @@ -1,5 +1,8 @@ package com.mikepenz.aboutlibraries.entity +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + /** * Describes a complete [License] element. * Either retrieved from spdx or downloaded from the artifacts repo @@ -11,13 +14,14 @@ package com.mikepenz.aboutlibraries.entity * @param licenseContent contains the whole license content as downloaded from the server * @param hash usually calculated to identify if a license is re-used and can be used for multiple artifacts */ +@Serializable data class License( - val name: String, - val url: String?, - val year: String? = null, - val spdxId: String? = null, - val licenseContent: String? = null, - val hash: String + @SerialName("name") val name: String, + @SerialName("url") val url: String?, + @SerialName("year") val year: String? = null, + @SerialName("spdxId") val spdxId: String? = null, + @SerialName("licenseContent") val licenseContent: String? = null, + @SerialName("hash") val hash: String ) { override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Organization.kt b/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Organization.kt index 8120ae49d..2b6dc0824 100644 --- a/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Organization.kt +++ b/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Organization.kt @@ -1,5 +1,8 @@ package com.mikepenz.aboutlibraries.entity +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + /** * Describes the [Organization] defined in the `pom.xml` file. * @@ -8,7 +11,8 @@ package com.mikepenz.aboutlibraries.entity * @param name of the organisation * @param url optional url to the website of the defined organisation */ +@Serializable data class Organization( - val name: String, - val url: String? + @SerialName("name") val name: String, + @SerialName("url") val url: String? ) \ No newline at end of file diff --git a/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Scm.kt b/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Scm.kt index d82251d7f..b6298248d 100644 --- a/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Scm.kt +++ b/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/entity/Scm.kt @@ -1,5 +1,8 @@ package com.mikepenz.aboutlibraries.entity +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + /** * Describes the [Scm] defined in the `pom.xml` file. * @@ -9,8 +12,9 @@ package com.mikepenz.aboutlibraries.entity * @param developerConnection optionally describing the developer connection * @param url optionally linking to the hosted form of this artifact */ +@Serializable data class Scm( - val connection: String?, - val developerConnection: String?, - val url: String? + @SerialName("connection") val connection: String?, + @SerialName("developerConnection") val developerConnection: String?, + @SerialName("url") val url: String? ) \ No newline at end of file From 1e8b298ca04370429550a43a706ef97a9bd5f00f Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Fri, 22 Mar 2024 14:44:01 +0100 Subject: [PATCH 2/3] - also make Libs class serializeable --- .../commonMain/kotlin/com/mikepenz/aboutlibraries/Libs.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/Libs.kt b/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/Libs.kt index 4b1274c46..292aed4a0 100644 --- a/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/Libs.kt +++ b/aboutlibraries-core/src/commonMain/kotlin/com/mikepenz/aboutlibraries/Libs.kt @@ -7,14 +7,17 @@ import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.ImmutableSet import kotlinx.collections.immutable.toImmutableList import kotlinx.collections.immutable.toImmutableSet +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable /** * The [Libs] class is the main access point to the generated data of the plugin. * Provides accessors for the [Library] and [License] lists, containing all the dependency information for the module. */ +@Serializable data class Libs constructor( - val libraries: ImmutableList, - val licenses: ImmutableSet, + @SerialName("libraries") val libraries: ImmutableList, + @SerialName("licenses") val licenses: ImmutableSet, ) { /** * Builder used to automatically parse and interpret the generated library data from the plugin. From 193f0fa49d8ba99ff25bf64f6ed79ab844183916 Mon Sep 17 00:00:00 2001 From: Mike Penz Date: Fri, 22 Mar 2024 14:45:45 +0100 Subject: [PATCH 3/3] - get serialization version from kotlin version in use --- aboutlibraries-core/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aboutlibraries-core/build.gradle.kts b/aboutlibraries-core/build.gradle.kts index 813f95309..3fa5f1a23 100644 --- a/aboutlibraries-core/build.gradle.kts +++ b/aboutlibraries-core/build.gradle.kts @@ -7,7 +7,7 @@ plugins { id("com.android.library") id("org.jetbrains.dokka") id("com.vanniktech.maven.publish") - kotlin("plugin.serialization") version "1.9.22" + kotlin("plugin.serialization") version libs.versions.kotlinCore.get() } android {