From c243ee5aff3ff43cf640942d34c79605dad5fe28 Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Tue, 13 Dec 2022 22:03:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(spring-boot-starter):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=8F=AF=E9=87=8D=E5=A4=8D=E6=B3=A8=E8=A7=A3=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9B=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E5=85=B6=E4=BB=96=E5=B0=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #540 --- libs.versions.toml | 4 +- .../love/forte/simboot/annotation/Filter.kt | 66 ++++++++--------- .../forte/simboot/annotation/Interceptor.kt | 26 +++---- .../love/forte/simboot/annotation/Listen.kt | 22 +++--- .../love/forte/simboot/annotation/Preparer.kt | 26 +++---- .../build.gradle.kts | 31 ++++---- .../utils/SpringAnnotationTool.kt | 70 ++++++++++++------- .../build.gradle.kts | 16 ++++- 8 files changed, 140 insertions(+), 121 deletions(-) diff --git a/libs.versions.toml b/libs.versions.toml index 54a6cd0dc..3ea2eee44 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -1,7 +1,7 @@ [versions] kotlinx-coroutines = "1.6.4" kotlinx-serialization = "1.4.0" -spring-boot = "2.7.2" +spring-boot = "2.7.6" openjdk-jmh = "1.35" forte-di = "0.0.3" forte-annotationTool = "0.6.3" @@ -72,4 +72,4 @@ ktor-server-netty = { group = "io.ktor", name = "ktor-server-netty", version.ref # Lincheck # https://kotlinlang.org/docs/lincheck-guide.html#associate-compiler-tasks -kotlinx-lincheck = "org.jetbrains.kotlinx:lincheck:2.15" \ No newline at end of file +kotlinx-lincheck = "org.jetbrains.kotlinx:lincheck:2.15" diff --git a/simbot-boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/Filter.kt b/simbot-boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/Filter.kt index 77ec1f097..639de6581 100644 --- a/simbot-boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/Filter.kt +++ b/simbot-boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/Filter.kt @@ -1,17 +1,14 @@ /* - * Copyright (c) 2021-2022 ForteScarlet + * Copyright (c) 2021-2022 ForteScarlet * - * 本文件是 simply-robot (或称 simple-robot 3.x 、simbot 3.x ) 的一部分。 - * - * simply-robot 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。 - * - * 发布 simply-robot 是希望它能有用,但是并无保障;甚至连可销售和符合某个特定的目的都不保证。请参看 GNU 通用公共许可证,了解详情。 - * - * 你应该随程序获得一份 GNU 通用公共许可证的复本。如果没有,请看: - * https://www.gnu.org/licenses - * https://www.gnu.org/licenses/gpl-3.0-standalone.html - * https://www.gnu.org/licenses/lgpl-3.0-standalone.html + * 本文件是 simply-robot (或称 simple-robot 3.x 、simbot 3.x 、simbot3 等) 的一部分。 + * simply-robot 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。 + * 发布 simply-robot 是希望它能有用,但是并无保障;甚至连可销售和符合某个特定的目的都不保证。请参看 GNU 通用公共许可证,了解详情。 * + * 你应该随程序获得一份 GNU 通用公共许可证的复本。如果没有,请看: + * https://www.gnu.org/licenses + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * https://www.gnu.org/licenses/lgpl-3.0-standalone.html */ package love.forte.simboot.annotation @@ -78,7 +75,6 @@ import kotlin.reflect.KClass * */ @Retention(AnnotationRetention.RUNTIME) -@Repeatable @JvmRepeatable(Filters::class) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.ANNOTATION_CLASS) @MustBeDocumented @@ -88,7 +84,7 @@ public annotation class Filter( * 如果此属性为空,则相当于不生效。 */ val value: String = "", - + /** * 当 [value] 匹配的目标([EventListenerProcessingContext.textContent][love.forte.simbot.event.EventListenerProcessingContext.textContent])的值为 null 的时候, * 是否直接放行。如果为 `true`, 则代表匹配值为null的时候视为匹配通过,反之则为匹配失败。默认为 `false`。此参数只有当 [value] 不为空的时候有效。如果 [value] 为空,则不会进行匹配。 @@ -96,13 +92,13 @@ public annotation class Filter( * */ val ifNullPass: Boolean = false, - + /** * 针对匹配目标所使用的匹配规则。 * 默认情况下使用 [正则完全匹配][MatchType.REGEX_MATCHES]. */ val matchType: MatchType = MatchType.REGEX_MATCHES, - + /** * 目标过滤内容。 * @@ -115,12 +111,12 @@ public annotation class Filter( @Suppress("DEPRECATION_ERROR") @Deprecated("Use targets", ReplaceWith("targets"), level = DeprecationLevel.ERROR) val target: TargetFilter = TargetFilter(), - + /* 在 target 还存在的情况下, 当使用了 targets, 则不会使用 target。 */ - + /** * 目标过滤内容。 * @@ -129,8 +125,8 @@ public annotation class Filter( * @see [Targets] */ val targets: Targets = Targets(), - - + + /** * 指定一个对当前 [Filter] 的处理过滤器。当 [by] 指定了任意一个不直接等同于 [AnnotationEventFilterFactory] * 的类型时,此注解的上述其他参数将不再继续被解析,而是直接交由指定目标进行处理。 @@ -143,9 +139,9 @@ public annotation class Filter( * */ val by: KClass = AnnotationEventFilterFactory::class, - + ) { - + /** * 通用属性过滤规则。 * @@ -175,7 +171,7 @@ public annotation class Filter( * 除了通过此 [components] 作为组件的筛选条件,直接监听一个组件下特有的事件类型能够更好的起到组件过滤的作用。 */ val components: Array = [], - + /** * 对接收事件的botID匹配。 * @@ -185,7 +181,7 @@ public annotation class Filter( * ``` */ val bots: Array = [], - + /** * 对消息发送者的ID匹配。 * @@ -195,7 +191,7 @@ public annotation class Filter( * ``` */ val authors: Array = [], - + /** * 如果这是个[群相关事件][GroupEvent] ,则对群ID匹配。 * @@ -206,7 +202,7 @@ public annotation class Filter( * */ val groups: Array = [], - + /** * 如果是个[子频道相关事件][ChannelEvent], 则对频道ID匹配。 * @@ -216,12 +212,12 @@ public annotation class Filter( * ``` */ val channels: Array = [], - + /** * 如果是个[频道服务器相关事件][GuildEvent], 则对频道服务器ID匹配。 */ val guilds: Array = [], - + /** * 只有当前消息中存在任意一个 [At.target][love.forte.simbot.message.At.target] == event.bot.id 的 [At][love.forte.simbot.message.At] 消息的时候才会通过匹配。 * @@ -273,7 +269,7 @@ public annotation class TargetFilter( * 除了通过此 [components] 作为组件的筛选条件,直接监听一个组件下特有的事件类型能够更好的起到组件过滤的作用。 */ val components: Array = [], - + /** * 对接收事件的botID匹配。 * @@ -283,7 +279,7 @@ public annotation class TargetFilter( * ``` */ val bots: Array = [], - + /** * 对消息发送者的ID匹配。 * @@ -293,7 +289,7 @@ public annotation class TargetFilter( * ``` */ val authors: Array = [], - + /** * 如果这是个[群相关事件][GroupEvent] ,则对群ID匹配。 * @@ -304,7 +300,7 @@ public annotation class TargetFilter( * */ val groups: Array = [], - + /** * 如果是个[子频道相关事件][ChannelEvent], 则对频道ID匹配。 * @@ -314,12 +310,12 @@ public annotation class TargetFilter( * ``` */ val channels: Array = [], - + /** * 如果是个[频道服务器相关事件][GuildEvent], 则对频道服务器ID匹配。 */ val guilds: Array = [], - + /** * 只有当前消息中存在任意一个 [At.target][love.forte.simbot.message.At.target] == event.bot.id 的 [At][love.forte.simbot.message.At] 消息的时候才会通过匹配。 * @@ -357,9 +353,9 @@ public annotation class Filters( * 所有子过滤器。 */ vararg val value: Filter, - + /** * 多个过滤器之间的匹配策略。默认情况下为 [any][MultiFilterMatchType.ANY] 匹配。 */ val multiMatchType: MultiFilterMatchType = MultiFilterMatchType.ANY, -) \ No newline at end of file +) diff --git a/simbot-boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/Interceptor.kt b/simbot-boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/Interceptor.kt index 7a200405d..52b605eb3 100644 --- a/simbot-boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/Interceptor.kt +++ b/simbot-boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/Interceptor.kt @@ -1,17 +1,14 @@ /* - * Copyright (c) 2021-2022 ForteScarlet + * Copyright (c) 2021-2022 ForteScarlet * - * 本文件是 simply-robot (或称 simple-robot 3.x 、simbot 3.x ) 的一部分。 - * - * simply-robot 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。 - * - * 发布 simply-robot 是希望它能有用,但是并无保障;甚至连可销售和符合某个特定的目的都不保证。请参看 GNU 通用公共许可证,了解详情。 - * - * 你应该随程序获得一份 GNU 通用公共许可证的复本。如果没有,请看: - * https://www.gnu.org/licenses - * https://www.gnu.org/licenses/gpl-3.0-standalone.html - * https://www.gnu.org/licenses/lgpl-3.0-standalone.html + * 本文件是 simply-robot (或称 simple-robot 3.x 、simbot 3.x 、simbot3 等) 的一部分。 + * simply-robot 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。 + * 发布 simply-robot 是希望它能有用,但是并无保障;甚至连可销售和符合某个特定的目的都不保证。请参看 GNU 通用公共许可证,了解详情。 * + * 你应该随程序获得一份 GNU 通用公共许可证的复本。如果没有,请看: + * https://www.gnu.org/licenses + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * https://www.gnu.org/licenses/lgpl-3.0-standalone.html */ package love.forte.simboot.annotation @@ -67,7 +64,6 @@ import kotlin.reflect.KClass * @see AnnotatedEventListenerInterceptor */ @Retention(AnnotationRetention.RUNTIME) -@Repeatable @JvmRepeatable(Interceptors::class) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.ANNOTATION_CLASS) public annotation class Interceptor( @@ -77,7 +73,7 @@ public annotation class Interceptor( * 当使用 [value] 的时候([value] 不为空字符串时),[type]的值将会被忽略。 */ val value: String = "", - + /** * 通过 **类型** 获取所需拦截器。 * 对于类型的获取,流程如下: @@ -89,7 +85,7 @@ public annotation class Interceptor( * */ val type: KClass = AnnotatedEventListenerInterceptor::class, - + /** * 此拦截器在所有标记的注解拦截器中的优先级。 */ @@ -104,4 +100,4 @@ public annotation class Interceptor( */ @Retention(AnnotationRetention.RUNTIME) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.ANNOTATION_CLASS) -public annotation class Interceptors(vararg val value: Interceptor) \ No newline at end of file +public annotation class Interceptors(vararg val value: Interceptor) diff --git a/simbot-boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/Listen.kt b/simbot-boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/Listen.kt index 392d56d4a..b89196d21 100644 --- a/simbot-boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/Listen.kt +++ b/simbot-boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/Listen.kt @@ -1,17 +1,14 @@ /* - * Copyright (c) 2021-2022 ForteScarlet + * Copyright (c) 2021-2022 ForteScarlet * - * 本文件是 simply-robot (或称 simple-robot 3.x 、simbot 3.x ) 的一部分。 - * - * simply-robot 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。 - * - * 发布 simply-robot 是希望它能有用,但是并无保障;甚至连可销售和符合某个特定的目的都不保证。请参看 GNU 通用公共许可证,了解详情。 - * - * 你应该随程序获得一份 GNU 通用公共许可证的复本。如果没有,请看: - * https://www.gnu.org/licenses - * https://www.gnu.org/licenses/gpl-3.0-standalone.html - * https://www.gnu.org/licenses/lgpl-3.0-standalone.html + * 本文件是 simply-robot (或称 simple-robot 3.x 、simbot 3.x 、simbot3 等) 的一部分。 + * simply-robot 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。 + * 发布 simply-robot 是希望它能有用,但是并无保障;甚至连可销售和符合某个特定的目的都不保证。请参看 GNU 通用公共许可证,了解详情。 * + * 你应该随程序获得一份 GNU 通用公共许可证的复本。如果没有,请看: + * https://www.gnu.org/licenses + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * https://www.gnu.org/licenses/lgpl-3.0-standalone.html */ package love.forte.simboot.annotation @@ -35,7 +32,6 @@ import kotlin.reflect.KClass * @see love.forte.simbot.event.Event */ @Retention(AnnotationRetention.RUNTIME) -@Repeatable @JvmRepeatable(Listens::class) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.ANNOTATION_CLASS) @MustBeDocumented @@ -45,4 +41,4 @@ public annotation class Listen(val value: KClass) @Retention(AnnotationRetention.RUNTIME) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.ANNOTATION_CLASS) @MustBeDocumented -public annotation class Listens(vararg val value: Listen) \ No newline at end of file +public annotation class Listens(vararg val value: Listen) diff --git a/simbot-boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/Preparer.kt b/simbot-boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/Preparer.kt index 0fee21311..7b08c55c2 100644 --- a/simbot-boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/Preparer.kt +++ b/simbot-boots/simboot-core-annotation/src/main/kotlin/love/forte/simboot/annotation/Preparer.kt @@ -1,17 +1,14 @@ /* - * Copyright (c) 2022-2022 ForteScarlet + * Copyright (c) 2022 ForteScarlet * - * 本文件是 simply-robot (或称 simple-robot 3.x 、simbot 3.x ) 的一部分。 - * - * simply-robot 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。 - * - * 发布 simply-robot 是希望它能有用,但是并无保障;甚至连可销售和符合某个特定的目的都不保证。请参看 GNU 通用公共许可证,了解详情。 - * - * 你应该随程序获得一份 GNU 通用公共许可证的复本。如果没有,请看: - * https://www.gnu.org/licenses - * https://www.gnu.org/licenses/gpl-3.0-standalone.html - * https://www.gnu.org/licenses/lgpl-3.0-standalone.html + * 本文件是 simply-robot (或称 simple-robot 3.x 、simbot 3.x 、simbot3 等) 的一部分。 + * simply-robot 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。 + * 发布 simply-robot 是希望它能有用,但是并无保障;甚至连可销售和符合某个特定的目的都不保证。请参看 GNU 通用公共许可证,了解详情。 * + * 你应该随程序获得一份 GNU 通用公共许可证的复本。如果没有,请看: + * https://www.gnu.org/licenses + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * https://www.gnu.org/licenses/lgpl-3.0-standalone.html */ package love.forte.simboot.annotation @@ -43,7 +40,6 @@ public annotation class Preparator( * * @see ListenerPreparer */ -@Repeatable @JvmRepeatable(Preparers::class) @Retention(AnnotationRetention.RUNTIME) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.ANNOTATION_CLASS) @@ -59,7 +55,7 @@ public annotation class Preparer( * */ val value: KClass, - + /** * 假如提供的 [value] 能够从 bean 容器中获取, * 可以通过 [name] 指定此 bean 在容器中的唯一标识。 @@ -68,7 +64,7 @@ public annotation class Preparer( * */ val name: String = "", - + /** * 相对于所有预处理器之间的优先级。 */ @@ -81,4 +77,4 @@ public annotation class Preparer( */ @Retention(AnnotationRetention.RUNTIME) @Target(AnnotationTarget.FUNCTION, AnnotationTarget.ANNOTATION_CLASS) -public annotation class Preparers(vararg val value: Preparer) \ No newline at end of file +public annotation class Preparers(vararg val value: Preparer) diff --git a/simbot-boots/simboot-core-spring-boot-starter/build.gradle.kts b/simbot-boots/simboot-core-spring-boot-starter/build.gradle.kts index 538957f2a..de92c3c45 100644 --- a/simbot-boots/simboot-core-spring-boot-starter/build.gradle.kts +++ b/simbot-boots/simboot-core-spring-boot-starter/build.gradle.kts @@ -1,17 +1,14 @@ /* - * Copyright (c) 2021-2022 ForteScarlet + * Copyright (c) 2021-2022 ForteScarlet * - * 本文件是 simply-robot (或称 simple-robot 3.x 、simbot 3.x ) 的一部分。 - * - * simply-robot 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。 - * - * 发布 simply-robot 是希望它能有用,但是并无保障;甚至连可销售和符合某个特定的目的都不保证。请参看 GNU 通用公共许可证,了解详情。 - * - * 你应该随程序获得一份 GNU 通用公共许可证的复本。如果没有,请看: - * https://www.gnu.org/licenses - * https://www.gnu.org/licenses/gpl-3.0-standalone.html - * https://www.gnu.org/licenses/lgpl-3.0-standalone.html + * 本文件是 simply-robot (或称 simple-robot 3.x 、simbot 3.x 、simbot3 等) 的一部分。 + * simply-robot 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。 + * 发布 simply-robot 是希望它能有用,但是并无保障;甚至连可销售和符合某个特定的目的都不保证。请参看 GNU 通用公共许可证,了解详情。 * + * 你应该随程序获得一份 GNU 通用公共许可证的复本。如果没有,请看: + * https://www.gnu.org/licenses + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * https://www.gnu.org/licenses/lgpl-3.0-standalone.html */ plugins { @@ -24,14 +21,14 @@ plugins { dependencies { api(project(":simbot-boots:simboot-core")) - + api(libs.javax.inject) api(libs.forte.di.spring) api(libs.spring.boot.logging) - implementation(libs.spring.boot.autoconfigure) - implementation(libs.spring.boot.configuration.processor) + compileOnly(libs.spring.boot.autoconfigure) + compileOnly(libs.spring.boot.configuration.processor) annotationProcessor(libs.spring.boot.configuration.processor) kapt(libs.spring.boot.configuration.processor) @@ -42,10 +39,12 @@ dependencies { testImplementation(libs.kotlinx.serialization.properties) testImplementation(libs.kotlinx.serialization.protobuf) testImplementation(libs.spring.boot.aop) + testImplementation(libs.spring.boot.autoconfigure) + testImplementation(libs.spring.boot.configuration.processor) // testImplementation(libs.spring.boot.webflux) - + // @Suppress("VulnerableLibrariesLocal") - testImplementation("love.forte.simbot.component:simbot-component-mirai-boot:3.0.0.0-beta-M2-SNAPSHOT") + testImplementation("love.forte.simbot.component:simbot-component-mirai-boot:3.0.0.0-beta.6") // testImplementation(V.Kotlinx.Coroutines.Reactor.notation) } diff --git a/simbot-boots/simboot-core-spring-boot-starter/src/main/kotlin/love/forte/simboot/spring/autoconfigure/utils/SpringAnnotationTool.kt b/simbot-boots/simboot-core-spring-boot-starter/src/main/kotlin/love/forte/simboot/spring/autoconfigure/utils/SpringAnnotationTool.kt index 0ce093f30..9b58435d4 100644 --- a/simbot-boots/simboot-core-spring-boot-starter/src/main/kotlin/love/forte/simboot/spring/autoconfigure/utils/SpringAnnotationTool.kt +++ b/simbot-boots/simboot-core-spring-boot-starter/src/main/kotlin/love/forte/simboot/spring/autoconfigure/utils/SpringAnnotationTool.kt @@ -1,26 +1,25 @@ /* - * Copyright (c) 2022-2022 ForteScarlet + * Copyright (c) 2022 ForteScarlet * - * 本文件是 simply-robot (或称 simple-robot 3.x 、simbot 3.x ) 的一部分。 - * - * simply-robot 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。 - * - * 发布 simply-robot 是希望它能有用,但是并无保障;甚至连可销售和符合某个特定的目的都不保证。请参看 GNU 通用公共许可证,了解详情。 - * - * 你应该随程序获得一份 GNU 通用公共许可证的复本。如果没有,请看: - * https://www.gnu.org/licenses - * https://www.gnu.org/licenses/gpl-3.0-standalone.html - * https://www.gnu.org/licenses/lgpl-3.0-standalone.html + * 本文件是 simply-robot (或称 simple-robot 3.x 、simbot 3.x 、simbot3 等) 的一部分。 + * simply-robot 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。 + * 发布 simply-robot 是希望它能有用,但是并无保障;甚至连可销售和符合某个特定的目的都不保证。请参看 GNU 通用公共许可证,了解详情。 * + * 你应该随程序获得一份 GNU 通用公共许可证的复本。如果没有,请看: + * https://www.gnu.org/licenses + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * https://www.gnu.org/licenses/lgpl-3.0-standalone.html */ package love.forte.simboot.spring.autoconfigure.utils import love.forte.annotationtool.core.KAnnotationTool +import love.forte.simboot.annotation.* import org.springframework.core.annotation.AnnotatedElementUtils import org.springframework.core.annotation.AnnotationUtils import java.lang.reflect.AnnotatedElement import kotlin.reflect.* +import kotlin.reflect.full.findAnnotation import kotlin.reflect.jvm.javaConstructor import kotlin.reflect.jvm.javaField import kotlin.reflect.jvm.javaGetter @@ -39,7 +38,7 @@ public class SpringAnnotationTool(private val tool: KAnnotationTool = KAnnotatio tool.clearCache() AnnotationUtils.clearCache() } - + override fun createAnnotationInstance( annotationType: KClass, properties: Map, @@ -51,7 +50,7 @@ public class SpringAnnotationTool(private val tool: KAnnotationTool = KAnnotatio } return tool.createAnnotationInstance(annotationType, properties, base) } - + override fun getAnnotation( fromElement: KAnnotatedElement, annotationType: KClass, @@ -65,19 +64,19 @@ public class SpringAnnotationTool(private val tool: KAnnotationTool = KAnnotatio } } catch (ignore: Throwable) { } - + return tool.getAnnotation(fromElement, annotationType, excludes) } - - + + override fun getAnnotationPropertyTypes(annotationType: KClass): Map { return tool.getAnnotationPropertyTypes(annotationType) } - + override fun getAnnotationValues(annotation: A): Map { return AnnotationUtils.getAnnotationAttributes(annotation) } - + override fun getAnnotations( element: KAnnotatedElement, annotationType: KClass, @@ -86,21 +85,43 @@ public class SpringAnnotationTool(private val tool: KAnnotationTool = KAnnotatio try { val annotatedElement = element.javaAnnotatedElement if (annotatedElement != null) { - val repeatedResult = AnnotatedElementUtils.findMergedRepeatableAnnotations(annotatedElement, annotationType.java) - val directedResult = AnnotatedElementUtils.findAllMergedAnnotations(annotatedElement, annotationType.java) - return (repeatedResult + directedResult).toList() - // return AnnotatedElementUtils.findAllMergedAnnotations(annotatedElement, annotationType.java).toList() + val containerType = annotationType.findContainerType() + val repeatedResult = AnnotatedElementUtils.findMergedRepeatableAnnotations( + annotatedElement, + annotationType.java, + containerType + ) +// val directedResult = AnnotatedElementUtils.findAllMergedAnnotations(annotatedElement, annotationType.java) + return repeatedResult.toList() } } catch (ignore: Throwable) { } return tool.getAnnotations(element, annotationType, excludes) } - + override fun getPropertyNames(annotation: Annotation): Set { return AnnotationUtils.getAnnotationAttributes(annotation).keys } } +private fun KClass.findContainerType(): Class? { + return kotlin.runCatching { + when (this) { + Filter::class -> return Filters::class.java + Interceptor::class -> Interceptors::class.java + Listen::class -> Listens::class.java + Preparer::class -> Preparers::class.java + // known + Filters::class, Listens::class, Listener::class, + Binder::class, SpecifyBinder::class, CurrentBinder::class, GlobalBinder::class, + FilterValue::class, Interceptors::class, Preparers::class, + -> return null + } + + // find repeatable annotation + return this.findAnnotation()?.value?.java + }.getOrNull() +} private val KAnnotatedElement.javaAnnotatedElement: AnnotatedElement? get() { @@ -110,6 +131,7 @@ private val KAnnotatedElement.javaAnnotatedElement: AnnotatedElement? is KProperty<*> -> javaField ?: javaGetter else -> null } + is KClass<*> -> java is KType -> when (val classifier = classifier) { is KClass<*> -> classifier.javaAnnotatedElement @@ -119,4 +141,4 @@ private val KAnnotatedElement.javaAnnotatedElement: AnnotatedElement? is KParameter -> null else -> null } - } \ No newline at end of file + } diff --git a/simbot-project-tests/simbot-project-test-spring-boot-starter/build.gradle.kts b/simbot-project-tests/simbot-project-test-spring-boot-starter/build.gradle.kts index 2ad88e1d9..ccd232d24 100644 --- a/simbot-project-tests/simbot-project-test-spring-boot-starter/build.gradle.kts +++ b/simbot-project-tests/simbot-project-test-spring-boot-starter/build.gradle.kts @@ -1,7 +1,20 @@ +/* + * Copyright (c) 2022 ForteScarlet + * + * 本文件是 simply-robot (或称 simple-robot 3.x 、simbot 3.x 、simbot3 等) 的一部分。 + * simply-robot 是自由软件:你可以再分发之和/或依照由自由软件基金会发布的 GNU 通用公共许可证修改之,无论是版本 3 许可证,还是(按你的决定)任何以后版都可以。 + * 发布 simply-robot 是希望它能有用,但是并无保障;甚至连可销售和符合某个特定的目的都不保证。请参看 GNU 通用公共许可证,了解详情。 + * + * 你应该随程序获得一份 GNU 通用公共许可证的复本。如果没有,请看: + * https://www.gnu.org/licenses + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * https://www.gnu.org/licenses/lgpl-3.0-standalone.html + */ + plugins { java kotlin("jvm") // version "1.7.21" - id("org.springframework.boot") version "2.7.5" + id("org.springframework.boot") version "2.7.6" id("io.spring.dependency-management") version "1.1.0" } @@ -20,3 +33,4 @@ dependencies { tasks.withType { useJUnitPlatform() } +