Skip to content

Commit f8d97d9

Browse files
authored
Merge pull request #797 from bnvinay92/vn/p2-core
Convert :workflow-core to kmp
2 parents b5f7837 + c5a471f commit f8d97d9

File tree

31 files changed

+400
-221
lines changed

31 files changed

+400
-221
lines changed

gradle/libs.versions.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,11 @@ kotlin = "1.6.10"
5050

5151
kotlinx-binary-compatibility = "0.6.0"
5252
kotlinx-coroutines = "1.5.1"
53+
# The 1.5.1 test artifact is jvm-only. The commonTest module should use 1.6.1.
54+
kotlinx-coroutines-test-common = "1.6.1"
5355
kotlinx-serialization-json = "1.3.2"
5456
kotlinx-benchmark = "0.4.2"
57+
kotlinx-atomicfu = "0.17.2"
5558

5659
ktlint = "10.3.0"
5760
material = "1.3.0"
@@ -184,9 +187,11 @@ kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutine
184187
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
185188
kotlinx-coroutines-rx2 = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-rx2", version.ref = "kotlinx-coroutines" }
186189
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" }
190+
kotlinx-coroutines-test-common = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines-test-common" }
187191
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinx-serialization-json" }
188192
kotlinx-benchmark-gradle-plugin = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-plugin", version.ref = "kotlinx-benchmark" }
189193
kotlinx-benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "kotlinx-benchmark" }
194+
kotlinx-atomicfu = { module = "org.jetbrains.kotlinx:atomicfu", version.ref = "kotlinx-atomicfu" }
190195

191196
ktlint-gradle = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref = "ktlint" }
192197

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ gradleEnterprise {
2525

2626
@Suppress("UnstableApiUsage")
2727
dependencyResolutionManagement {
28-
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
28+
repositoriesMode.set(RepositoriesMode.PREFER_PROJECT)
2929
repositories {
3030
mavenCentral()
3131
google()

workflow-core/api/workflow-core.api

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ public final class com/squareup/workflow1/TypedWorker : com/squareup/workflow1/W
164164
public fun toString ()Ljava/lang/String;
165165
}
166166

167+
public final class com/squareup/workflow1/Void {
168+
}
169+
167170
public abstract interface class com/squareup/workflow1/Worker {
168171
public static final field Companion Lcom/squareup/workflow1/Worker$Companion;
169172
public abstract fun doesSameWorkAs (Lcom/squareup/workflow1/Worker;)Z
@@ -228,10 +231,10 @@ public final class com/squareup/workflow1/WorkflowAction$Updater {
228231

229232
public final class com/squareup/workflow1/WorkflowIdentifier {
230233
public static final field Companion Lcom/squareup/workflow1/WorkflowIdentifier$Companion;
231-
public fun <init> (Lkotlin/reflect/KAnnotatedElement;Lcom/squareup/workflow1/WorkflowIdentifier;Lkotlin/jvm/functions/Function0;)V
232-
public synthetic fun <init> (Lkotlin/reflect/KAnnotatedElement;Lcom/squareup/workflow1/WorkflowIdentifier;Lkotlin/jvm/functions/Function0;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
234+
public fun <init> (Lcom/squareup/workflow1/WorkflowIdentifierType;Lcom/squareup/workflow1/WorkflowIdentifier;Lkotlin/jvm/functions/Function0;)V
235+
public synthetic fun <init> (Lcom/squareup/workflow1/WorkflowIdentifierType;Lcom/squareup/workflow1/WorkflowIdentifier;Lkotlin/jvm/functions/Function0;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
233236
public fun equals (Ljava/lang/Object;)Z
234-
public final fun getRealIdentifierType ()Lkotlin/reflect/KAnnotatedElement;
237+
public final fun getRealIdentifierType ()Lcom/squareup/workflow1/WorkflowIdentifierType;
235238
public fun hashCode ()I
236239
public final fun toByteStringOrNull ()Lokio/ByteString;
237240
public fun toString ()Ljava/lang/String;
@@ -241,6 +244,41 @@ public final class com/squareup/workflow1/WorkflowIdentifier$Companion {
241244
public final fun parse (Lokio/ByteString;)Lcom/squareup/workflow1/WorkflowIdentifier;
242245
}
243246

247+
public final class com/squareup/workflow1/WorkflowIdentifierExKt {
248+
public static final fun getWorkflowIdentifier (Lkotlin/reflect/KClass;)Lcom/squareup/workflow1/WorkflowIdentifier;
249+
}
250+
251+
public abstract class com/squareup/workflow1/WorkflowIdentifierType {
252+
public abstract fun getTypeName ()Ljava/lang/String;
253+
}
254+
255+
public final class com/squareup/workflow1/WorkflowIdentifierType$Snapshottable : com/squareup/workflow1/WorkflowIdentifierType {
256+
public fun <init> (Ljava/lang/String;Lkotlin/reflect/KClass;)V
257+
public synthetic fun <init> (Ljava/lang/String;Lkotlin/reflect/KClass;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
258+
public fun <init> (Lkotlin/reflect/KClass;)V
259+
public final fun component1 ()Ljava/lang/String;
260+
public final fun component2 ()Lkotlin/reflect/KClass;
261+
public final fun copy (Ljava/lang/String;Lkotlin/reflect/KClass;)Lcom/squareup/workflow1/WorkflowIdentifierType$Snapshottable;
262+
public static synthetic fun copy$default (Lcom/squareup/workflow1/WorkflowIdentifierType$Snapshottable;Ljava/lang/String;Lkotlin/reflect/KClass;ILjava/lang/Object;)Lcom/squareup/workflow1/WorkflowIdentifierType$Snapshottable;
263+
public fun equals (Ljava/lang/Object;)Z
264+
public final fun getKClass ()Lkotlin/reflect/KClass;
265+
public fun getTypeName ()Ljava/lang/String;
266+
public fun hashCode ()I
267+
public fun toString ()Ljava/lang/String;
268+
}
269+
270+
public final class com/squareup/workflow1/WorkflowIdentifierType$Unsnapshottable : com/squareup/workflow1/WorkflowIdentifierType {
271+
public fun <init> (Lkotlin/reflect/KType;)V
272+
public final fun component1 ()Lkotlin/reflect/KType;
273+
public final fun copy (Lkotlin/reflect/KType;)Lcom/squareup/workflow1/WorkflowIdentifierType$Unsnapshottable;
274+
public static synthetic fun copy$default (Lcom/squareup/workflow1/WorkflowIdentifierType$Unsnapshottable;Lkotlin/reflect/KType;ILjava/lang/Object;)Lcom/squareup/workflow1/WorkflowIdentifierType$Unsnapshottable;
275+
public fun equals (Ljava/lang/Object;)Z
276+
public final fun getKType ()Lkotlin/reflect/KType;
277+
public fun getTypeName ()Ljava/lang/String;
278+
public fun hashCode ()I
279+
public fun toString ()Ljava/lang/String;
280+
}
281+
244282
public final class com/squareup/workflow1/WorkflowOutput {
245283
public fun <init> (Ljava/lang/Object;)V
246284
public fun equals (Ljava/lang/Object;)Z
@@ -266,7 +304,6 @@ public final class com/squareup/workflow1/Workflows {
266304
public static final fun collectToSink (Lkotlinx/coroutines/flow/Flow;Lcom/squareup/workflow1/Sink;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
267305
public static final fun contraMap (Lcom/squareup/workflow1/Sink;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/Sink;
268306
public static final fun getIdentifier (Lcom/squareup/workflow1/Workflow;)Lcom/squareup/workflow1/WorkflowIdentifier;
269-
public static final fun getWorkflowIdentifier (Lkotlin/reflect/KClass;)Lcom/squareup/workflow1/WorkflowIdentifier;
270307
public static final fun mapRendering (Lcom/squareup/workflow1/Workflow;Lkotlin/jvm/functions/Function1;)Lcom/squareup/workflow1/Workflow;
271308
public static final fun renderChild (Lcom/squareup/workflow1/BaseRenderContext;Lcom/squareup/workflow1/Workflow;Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;
272309
public static final fun renderChild (Lcom/squareup/workflow1/BaseRenderContext;Lcom/squareup/workflow1/Workflow;Ljava/lang/String;)Ljava/lang/Object;

workflow-core/build.gradle.kts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,26 @@ apply(from = rootProject.file(".buildscript/configure-maven-publish.gradle"))
77

88
kotlin {
99
jvm { withJava() }
10+
ios()
1011

1112
sourceSets {
12-
val jvmMain by getting {
13+
all {
14+
languageSettings.apply {
15+
optIn("kotlin.RequiresOptIn")
16+
}
17+
}
18+
val commonMain by getting {
1319
dependencies {
14-
compileOnly(libs.jetbrains.annotations)
15-
1620
api(libs.kotlin.jdk6)
1721
api(libs.kotlinx.coroutines.core)
1822
// For Snapshot.
1923
api(libs.squareup.okio)
2024
}
2125
}
22-
val jvmTest by getting {
26+
val commonTest by getting {
2327
dependencies {
24-
implementation(libs.kotlinx.coroutines.test)
28+
implementation(libs.kotlinx.atomicfu)
29+
implementation(libs.kotlinx.coroutines.test.common)
2530
implementation(libs.kotlin.test.jdk)
2631
}
2732
}

workflow-core/src/jvmMain/kotlin/com/squareup/workflow1/BaseRenderContext.kt renamed to workflow-core/src/commonMain/kotlin/com/squareup/workflow1/BaseRenderContext.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package com.squareup.workflow1
66

77
import com.squareup.workflow1.WorkflowAction.Companion.noAction
88
import kotlinx.coroutines.CoroutineScope
9+
import kotlin.jvm.JvmMultifileClass
10+
import kotlin.jvm.JvmName
911
import kotlin.reflect.KType
1012
import kotlin.reflect.typeOf
1113

workflow-core/src/jvmMain/kotlin/com/squareup/workflow1/ImpostorWorkflow.kt renamed to workflow-core/src/commonMain/kotlin/com/squareup/workflow1/ImpostorWorkflow.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
package com.squareup.workflow1
55

6+
import kotlin.jvm.JvmMultifileClass
7+
import kotlin.jvm.JvmName
8+
69
/**
710
* Optional interface that [Workflow]s should implement if they need the runtime to consider their
811
* identity to include a child workflow's identity. Two [ImpostorWorkflow]s with the same concrete

workflow-core/src/jvmMain/kotlin/com/squareup/workflow1/LifecycleWorker.kt renamed to workflow-core/src/commonMain/kotlin/com/squareup/workflow1/LifecycleWorker.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package com.squareup.workflow1
66
import kotlinx.coroutines.flow.Flow
77
import kotlinx.coroutines.flow.flow
88
import kotlinx.coroutines.suspendCancellableCoroutine
9+
import kotlin.jvm.JvmMultifileClass
10+
import kotlin.jvm.JvmName
911

1012
/**
1113
* [Worker] that performs some action when the worker is started and/or stopped.

workflow-core/src/jvmMain/kotlin/com/squareup/workflow1/Sink.kt renamed to workflow-core/src/commonMain/kotlin/com/squareup/workflow1/Sink.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import kotlinx.coroutines.flow.Flow
77
import kotlinx.coroutines.flow.collect
88
import kotlinx.coroutines.suspendCancellableCoroutine
99
import kotlin.coroutines.resume
10+
import kotlin.jvm.JvmMultifileClass
11+
import kotlin.jvm.JvmName
1012

1113
/**
1214
* An object that receives values (commonly events or [WorkflowAction]).

workflow-core/src/jvmMain/kotlin/com/squareup/workflow1/Snapshot.kt renamed to workflow-core/src/commonMain/kotlin/com/squareup/workflow1/Snapshot.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import okio.BufferedSink
88
import okio.BufferedSource
99
import okio.ByteString
1010
import okio.ByteString.Companion.encodeUtf8
11-
import java.lang.Float.floatToRawIntBits
12-
import java.lang.Float.intBitsToFloat
11+
import kotlin.jvm.JvmName
12+
import kotlin.jvm.JvmStatic
1313

1414
/**
1515
* A lazy wrapper of [ByteString]. Allows [Workflow]s to capture their state frequently, without
@@ -93,9 +93,9 @@ public fun BufferedSink.writeBooleanAsInt(bool: Boolean): BufferedSink =
9393

9494
public fun BufferedSource.readBooleanFromInt(): Boolean = readInt() == 1
9595

96-
public fun BufferedSink.writeFloat(float: Float): BufferedSink = writeInt(floatToRawIntBits(float))
96+
public fun BufferedSink.writeFloat(float: Float): BufferedSink = writeInt(float.toRawBits())
9797

98-
public fun BufferedSource.readFloat(): Float = intBitsToFloat(readInt())
98+
public fun BufferedSource.readFloat(): Float = Float.fromBits(readInt())
9999

100100
public fun BufferedSink.writeUtf8WithLength(str: String): BufferedSink {
101101
return writeByteStringWithLength(str.encodeUtf8())
@@ -130,7 +130,7 @@ public fun <T : Enum<T>> BufferedSink.writeOptionalEnumByOrdinal(enumVal: T?): B
130130
}
131131

132132
public inline fun <reified T : Enum<T>> BufferedSource.readEnumByOrdinal(): T {
133-
return T::class.java.enumConstants[readInt()]
133+
return enumValues<T>()[readInt()]
134134
}
135135

136136
public fun <T : Enum<T>> BufferedSink.writeEnumByOrdinal(enumVal: T): BufferedSink {

0 commit comments

Comments
 (0)