Skip to content

Commit

Permalink
Final touches
Browse files Browse the repository at this point in the history
- Add test-kit
- Add samples
- Move HttpEngine to common
  • Loading branch information
DRSchlaubi committed Mar 1, 2023
1 parent f8e71b3 commit 07d8aae
Show file tree
Hide file tree
Showing 54 changed files with 333 additions and 233 deletions.
11 changes: 7 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ plugins {
org.jetbrains.dokka // for dokkaHtmlMultiModule task
}

repositories {
mavenCentral()
// until Dokka 1.8.0 is released and we no longer need dev builds, see https://github.com/kordlib/kord/pull/755
maven("https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev")
allprojects {
repositories {
mavenCentral()
mavenLocal()
// until Dokka 1.8.0 is released and we no longer need dev builds, see https://github.com/kordlib/kord/pull/755
maven("https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev")
}
}

group = Library.group
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/Compiler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
object OptIns {
const val time = "kotlin.time.ExperimentalTime"
const val contracts = "kotlin.contracts.ExperimentalContracts"
const val coroutines = "kotlinx.coroutines.ExperimentalCoroutinesApi"

const val kordInternal = "dev.kord.common.annotation.KordInternal"
const val kordPreview = "dev.kord.common.annotation.KordPreview"
const val kordExperimental = "dev.kord.common.annotation.KordExperimental"
const val kordVoice = "dev.kord.common.annotation.KordVoice"
Expand Down
12 changes: 11 additions & 1 deletion buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ kotlin {
all {
languageSettings {
if ("Test" in name) {
optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
optIn(OptIns.coroutines)
}
optIn(OptIns.kordInternal)
listOf(
OptIns.time,
OptIns.contracts,
Expand All @@ -55,6 +56,15 @@ kotlin {
// mark ksp src dir
kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
}

targets.forEach {
val safeName = if(it.name == "metadata") "common" else it.name
findByName("${safeName}Test")?.apply {
dependencies {
implementation(project(":test-kit"))
}
}
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions common/api/common.api
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ public final class dev/kord/common/LocaleKt {
public static final fun getKLocale (Ljava/util/Locale;)Ldev/kord/common/Locale;
}

public final class dev/kord/common/Platform {
public static final field INSTANCE Ldev/kord/common/Platform;
public final fun getIS_BROWSER ()Z
public final fun getIS_JVM ()Z
public final fun getIS_NODE ()Z
}

public abstract interface annotation class dev/kord/common/annotation/DeprecatedSinceKord : java/lang/annotation/Annotation {
public abstract fun version ()Ljava/lang/String;
}
Expand All @@ -174,6 +181,9 @@ public abstract interface annotation class dev/kord/common/annotation/KordDsl :
public abstract interface annotation class dev/kord/common/annotation/KordExperimental : java/lang/annotation/Annotation {
}

public abstract interface annotation class dev/kord/common/annotation/KordInternal : java/lang/annotation/Annotation {
}

public abstract interface annotation class dev/kord/common/annotation/KordPreview : java/lang/annotation/Annotation {
}

Expand Down Expand Up @@ -8306,6 +8316,11 @@ public abstract class dev/kord/common/exception/RequestException : java/lang/Exc
public fun <init> (Ljava/lang/Throwable;)V
}

public final class dev/kord/common/http/HttpEngine : io/ktor/client/engine/HttpClientEngineFactory {
public static final field INSTANCE Ldev/kord/common/http/HttpEngine;
public fun create (Lkotlin/jvm/functions/Function1;)Lio/ktor/client/engine/HttpClientEngine;
}

public abstract class dev/kord/common/ratelimit/AbstractIntervalRateLimiter : dev/kord/common/ratelimit/IntervalRateLimiter {
public synthetic fun <init> (IJLkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun consume (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down
16 changes: 5 additions & 11 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,21 @@ kotlin {
api(libs.bignum)
// Replacement for java.io
api(libs.ktor.utils)
api(libs.ktor.client.core)

compileOnly(projects.kspAnnotations)
// The plugin should add this automatically, but it doesn't
compileOnly(libs.kotlinx.atomicfu)
}
}

commonTest {
dependencies {
implementation(libs.bundles.test.common)
}
}
jvmTest {
jvmMain {
dependencies {
runtimeOnly(libs.bundles.test.runtime)
implementation(libs.kotlin.test.junit5)
api(libs.ktor.client.cio)
}
}
jsTest {
jsMain {
dependencies {
implementation(libs.bundles.test.js)
api(libs.ktor.client.js)
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions common/src/commonMain/kotlin/Platform.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.kord.common

import dev.kord.common.annotation.KordInternal

@KordInternal
public expect object Platform {
public val IS_JVM: Boolean
public val IS_NODE: Boolean
public val IS_BROWSER: Boolean
}
11 changes: 10 additions & 1 deletion common/src/commonMain/kotlin/annotation/Annotations.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.kord.common.annotation

import kotlin.RequiresOptIn.Level.ERROR
import kotlin.RequiresOptIn.Level.WARNING
import kotlin.annotation.AnnotationRetention.BINARY
import kotlin.annotation.AnnotationRetention.RUNTIME
import kotlin.annotation.AnnotationTarget.*

/** [DslMarker] for Kord DSLs. */
Expand Down Expand Up @@ -80,3 +80,12 @@ public annotation class KordUnsafe
@Retention(BINARY)
@Target(CLASS, ANNOTATION_CLASS, PROPERTY, CONSTRUCTOR, FUNCTION, PROPERTY_GETTER, PROPERTY_SETTER, TYPEALIAS)
public annotation class DeprecatedSinceKord(val version: String)

/**
* Marks an API for internal use only.
*/
@MustBeDocumented
@RequiresOptIn("This Api is intended for internal use only", level = ERROR)
@Retention(BINARY)
@Target(CLASS, PROPERTY, FUNCTION, TYPEALIAS)
public annotation class KordInternal
7 changes: 7 additions & 0 deletions common/src/commonMain/kotlin/http/HttpEngine.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.kord.common.http

import dev.kord.common.annotation.KordInternal
import io.ktor.client.engine.*

@KordInternal
public expect object HttpEngine : HttpClientEngineFactory<HttpClientEngineConfig>
4 changes: 3 additions & 1 deletion common/src/commonTest/kotlin/file.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package dev.kord.common

expect suspend fun readFile(prefix: String, name: String): String
import dev.kord.test.file
suspend fun readFile(prefix: String, name: String): String =
file("common", "json/$prefix/$name.json")
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package serialization

import dev.kord.common.serialization.InstantInEpochMillisecondsSerializer
import dev.kord.common.serialization.InstantInEpochSecondsSerializer
import dev.kord.test.IgnoreOnJs
import kotlinx.datetime.Instant
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerializationException
import kotlinx.serialization.json.Json
import kotlin.js.JsName
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
Expand Down Expand Up @@ -70,7 +70,7 @@ abstract class InstantSerializerTest(
}


@Ignore // currently can't pass
@IgnoreOnJs // currently can't pass
class InstantInEpochMillisecondsSerializerTest : InstantSerializerTest(
json = "796514689159",
instant = Instant.fromEpochMilliseconds(796514689159),
Expand Down
13 changes: 13 additions & 0 deletions common/src/jsMain/kotlin/dev/kord/common/Platform.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dev.kord.common

public actual object Platform {
public actual val IS_JVM: Boolean = false
public actual val IS_NODE: Boolean
get() = js(
"typeof process !== 'undefined' && process.versions != null && process.versions.node != null"
) as Boolean
public actual val IS_BROWSER: Boolean
get() = js(
"typeof window !== 'undefined' && typeof window.document !== 'undefined' || typeof self !== 'undefined' && typeof self.location !== 'undefined'"
) as Boolean
}
5 changes: 5 additions & 0 deletions common/src/jsMain/kotlin/dev/kord/common/http/HttpEngine.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dev.kord.common.http

import io.ktor.client.engine.js.*

public actual typealias HttpEngine = Js
10 changes: 0 additions & 10 deletions common/src/jsTest/kotlin/file.kt

This file was deleted.

3 changes: 1 addition & 2 deletions common/src/jvmMain/kotlin/Color.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@file:JvmName("ColorJvm"
)
@file:JvmName("ColorJvm")
package dev.kord.common

import java.awt.Color as AwtColor
Expand Down
7 changes: 7 additions & 0 deletions common/src/jvmMain/kotlin/Platform.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.kord.common

public actual object Platform {
public actual val IS_JVM: Boolean = true
public actual val IS_NODE: Boolean = false
public actual val IS_BROWSER: Boolean = false
}
6 changes: 6 additions & 0 deletions common/src/jvmMain/kotlin/http/HttpEngine.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dev.kord.common.http

import io.ktor.client.engine.*
import io.ktor.client.engine.cio.*

public actual object HttpEngine : HttpClientEngineFactory<HttpClientEngineConfig> by CIO
4 changes: 0 additions & 4 deletions common/src/jvmTest/kotlin/file.kt

This file was deleted.

9 changes: 9 additions & 0 deletions core-voice/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
`kord-module`
`kord-publishing`
}

dependencies {
api(projects.core)
api(projects.voice)
}
50 changes: 18 additions & 32 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,40 +1,26 @@
plugins {
java
`kord-module`
`kord-sampled-module`
`kord-multiplatform-module`
`kord-publishing`
}

val voice: SourceSet by sourceSets.creating
val voiceApi: Configuration by configurations.getting
kotlin {
sourceSets {
commonMain {
dependencies {
compileOnly(projects.kspAnnotations)
api(projects.common)
api(projects.rest)
api(projects.gateway)

configurations {
getByName("voiceImplementation") {
extendsFrom(implementation.get())
}
}

dependencies {
api(projects.common)
api(projects.rest)
api(projects.gateway)
voiceApi(projects.core)
voiceApi(projects.voice)

api(libs.kord.cache.api)
api(libs.kord.cache.map)

samplesImplementation(libs.slf4j.simple)

testImplementation(libs.bundles.test.implementation)
testRuntimeOnly(libs.bundles.test.runtime)
}
api(libs.kord.cache.api)
api(libs.kord.cache.map)
}
}

java {
registerFeature("voice") {
usingSourceSet(voice)
withJavadocJar()
withSourcesJar()
capability("dev.kord", "core-voice", version as String)
jvmTest {
dependencies {
implementation(libs.mockk)
}
}
}
}
2 changes: 1 addition & 1 deletion core/src/commonMain/kotlin/builder/kord/KordBuilderUtil.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.kord.core.builder.kord

import dev.kord.common.entity.Snowflake
import dev.kord.rest.request.HttpEngine
import dev.kord.common.http.HttpEngine
import io.ktor.client.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.websocket.*
Expand Down
1 change: 1 addition & 0 deletions gateway/src/commonMain/kotlin/DefaultGatewayBuilder.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.kord.gateway

import dev.kord.common.KordConfiguration
import dev.kord.common.http.HttpEngine
import dev.kord.common.ratelimit.IntervalRateLimiter
import dev.kord.common.ratelimit.RateLimiter
import dev.kord.gateway.ratelimit.IdentifyRateLimiter
Expand Down
5 changes: 0 additions & 5 deletions gateway/src/commonMain/kotlin/HttpEngine.kt

This file was deleted.

5 changes: 0 additions & 5 deletions gateway/src/commonTest/kotlin/Platform.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import dev.kord.common.entity.PresenceStatus
import dev.kord.common.ratelimit.IntervalRateLimiter
import dev.kord.gateway.*
import dev.kord.gateway.retry.LinearRetry
import dev.kord.test.getEnv
import io.ktor.client.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.websocket.*
Expand Down
1 change: 0 additions & 1 deletion gateway/src/commonTest/kotlin/json/RegressionTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package json

import dev.kord.gateway.Event
import dev.kord.gateway.Reconnect
import dev.kord.gateway.readFile
import kotlinx.coroutines.test.runTest
import kotlinx.serialization.json.Json
import kotlin.js.JsName
Expand Down
3 changes: 3 additions & 0 deletions gateway/src/commonTest/kotlin/json/Util.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package json

import dev.kord.test.file
import kotlin.test.assertEquals

suspend fun readFile(prefix: String, name: String) = file("gateway", "json/$prefix/$name.jspon")

infix fun <T> T.shouldBe(that: T) {
assertEquals(that, this)
}
Expand Down
7 changes: 0 additions & 7 deletions gateway/src/jsMain/kotlin/dev/kord/gateway/HttpEngine.kt

This file was deleted.

11 changes: 0 additions & 11 deletions gateway/src/jsTest/kotlin/dev/kord/gateway/Platform.kt

This file was deleted.

Loading

0 comments on commit 07d8aae

Please sign in to comment.