Skip to content

Commit

Permalink
fix: add runtime hints for kord until kordlib/kord/issues/786 is merged
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkAtra committed Apr 23, 2023
1 parent 2521f2e commit f2c5880
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
6 changes: 0 additions & 6 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
{
"matchPackagePatterns": "*",
"allowedVersions": "!/-.+\\.[0-9]+$/"
},
{
"matchPackagePatterns": [
"dev.kord:kord-core"
],
"enabled": false
}
]
}
45 changes: 43 additions & 2 deletions src/main/kotlin/de/darkatra/vrising/discord/BotRuntimeHints.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
package de.darkatra.vrising.discord

import io.ktor.network.selector.InterestSuspensionsMap
import io.ktor.utils.io.pool.DefaultPool
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.*
import io.ktor.utils.io.pool.*
import org.dizitart.no2.Document
import org.dizitart.no2.Index
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
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit f2c5880

Please sign in to comment.