Skip to content

Commit

Permalink
合并拉取请求 #460
Browse files Browse the repository at this point in the history
尝试应用编译器插件Kotlin suspend transform
  • Loading branch information
ForliyScarlet authored Sep 28, 2022
2 parents bc45b1f + df0357f commit e4c53c1
Show file tree
Hide file tree
Showing 67 changed files with 802 additions and 1,238 deletions.
20 changes: 20 additions & 0 deletions .changelog/v3.0.0-beta.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
**仓库参考:**

| **模块** | **repo1.maven** | **search.maven** |
|---------|-----------------|------------------|
| simbot-api | [simbot-api: v3.0.0-beta.2](https://repo1.maven.org/maven2/love/forte/simbot/simbot-api/3.0.0-beta.2) | [simbot-api: v3.0.0-beta.2](https://search.maven.org/artifact/love.forte.simbot/simbot-api/3.0.0-beta.2/jar) |
| simbot-core | [simbot-core: v3.0.0-beta.2](https://repo1.maven.org/maven2/love/forte/simbot/simbot-core/3.0.0-beta.2) | [simbot-core: v3.0.0-beta.2](https://search.maven.org/artifact/love.forte.simbot/simbot-core/3.0.0-beta.2/jar) |
| simbot-logger | [simbot-logger: v3.0.0-beta.2](https://repo1.maven.org/maven2/love/forte/simbot/simbot-logger/3.0.0-beta.2) | [simbot-logger: v3.0.0-beta.2](https://search.maven.org/artifact/love.forte.simbot/simbot-logger/3.0.0-beta.2/jar) |
| simboot-api | [simboot-api: v3.0.0-beta.2](https://repo1.maven.org/maven2/love/forte/simbot/boot/simboot-api/3.0.0-beta.2) | [simboot-api: v3.0.0-beta.2](https://search.maven.org/artifact/love.forte.simbot.boot/simboot-api/3.0.0-beta.2/jar) |
| simboot-core | [simboot-core: v3.0.0-beta.2](https://repo1.maven.org/maven2/love/forte/simbot/boot/simboot-core/3.0.0-beta.2) | [simboot-core: v3.0.0-beta.2](https://search.maven.org/artifact/love.forte.simbot.boot/simboot-core/3.0.0-beta.2/jar) |
| simboot-core-annotation | [simboot-core-annotation: v3.0.0-beta.2](https://repo1.maven.org/maven2/love/forte/simbot/boot/simboot-core-annotation/3.0.0-beta.2) | [simboot-core-annotation: v3.0.0-beta.2](https://search.maven.org/artifact/love.forte.simbot.boot/simboot-core-annotation/3.0.0-beta.2/jar) |
| simboot-core-spring-boot-starter | [simboot-core-spring-boot-starter: v3.0.0-beta.2](https://repo1.maven.org/maven2/love/forte/simbot/boot/simboot-core-spring-boot-starter/3.0.0-beta.2) | [simboot-core-spring-boot-starter: v3.0.0-beta.2](https://search.maven.org/artifact/love.forte.simbot.boot/simboot-core-spring-boot-starter/3.0.0-beta.2/jar) |

<br />
<br />

## 版本变更

- `Kotlin` 更新至 `v1.7.10`
- `Kotlinx Coroutines` 更新至 [`v1.6.4`](https://github.com/Kotlin/kotlinx.coroutines/releases/tag/1.6.4)
- `Kotlinx Serialization` 更新至 [`v1.4.0`](https://github.com/Kotlin/kotlinx.serialization/releases/tag/v1.4.0)
10 changes: 5 additions & 5 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Gradle Publish Release
uses: gradle/gradle-build-action@v2
with:
gradle-version: 7.4.2
gradle-version: 7.5.1
arguments: clean build test

publish-release:
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Gradle Publish Release
uses: gradle/gradle-build-action@v2
with:
gradle-version: 7.4.2
gradle-version: 7.5.1
arguments: clean build publishToSonatype closeAndReleaseStagingRepository --warning-mode all --info -Porg.gradle.jvmargs="org.gradle.jvmargs=-Xmx4G -Xms4G -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8"
env:
SIMBOT_IS_SNAPSHOT: false
Expand Down Expand Up @@ -114,8 +114,8 @@ jobs:
- name: Gradle publish snapshot
uses: gradle/gradle-build-action@v2
with:
gradle-version: 7.4.2
arguments: clean build publishToSonatype closeAndReleaseStagingRepository -Porg.gradle.workers.max=16 -Porg.gradle.parallel=true
gradle-version: 7.5.1
arguments: clean build createChangelog publishToSonatype closeAndReleaseStagingRepository -Porg.gradle.workers.max=16 -Porg.gradle.parallel=true
env:
SIMBOT_IS_SNAPSHOT: true
SIMBOT_SNAPSHOT_ONLY: true
Expand Down Expand Up @@ -152,7 +152,7 @@ jobs:
- name: Gradle generate documentation
uses: gradle/gradle-build-action@v2
with:
gradle-version: 7.4.2
gradle-version: 7.5.1
arguments: clean build dokkaHtmlMultiModuleAndPost
env:
SIMBOT_IS_SNAPSHOT: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Gradle publish snapshot
uses: gradle/gradle-build-action@v2
with:
gradle-version: 7.4.2
gradle-version: 7.5.1
arguments: clean build test publishToSonatype closeAndReleaseStagingRepository -Porg.gradle.workers.max=16 -Porg.gradle.parallel=true


Expand Down
7 changes: 5 additions & 2 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ plugins {
}

repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
}

val kotlinVersion = "1.6.21"
val dokkaPluginVersion = "1.6.21"
val kotlinVersion = "1.7.10"
val dokkaPluginVersion = "1.7.10"
val suspendTransformVersion = "0.0.3"

dependencies {
// kotlin("jvm") apply false
Expand All @@ -21,6 +23,7 @@ dependencies {

// see https://github.com/gradle-nexus/publish-plugin
implementation("io.github.gradle-nexus:publish-plugin:1.1.0")
implementation("love.forte.plugin.suspend-transform:suspend-transform-plugin-gradle:$suspendTransformVersion")
}

val compileKotlin: KotlinCompile by tasks
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/V.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ object V {
* Kotlin相关依赖项
*/
object Kotlin {
const val VERSION = "1.6.21"
const val VERSION = "1.7.10"
}
}
28 changes: 16 additions & 12 deletions buildSrc/src/main/kotlin/simbot.maven-publish.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,26 @@ if (isPublishConfigurable) {
// https://stackoverflow.com/questions/57921325/gradle-signarchives-unable-to-read-secret-key
// https://github.com/gradle/gradle/issues/15718

signing {
val keyId = System.getenv("GPG_KEY_ID")
val secretKey = System.getenv("GPG_SECRET_KEY")
val password = System.getenv("GPG_PASSWORD")

setRequired {
!project.version.toString().endsWith("SNAPSHOT")
val keyId = System.getenv("GPG_KEY_ID")
val secretKey = System.getenv("GPG_SECRET_KEY")
val password = System.getenv("GPG_PASSWORD")

if (keyId != null) {
signing {
setRequired {
!project.version.toString().endsWith("SNAPSHOT")
}

useInMemoryPgpKeys(keyId, secretKey, password)

sign(publishing.publications)
}

useInMemoryPgpKeys(keyId, secretKey, password)

sign(publishing.publications["simbotDist"])
} else {
logger.warn("Signing property [keyId] (from system env [GPG_KEY_ID]) is null.")
}


println("[publishing-configure] - [$name] configured.")
logger.info("[publishing-configure] - [{}] configured.", name)
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2022-2022 ForteScarlet <ForteScarlet@163.com>
*
* 本文件是 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
*
*/

import love.forte.plugin.suspendtrans.SuspendTransformConfiguration

/*
* Copyright (c) 2022 ForteScarlet <ForteScarlet@163.com>
*
* 本文件是 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
*
*/

plugins {
id("love.forte.plugin.suspend-transform")

}

suspendTransform {
includeRuntime = false
jvm {
// jvmBlockingMarkAnnotation.functionInheritable = true
// jvmAsyncMarkAnnotation.functionInheritable = true
// api and annotation comes from :apis:simbot-api
val api4JIncludeAnnotation = SuspendTransformConfiguration.IncludeAnnotation("love.forte.simbot.Api4J")
syntheticBlockingFunctionIncludeAnnotations = listOf(api4JIncludeAnnotation)
syntheticAsyncFunctionIncludeAnnotations = listOf(api4JIncludeAnnotation)
jvmBlockingFunctionName = "love.forte.simbot.utils.$\$runInBlocking"
jvmAsyncFunctionName = "love.forte.simbot.utils.$\$runInAsync"
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
11 changes: 8 additions & 3 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[versions]
kotlinx-coroutines = "1.6.2"
kotlinx-serialization = "1.3.3"
kotlinx-coroutines = "1.6.4"
kotlinx-serialization = "1.4.0"
spring-boot = "2.7.2"
openjdk-jmh = "1.35"
forte-di = "0.0.3"
forte-annotationTool = "0.6.3"
ktor = "2.1.1"

[libraries]
# jetbrains-annotation
Expand Down Expand Up @@ -62,4 +63,8 @@ forte-di-spring = { group = "love.forte.di", name = "di-spring", version.ref = "

forte-annotationTool-api = { group = "love.forte.annotation-tool", name = "api", version.ref = "forte-annotationTool" }
forte-annotationTool-core = { group = "love.forte.annotation-tool", name = "core", version.ref = "forte-annotationTool" }
forte-annotationTool-kcore = { group = "love.forte.annotation-tool", name = "kcore", version.ref = "forte-annotationTool" }
forte-annotationTool-kcore = { group = "love.forte.annotation-tool", name = "kcore", version.ref = "forte-annotationTool" }

# ktor
ktor-server-core = { group = "io.ktor", name = "ktor-server-core", version.ref = "ktor" }
ktor-server-netty = { group = "io.ktor", name = "ktor-server-netty", version.ref = "ktor" }
12 changes: 8 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ include(
projectTest("jmh-duration"),
)

rootProject.children.forEach {
println(it)
}
include(
componentHttpServer("api")
)


@Suppress("NOTHING_TO_INLINE")
inline fun api(moduleName: String): String = ":simbot-apis:simbot-$moduleName"
Expand All @@ -60,4 +61,7 @@ inline fun core(moduleName: String): String = ":simbot-cores:simbot-$moduleName"
inline fun boot(moduleName: String): String = ":simbot-boots:simboot-$moduleName"

@Suppress("NOTHING_TO_INLINE")
inline fun projectTest(moduleName: String): String = ":simbot-project-tests:simbot-project-test-$moduleName"
inline fun projectTest(moduleName: String): String = ":simbot-project-tests:simbot-project-test-$moduleName"

@Suppress("NOTHING_TO_INLINE")
inline fun componentHttpServer(moduleName: String): String = ":simbot-components:http-server:simbot-component-http-server-$moduleName"
6 changes: 4 additions & 2 deletions simbot-apis/simbot-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import love.forte.plugin.suspendtrans.SuspendTransformConfiguration

/*
* Copyright (c) 2021-2022 ForteScarlet <ForteScarlet@163.com>
*
Expand All @@ -19,6 +21,7 @@ plugins {
id("simbot.maven-publish")
kotlin("plugin.serialization")
kotlin("kapt")
id("simbot.suspend-transform-configure")
}

dependencies {
Expand All @@ -28,15 +31,13 @@ dependencies {
api(libs.kotlinx.coroutines.jdk8)
api(libs.kotlinx.serialization.core)


api(libs.slf4j.api)
compileOnly(libs.jetbrains.annotations)

compileOnly(libs.kotlinx.serialization.json)
compileOnly(libs.kotlinx.serialization.properties)
compileOnly(libs.charleskorn.kaml)
compileOnly(libs.kotlinx.serialization.protobuf)

compileOnly(libs.kotlinx.coroutines.reactive)
compileOnly(libs.kotlinx.coroutines.reactor)
compileOnly(libs.kotlinx.coroutines.rx2)
Expand All @@ -53,3 +54,4 @@ dependencies {
kaptTest(libs.openjdk.jmh.generator.annprocess)
testAnnotationProcessor(libs.openjdk.jmh.generator.annprocess)
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,73 +17,51 @@
package love.forte.simbot.ability

import kotlinx.coroutines.CompletionHandler
import kotlinx.coroutines.future.future
import love.forte.plugin.suspendtrans.annotation.JvmAsync
import love.forte.plugin.suspendtrans.annotation.JvmBlocking
import love.forte.simbot.Api4J
import love.forte.simbot.utils.runInBlocking
import java.util.concurrent.CompletableFuture
import java.util.concurrent.Future

/**
* 可存活的。
* 此接口提供 [join]、[invokeOnCompletion] 等函数来对生命周期提供一定操作。
*
* @author ForteScarlet
*/
@JvmBlocking
@JvmAsync
public interface Survivable : Switchable {

/**
* 挂起, 直到当前实例被 [cancel] 或完成.
*
* Java中考虑使用 [waiting] 或者通过 [toAsync] 得到 [Future] 来更灵活的操作。
*
* @see waiting
* @see toAsync
*/
@JvmSynthetic
@JvmAsync(baseName = "asFuture", suffix = "")
public suspend fun join()



@Api4J
@Deprecated("Just use join() or asFuture() for java", level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith("future { join() }")
)
public fun toFuture(): CompletableFuture<Unit> = future { join() }

/**
* 当完成(或被cancel)时执行一段处理。
*/
public fun invokeOnCompletion(handler: CompletionHandler)

/**
* 阻塞当前线程并等待 [join] 的挂起结束。
*
* 应当谨慎使用会造成阻塞的api,且在Kotlin中避免使用。
*
* 等同于 `joinBlocking`。目前来看唯一的区别是 [waiting] 显示通过 [Throws] 指定了受检异常 [InterruptedException],
* 而 joinBlocking 目前不会产生受检异常。
*/
@Api4J
@Throws(InterruptedException::class)
public fun waiting() {
runInBlocking { join() }
}

/**
* 得到一个 [Future], 其结果会在当前 [Survivable] 被终止后被推送。
*
* 返回值的 [Future.get] 得到的最终结果恒为 `0`。
*
*/
@Api4J
public fun toAsync(): Future<Unit> {
val future = CompletableFuture<Unit>()
invokeOnCompletion { e ->
if (e != null) {
future.completeExceptionally(e)
} else {
future.complete(Unit)
}
}
return future
}

@JvmSynthetic
override suspend fun start(): Boolean

@JvmSynthetic
override suspend fun cancel(reason: Throwable?): Boolean


}


Loading

0 comments on commit e4c53c1

Please sign in to comment.