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

Deprecate versionNumber with version #395

Merged
merged 5 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,10 @@ tasks {
}
}
}

apiValidation {
@OptIn(kotlinx.validation.ExperimentalBCVApi::class)
klib {
enabled = true
}
}
14 changes: 0 additions & 14 deletions gradle/build-logic/src/main/kotlin/KotlinConfig.kt

This file was deleted.

10 changes: 9 additions & 1 deletion gradle/build-logic/src/main/kotlin/kotlinMPP.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
plugins {
kotlin("multiplatform")
id("publish")
id("dokkaLicensee")
}

kotlin {
jvmToolchain(8)

jvm()
js(IR) {
browser()
Expand Down Expand Up @@ -35,5 +39,9 @@ kotlin {
mingwX64()
watchosDeviceArm64()

kotlinConfig()
explicitApi()
compilerOptions {
progressiveMode.set(true)
optIn.add("kotlin.uuid.ExperimentalUuidApi")
}
}
8 changes: 2 additions & 6 deletions gradle/build-logic/src/main/kotlin/publish.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import java.util.*

plugins {
id("maven-publish")
id("signing")
Expand All @@ -10,10 +8,8 @@ val emptyJar by tasks.registering(Jar::class)
publishing {
publications.configureEach {
this as MavenPublication
if (project.name != "kotlinx-uuid-exposed") {
artifact(emptyJar) {
classifier = "javadoc"
}
artifact(emptyJar) {
classifier = "javadoc"
}
pom {
name.set("app.softwork UUID Library")
Expand Down
1 change: 1 addition & 0 deletions kotlinx-uuid-core/api/android/kotlinx-uuid-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public final class app/softwork/uuid/UuidKt {
public static final fun getNode (Lkotlin/uuid/Uuid;)J
public static final fun getTimeStamp (Lkotlin/uuid/Uuid;)J
public static final fun getVariant (Lkotlin/uuid/Uuid;)I
public static final fun getVersion (Lkotlin/uuid/Uuid;)I
public static final fun getVersionNumber (Lkotlin/uuid/Uuid;)I
public static final fun isRfcVariant (Lkotlin/uuid/Uuid;)Z
public static final fun isValidUuidString (Lkotlin/uuid/Uuid$Companion;Ljava/lang/String;)Z
Expand Down
1 change: 1 addition & 0 deletions kotlinx-uuid-core/api/jvm/kotlinx-uuid-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public final class app/softwork/uuid/UuidKt {
public static final fun getNode (Lkotlin/uuid/Uuid;)J
public static final fun getTimeStamp (Lkotlin/uuid/Uuid;)J
public static final fun getVariant (Lkotlin/uuid/Uuid;)I
public static final fun getVersion (Lkotlin/uuid/Uuid;)I
public static final fun getVersionNumber (Lkotlin/uuid/Uuid;)I
public static final fun isRfcVariant (Lkotlin/uuid/Uuid;)Z
public static final fun isValidUuidString (Lkotlin/uuid/Uuid$Companion;Ljava/lang/String;)Z
Expand Down
54 changes: 54 additions & 0 deletions kotlinx-uuid-core/api/kotlinx-uuid-core.klib.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Klib ABI Dump
// Targets: [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86, iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
// Alias: apple => [iosArm64, iosSimulatorArm64, iosX64, macosArm64, macosX64, tvosArm64, tvosSimulatorArm64, tvosX64, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
// - Show declarations: true

// Library unique name: <app.softwork:kotlinx-uuid-core>
final object app.softwork.uuid/BinarySerializer : kotlinx.serialization/KSerializer<kotlin.uuid/Uuid> { // app.softwork.uuid/BinarySerializer|null[0]
final val descriptor // app.softwork.uuid/BinarySerializer.descriptor|{}descriptor[0]
final fun <get-descriptor>(): kotlinx.serialization.descriptors/SerialDescriptor // app.softwork.uuid/BinarySerializer.descriptor.<get-descriptor>|<get-descriptor>(){}[0]

final fun deserialize(kotlinx.serialization.encoding/Decoder): kotlin.uuid/Uuid // app.softwork.uuid/BinarySerializer.deserialize|deserialize(kotlinx.serialization.encoding.Decoder){}[0]
final fun equals(kotlin/Any?): kotlin/Boolean // app.softwork.uuid/BinarySerializer.equals|equals(kotlin.Any?){}[0]
final fun hashCode(): kotlin/Int // app.softwork.uuid/BinarySerializer.hashCode|hashCode(){}[0]
final fun serialize(kotlinx.serialization.encoding/Encoder, kotlin.uuid/Uuid) // app.softwork.uuid/BinarySerializer.serialize|serialize(kotlinx.serialization.encoding.Encoder;kotlin.uuid.Uuid){}[0]
final fun toString(): kotlin/String // app.softwork.uuid/BinarySerializer.toString|toString(){}[0]
}

final val app.softwork.uuid/MAX // app.softwork.uuid/MAX|@kotlin.uuid.Uuid.Companion{}MAX[0]
final fun (kotlin.uuid/Uuid.Companion).<get-MAX>(): kotlin.uuid/Uuid // app.softwork.uuid/MAX.<get-MAX>|<get-MAX>@kotlin.uuid.Uuid.Companion(){}[0]
final val app.softwork.uuid/clockSequence // app.softwork.uuid/clockSequence|@kotlin.uuid.Uuid{}clockSequence[0]
final fun (kotlin.uuid/Uuid).<get-clockSequence>(): kotlin/Int // app.softwork.uuid/clockSequence.<get-clockSequence>|<get-clockSequence>@kotlin.uuid.Uuid(){}[0]
final val app.softwork.uuid/isRfcVariant // app.softwork.uuid/isRfcVariant|@kotlin.uuid.Uuid{}isRfcVariant[0]
final fun (kotlin.uuid/Uuid).<get-isRfcVariant>(): kotlin/Boolean // app.softwork.uuid/isRfcVariant.<get-isRfcVariant>|<get-isRfcVariant>@kotlin.uuid.Uuid(){}[0]
final val app.softwork.uuid/node // app.softwork.uuid/node|@kotlin.uuid.Uuid{}node[0]
final fun (kotlin.uuid/Uuid).<get-node>(): kotlin/Long // app.softwork.uuid/node.<get-node>|<get-node>@kotlin.uuid.Uuid(){}[0]
final val app.softwork.uuid/timeStamp // app.softwork.uuid/timeStamp|@kotlin.uuid.Uuid{}timeStamp[0]
final fun (kotlin.uuid/Uuid).<get-timeStamp>(): kotlin/Long // app.softwork.uuid/timeStamp.<get-timeStamp>|<get-timeStamp>@kotlin.uuid.Uuid(){}[0]
final val app.softwork.uuid/unixTimeStamp // app.softwork.uuid/unixTimeStamp|@kotlin.uuid.Uuid{}unixTimeStamp[0]
final fun (kotlin.uuid/Uuid).<get-unixTimeStamp>(): kotlin/Long // app.softwork.uuid/unixTimeStamp.<get-unixTimeStamp>|<get-unixTimeStamp>@kotlin.uuid.Uuid(){}[0]
final val app.softwork.uuid/variant // app.softwork.uuid/variant|@kotlin.uuid.Uuid{}variant[0]
final fun (kotlin.uuid/Uuid).<get-variant>(): kotlin/Int // app.softwork.uuid/variant.<get-variant>|<get-variant>@kotlin.uuid.Uuid(){}[0]
final val app.softwork.uuid/version // app.softwork.uuid/version|@kotlin.uuid.Uuid{}version[0]
final fun (kotlin.uuid/Uuid).<get-version>(): kotlin/Int // app.softwork.uuid/version.<get-version>|<get-version>@kotlin.uuid.Uuid(){}[0]
final val app.softwork.uuid/versionNumber // app.softwork.uuid/versionNumber|@kotlin.uuid.Uuid{}versionNumber[0]
final fun (kotlin.uuid/Uuid).<get-versionNumber>(): kotlin/Int // app.softwork.uuid/versionNumber.<get-versionNumber>|<get-versionNumber>@kotlin.uuid.Uuid(){}[0]

final fun (kotlin.random/Random).app.softwork.uuid/nextUuid(): kotlin.uuid/Uuid // app.softwork.uuid/nextUuid|[email protected](){}[0]
final fun (kotlin.uuid/Uuid.Companion).app.softwork.uuid/from(kotlin/Int, kotlin/Long, kotlin/Int, kotlin/Long, kotlin/Int = ...): kotlin.uuid/Uuid // app.softwork.uuid/from|[email protected](kotlin.Int;kotlin.Long;kotlin.Int;kotlin.Long;kotlin.Int){}[0]
final fun (kotlin.uuid/Uuid.Companion).app.softwork.uuid/generateUuid(kotlin.uuid/Uuid, kotlin/String): kotlin.uuid/Uuid // app.softwork.uuid/generateUuid|[email protected](kotlin.uuid.Uuid;kotlin.String){}[0]
final fun (kotlin.uuid/Uuid.Companion).app.softwork.uuid/generateUuid(kotlin/ByteArray): kotlin.uuid/Uuid // app.softwork.uuid/generateUuid|[email protected](kotlin.ByteArray){}[0]
final fun (kotlin.uuid/Uuid.Companion).app.softwork.uuid/isValidUuidString(kotlin/String): kotlin/Boolean // app.softwork.uuid/isValidUuidString|[email protected](kotlin.String){}[0]
final fun (kotlin.uuid/Uuid.Companion).app.softwork.uuid/random(kotlin.random/Random): kotlin.uuid/Uuid // app.softwork.uuid/random|[email protected](kotlin.random.Random){}[0]
final fun (kotlin/String).app.softwork.uuid/toUuid(): kotlin.uuid/Uuid // app.softwork.uuid/toUuid|[email protected](){}[0]
final fun (kotlin/String).app.softwork.uuid/toUuidOrNull(): kotlin.uuid/Uuid? // app.softwork.uuid/toUuidOrNull|[email protected](){}[0]
final fun app.softwork.uuid/Uuidv7(kotlin/Long, kotlin.random/Random): kotlin.uuid/Uuid // app.softwork.uuid/Uuidv7|Uuidv7(kotlin.Long;kotlin.random.Random){}[0]

// Targets: [apple]
final fun (kotlin.uuid/Uuid).app.softwork.uuid/toNsUUID(): platform.Foundation/NSUUID // app.softwork.uuid/toNsUUID|[email protected](){}[0]

// Targets: [apple]
final fun (platform.Foundation/NSUUID).app.softwork.uuid/toKotlinUuid(): kotlin.uuid/Uuid // app.softwork.uuid/toKotlinUuid|[email protected](){}[0]
2 changes: 0 additions & 2 deletions kotlinx-uuid-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import org.jetbrains.kotlin.gradle.plugin.*

plugins {
id("kotlinMPP")
id("publish")
id("dokkaLicensee")
id("kover")
id("com.android.library")
kotlin("plugin.parcelize")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public fun Uuid.Companion.generateUuid(namespace: Uuid, name: String): Uuid {
* It is recommended to use generateUuid(namespace, name) instead while this function
* is more for java.util.UUID parity.
*/
@Deprecated("This function will be removed.")
public fun Uuid.Companion.generateUuid(bytes: ByteArray): Uuid {
val hash = sha1 {
update(bytes)
Expand Down
16 changes: 11 additions & 5 deletions kotlinx-uuid-core/src/commonMain/kotlin/app/softwork/uuid/Uuid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public fun Uuid.Companion.from(
}

/**
* A 60-bits non-negative number. Depending on the Uuid version it could have different semantics:
* A 60-bits non-negative number. Depending on the Uuid [version] it could have different semantics:
* - UTC time
* - a number constructed from the namespace
* - a random number
Expand All @@ -51,23 +51,29 @@ public val Uuid.clockSequence: Int
get() = toLongs { _, clockSequenceVariantAndNodeRaw -> (clockSequenceVariantAndNodeRaw shr 48 and 0x1fff).toInt() }

/**
* Uuid [numeric version](https://tools.ietf.org/html/rfc4122#section-4.1.3) in range `[0..15]
* Uuid [numeric version](https://tools.ietf.org/html/rfc4122#section-4.1.3) in range `[0..15]`
*/
public val Uuid.versionNumber: Int
@Deprecated("Use version instead", replaceWith = ReplaceWith("version"))
public val Uuid.versionNumber: Int get() = version

/**
* Uuid [numeric version](https://tools.ietf.org/html/rfc4122#section-4.1.3) in range `[0..15]`
*/
public val Uuid.version: Int
get() = toLongs { timeStampAndVersionRaw, _ ->
(timeStampAndVersionRaw and 0xf000L shr 12).toInt()
}

/**
* Uuid variant in range `[0..7]`, similar to version
* Uuid variant in range `[0..7]`, similar to [version]
*/
public val Uuid.variant: Int
get() = toLongs { _, clockSequenceVariantAndNodeRaw ->
(clockSequenceVariantAndNodeRaw ushr 61).toInt()
}

/**
* Uuid variant specified and documented by the RFC
* Uuid [variant] specified and documented by the RFC
*/
public val Uuid.isRfcVariant: Boolean get() = variant == 4 || variant == 5

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ class GenerationTest {
fun testGenerateFromName() {
val baseUuid = Uuid.parse(SOME_UUID_STRING)
val generated = Uuid.generateUuid(baseUuid, "test")
assertEquals(5, generated.versionNumber)
assertEquals(5, generated.version)
assertEquals("9dc3df60-4ed1-5ea9-9e66-5c2030d5827b", generated.toString())
}

@Test
fun testGenerateFromBytes() {
val generated = Uuid.generateUuid(SOME_UUID_STRING.explodeToBytes().toByteArray())
assertEquals(5, generated.versionNumber)
assertEquals(5, generated.version)
assertEquals("29e5befd-ca93-58bf-9ef0-30f7da112935", generated.toString())
}

private fun Uuid.assertRandomGenerated() {
assertTrue(isRfcVariant)
assertEquals(4, versionNumber)
assertEquals(4, version)
}

private fun String.explodeToBytes(): List<Byte> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package app.softwork.uuid

import app.softwork.uuid.version
Fixed Show fixed Hide fixed
import kotlin.random.Random
import kotlin.test.*
import kotlin.uuid.Uuid
Expand All @@ -17,7 +18,7 @@
fun testZero() {
assertEquals("00000000-0000-0000-0000-000000000000", Uuid.NIL.toString())
assertEquals(0, Uuid.NIL.variant)
assertEquals(0, Uuid.NIL.versionNumber)
assertEquals(0, Uuid.NIL.version)
assertEquals(0, Uuid.NIL.timeStamp)
assertEquals(0, Uuid.NIL.clockSequence)
assertEquals(0, Uuid.NIL.node)
Expand All @@ -28,7 +29,7 @@
fun testMax() {
assertEquals("ffffffff-ffff-ffff-ffff-ffffffffffff", Uuid.MAX.toString())
assertEquals(7, Uuid.MAX.variant)
assertEquals(15, Uuid.MAX.versionNumber)
assertEquals(15, Uuid.MAX.version)
assertEquals(1152921504606846975, Uuid.MAX.timeStamp)
assertEquals(8191, Uuid.MAX.clockSequence)
assertEquals(281474976710655, Uuid.MAX.node)
Expand All @@ -39,7 +40,7 @@
fun testConstructingFromString() {
val uuid = Uuid.parse(UUID_STRING)

assertEquals(1, uuid.versionNumber)
assertEquals(1, uuid.version)
assertEquals(5, uuid.variant)
assertEquals("3d3e99b1b3e4567", uuid.timeStamp.toString(16))
assertEquals("476", uuid.clockSequence.toString(16))
Expand All @@ -53,7 +54,7 @@
fun testConstructingFromStringAllFf() {
val uuid = Uuid.parse(UUID_STRING_ALL_FF)

assertEquals(0xf, uuid.versionNumber)
assertEquals(0xf, uuid.version)
assertEquals(7, uuid.variant)
assertEquals("fffffffffffffff", uuid.timeStamp.toString(16))
assertEquals("1fff", uuid.clockSequence.toString(16))
Expand All @@ -65,7 +66,7 @@
val first = Uuid.parse(SOME_UUID_STRING)
val second = Uuid.from(
timeStamp = first.timeStamp,
versionNumber = first.versionNumber,
versionNumber = first.version,
clockSequence = first.clockSequence,
node = first.node,
variant = first.variant
Expand All @@ -79,7 +80,7 @@
val first = Uuid.parse(SOME_UUID_STRING)
val second = Uuid.from(
timeStamp = first.timeStamp,
versionNumber = first.versionNumber,
versionNumber = first.version,
clockSequence = first.clockSequence,
node = first.node
)
Expand All @@ -92,7 +93,7 @@
val first = Uuid.parse(UUID_STRING_ALL_FF)
val second = Uuid.from(
timeStamp = first.timeStamp,
versionNumber = first.versionNumber,
versionNumber = first.version,
clockSequence = first.clockSequence,
node = first.node,
variant = first.variant
Expand All @@ -113,31 +114,31 @@
}

assertFailsWith<IllegalArgumentException> {
Uuid.from(first.versionNumber, first.timeStamp, Int.MAX_VALUE, first.node, first.variant)
Uuid.from(first.version, first.timeStamp, Int.MAX_VALUE, first.node, first.variant)
}

assertFailsWith<IllegalArgumentException> {
Uuid.from(first.versionNumber, first.timeStamp, first.clockSequence, Long.MAX_VALUE, first.variant)
Uuid.from(first.version, first.timeStamp, first.clockSequence, Long.MAX_VALUE, first.variant)
}

assertFailsWith<IllegalArgumentException> {
Uuid.from(-1, first.timeStamp, first.clockSequence, first.node, first.variant)
}

assertFailsWith<IllegalArgumentException> {
Uuid.from(first.versionNumber, -1, first.clockSequence, first.node, first.variant)
Uuid.from(first.version, -1, first.clockSequence, first.node, first.variant)
}

assertFailsWith<IllegalArgumentException> {
Uuid.from(first.versionNumber, first.timeStamp, -1, first.node, first.variant)
Uuid.from(first.version, first.timeStamp, -1, first.node, first.variant)
}

assertFailsWith<IllegalArgumentException> {
Uuid.from(first.versionNumber, first.timeStamp, first.clockSequence, -1, first.variant)
Uuid.from(first.version, first.timeStamp, first.clockSequence, -1, first.variant)
}

assertFailsWith<IllegalArgumentException> {
Uuid.from(first.versionNumber, first.timeStamp, first.clockSequence, first.node, -1)
Uuid.from(first.version, first.timeStamp, first.clockSequence, first.node, -1)
}
}

Expand All @@ -154,12 +155,12 @@

@Test
fun testVersionNumbers() {
assertEquals(1, Uuid.parse("1b3e4567-e99b-13d3-a476-446657420000").versionNumber)
assertEquals(2, Uuid.parse("1b3e4567-e99b-23d3-a476-446657420000").versionNumber)
assertEquals(3, Uuid.parse("1b3e4567-e99b-33d3-a476-446657420000").versionNumber)
assertEquals(4, Uuid.parse("1b3e4567-e99b-43d3-a476-446657420000").versionNumber)
assertEquals(5, Uuid.parse("1b3e4567-e99b-53d3-a476-446657420000").versionNumber)
assertEquals(0xf, Uuid.parse("1b3e4567-e99b-f3d3-a476-446657420000").versionNumber)
assertEquals(1, Uuid.parse("1b3e4567-e99b-13d3-a476-446657420000").version)
assertEquals(2, Uuid.parse("1b3e4567-e99b-23d3-a476-446657420000").version)
assertEquals(3, Uuid.parse("1b3e4567-e99b-33d3-a476-446657420000").version)
assertEquals(4, Uuid.parse("1b3e4567-e99b-43d3-a476-446657420000").version)
assertEquals(5, Uuid.parse("1b3e4567-e99b-53d3-a476-446657420000").version)
assertEquals(0xf, Uuid.parse("1b3e4567-e99b-f3d3-a476-446657420000").version)
}

@Test
Expand All @@ -174,7 +175,7 @@

@Test
fun testRandomCreation() {
assertEquals(4, Uuid.random().versionNumber)
assertEquals(4, Random.nextUuid().versionNumber)
assertEquals(4, Uuid.random().version)
assertEquals(4, Random.nextUuid().version)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Uuidv7Test {

assertEquals(1645557742000, uuid.unixTimeStamp)
assertEquals("017f22e2-79b0-7a1e-ad73-08cd2f61d78a", uuid.toString())
assertEquals(7, uuid.versionNumber)
assertEquals(7, uuid.version)
assertEquals(5, uuid.variant)
}
}
12 changes: 12 additions & 0 deletions kotlinx-uuid-datetime/api/kotlinx-uuid-datetime.klib.api
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Klib ABI Dump
// Targets: [androidNativeArm32, androidNativeArm64, androidNativeX64, androidNativeX86, iosArm64, iosSimulatorArm64, iosX64, js, linuxArm64, linuxX64, macosArm64, macosX64, mingwX64, tvosArm64, tvosSimulatorArm64, tvosX64, watchosArm32, watchosArm64, watchosDeviceArm64, watchosSimulatorArm64, watchosX64]
// Rendering settings:
// - Signature version: 2
// - Show manifest properties: true
// - Show declarations: true

// Library unique name: <app.softwork:kotlinx-uuid-datetime>
final val app.softwork.uuid.datetime/instant // app.softwork.uuid.datetime/instant|@kotlin.uuid.Uuid{}instant[0]
final fun (kotlin.uuid/Uuid).<get-instant>(): kotlinx.datetime/Instant // app.softwork.uuid.datetime/instant.<get-instant>|<get-instant>@kotlin.uuid.Uuid(){}[0]

final fun app.softwork.uuid.datetime/Uuidv7(kotlinx.datetime/Instant = ..., kotlin.random/Random): kotlin.uuid/Uuid // app.softwork.uuid.datetime/Uuidv7|Uuidv7(kotlinx.datetime.Instant;kotlin.random.Random){}[0]
2 changes: 0 additions & 2 deletions kotlinx-uuid-datetime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

plugins {
id("kotlinMPP")
id("publish")
id("dokkaLicensee")
}

kotlin.sourceSets {
Expand Down
Loading
Loading