From f6c41a8f41f6a1a1fefbd2496f761efc7b8585f2 Mon Sep 17 00:00:00 2001 From: Tommy Schmidt Date: Sun, 23 Apr 2023 20:16:16 +0200 Subject: [PATCH] fix: add runtime hints for kord until kordlib/kord/issues/786 is merged (#67) --- .github/renovate.json | 6 --- .../vrising/discord/BotRuntimeHints.kt | 41 +++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/.github/renovate.json b/.github/renovate.json index bb2137f..2b8f4fc 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -14,12 +14,6 @@ { "matchPackagePatterns": "*", "allowedVersions": "!/-.+\\.[0-9]+$/" - }, - { - "matchPackagePatterns": [ - "dev.kord:kord-core" - ], - "enabled": false } ] } diff --git a/src/main/kotlin/de/darkatra/vrising/discord/BotRuntimeHints.kt b/src/main/kotlin/de/darkatra/vrising/discord/BotRuntimeHints.kt index 825e2c1..3046030 100644 --- a/src/main/kotlin/de/darkatra/vrising/discord/BotRuntimeHints.kt +++ b/src/main/kotlin/de/darkatra/vrising/discord/BotRuntimeHints.kt @@ -1,5 +1,21 @@ package de.darkatra.vrising.discord +import dev.kord.core.cache.data.ApplicationCommandData +import dev.kord.core.cache.data.AutoModerationRuleData +import dev.kord.core.cache.data.ChannelData +import dev.kord.core.cache.data.EmojiData +import dev.kord.core.cache.data.GuildApplicationCommandPermissionsData +import dev.kord.core.cache.data.GuildData +import dev.kord.core.cache.data.MemberData +import dev.kord.core.cache.data.MessageData +import dev.kord.core.cache.data.PresenceData +import dev.kord.core.cache.data.RoleData +import dev.kord.core.cache.data.StickerData +import dev.kord.core.cache.data.StickerPackData +import dev.kord.core.cache.data.ThreadMemberData +import dev.kord.core.cache.data.UserData +import dev.kord.core.cache.data.VoiceStateData +import dev.kord.core.cache.data.WebhookData import io.ktor.network.selector.InterestSuspensionsMap import io.ktor.utils.io.pool.DefaultPool import org.dizitart.no2.Document @@ -8,6 +24,7 @@ import org.dizitart.no2.NitriteId import org.dizitart.no2.meta.Attributes import org.h2.store.fs.FilePathDisk import org.h2.store.fs.FilePathNio +import org.springframework.aot.hint.BindingReflectionHintsRegistrar import org.springframework.aot.hint.MemberCategory import org.springframework.aot.hint.RuntimeHints import org.springframework.aot.hint.RuntimeHintsRegistrar @@ -21,6 +38,8 @@ import java.util.concurrent.atomic.AtomicBoolean */ class BotRuntimeHints : RuntimeHintsRegistrar { + private val bindingReflectionHintsRegistrar = BindingReflectionHintsRegistrar() + override fun registerHints(hints: RuntimeHints, classLoader: ClassLoader?) { // required by nitrite to create a database with password @@ -42,10 +61,32 @@ class BotRuntimeHints : RuntimeHintsRegistrar { hints.serialization().registerType(NitriteId::class.java) hints.serialization().registerType(TypeReference.of("java.lang.String")) + // reflection hints for kord (remove once https://github.com/kordlib/kord/issues/786 is merged) + bindingReflectionHintsRegistrar.registerReflectionHints( + hints.reflection(), + ApplicationCommandData::class.java, + AutoModerationRuleData::class.java, + ChannelData::class.java, + EmojiData::class.java, + GuildData::class.java, + MemberData::class.java, + MessageData::class.java, + PresenceData::class.java, + RoleData::class.java, + StickerData::class.java, + ThreadMemberData::class.java, + UserData::class.java, + VoiceStateData::class.java, + WebhookData::class.java + ) + hints.reflection() // required by nitrite to create and open file based databases .registerType(FilePathDisk::class.java, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS) .registerType(FilePathNio::class.java, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS) + // required by kord (remove once https://github.com/kordlib/kord/issues/786 is merged) + .registerType(GuildApplicationCommandPermissionsData::class.java) + .registerType(StickerPackData::class.java) // required by kotlin coroutines (dependency of kord) .registerType(TypeReference.of("kotlin.internal.jdk8.JDK8PlatformImplementations"), MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS) // required by ktor (dependency of kord)