Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

独立 simbot-api 中的注解为新模块 simbot-annotations; 独立 simbot-api 中 suspend 转化函数为新模块 simbot-util-suspend-transformer #652

Merged
merged 3 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 17 additions & 35 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,10 @@
*/
rootProject.name = "simply-robot"

include(
":simbot-util-api-requestor-core",
":simbot-util-api-requestor-ktor",
":simbot-util-stage-loop",
)

include(
":simbot-util-annotation-tool"
)

include(
":simbot-util-di-api",
":simbot-util-di-core",
)

include(":simbot-logger")
include(":simbot-logger-slf4j-impl")

include(":simbot-annotations")
include(":simbot-api")
include(":simbot-core")

Expand All @@ -40,6 +26,22 @@ include(
":simboot-core-spring-boot-starter",
)


include(
":simbot-util-api-requestor-core",
":simbot-util-api-requestor-ktor",
":simbot-util-stage-loop",
)

include(":simbot-util-annotation-tool")

include(
":simbot-util-di-api",
":simbot-util-di-core",
)

include(":simbot-util-suspend-transformer")

// project test
// if not in CI workflows
if (!System.getenv("IS_CI").toBoolean()) {
Expand All @@ -54,25 +56,5 @@ if (!System.getenv("IS_CI").toBoolean()) {





@Suppress("NOTHING_TO_INLINE")
inline fun api(moduleName: String): String = ":simbot-apis:simbot-$moduleName"

@Suppress("NOTHING_TO_INLINE")
inline fun core(moduleName: String): String = ":simbot-cores:simbot-$moduleName"

@Suppress("NOTHING_TO_INLINE")
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"

@Suppress("NOTHING_TO_INLINE")
inline fun componentHttpServer(moduleName: String): String = ":simbot-components:http-server:simbot-component-http-server-$moduleName"

@Suppress("NOTHING_TO_INLINE")
inline fun util(moduleName: String): String = ":simbot-utils:simbot-util-$moduleName"

@Suppress("NOTHING_TO_INLINE")
inline fun utilApiReq(moduleName: String): String = ":simbot-utils:api-requestor:simbot-util-api-requestor-$moduleName"
3 changes: 3 additions & 0 deletions simbot-annotations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# simbot-annotations

部分 simbot 中会使用的基础注解。
91 changes: 91 additions & 0 deletions simbot-annotations/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (c) 2023 ForteScarlet.
*
* This file is part of Simple Robot.
*
* Simple Robot is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* Simple Robot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with Simple Robot. If not, see <https://www.gnu.org/licenses/>.
*/

import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet

plugins {
id("simbot.util-module-conventions")
`simbot-multiplatform-maven-publish`
id("simbot.dokka-module-configuration")
}

repositories {
mavenCentral()
}

kotlin {
explicitApi()

jvm {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
javaParameters = true
freeCompilerArgs = freeCompilerArgs + listOf("-Xjvm-default=all")
}
}
withJava()
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}

js(IR) {
browser()
nodejs()
}

val mainPresets = mutableSetOf<KotlinSourceSet>()
val testPresets = mutableSetOf<KotlinSourceSet>()

targets {
presets.filterIsInstance<org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeTargetPreset<*>>()
.forEach { presets ->
val target = fromPreset(presets, presets.name)
mainPresets.add(target.compilations["main"].kotlinSourceSets.first())
testPresets.add(target.compilations["test"].kotlinSourceSets.first())
}
}

sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlinx.coroutines.test)
}
}

val nativeMain by creating {
dependsOn(commonMain)
}
val nativeTest by creating {
dependsOn(commonTest)
}

configure(mainPresets) { dependsOn(nativeMain) }
configure(testPresets) { dependsOn(nativeTest) }

}

}

// suppress all
tasks.withType<org.jetbrains.dokka.gradle.DokkaTaskPartial>().configureEach {
dokkaSourceSets.configureEach {
suppress.set(true)
perPackageOption {
suppress.set(true)
}
}
}
2 changes: 2 additions & 0 deletions simbot-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ plugins {
dependencies {
api(kotlin("reflect"))
api(project(":simbot-logger"))
api(project(":simbot-annotations"))
api(project(":simbot-util-suspend-transformer"))

api(libs.kotlinx.coroutines.core)
api(libs.kotlinx.coroutines.jdk8)
Expand Down
5 changes: 5 additions & 0 deletions simbot-util-suspend-transformer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# simbot-util-suspend-transformer

simbot中独立出来并用于提供各平台兼容 `suspend` 函数的扩展,
主要用于与编译器插件 [suspend-transform-compiler-plugin](https://github.com/forteScarlet/kotlin-suspend-transform-compiler-plugin)
配合使用而脱离simbot主要体系(不掺杂过多代码)
109 changes: 109 additions & 0 deletions simbot-util-suspend-transformer/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright (c) 2023 ForteScarlet.
*
* This file is part of Simple Robot.
*
* Simple Robot is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* Simple Robot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with Simple Robot. If not, see <https://www.gnu.org/licenses/>.
*/

import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet

plugins {
id("simbot.util-module-conventions")
`simbot-multiplatform-maven-publish`
id("simbot.dokka-module-configuration")
}

repositories {
mavenCentral()
}

kotlin {
explicitApi()

jvm {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
javaParameters = true
freeCompilerArgs = freeCompilerArgs + listOf("-Xjvm-default=all")
}
}
withJava()
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}

js(IR) {
browser()
nodejs()
}

val mainPresets = mutableSetOf<KotlinSourceSet>()
val testPresets = mutableSetOf<KotlinSourceSet>()

targets {
presets.filterIsInstance<org.jetbrains.kotlin.gradle.plugin.mpp.AbstractKotlinNativeTargetPreset<*>>()
.forEach { presets ->
val target = fromPreset(presets, presets.name)
mainPresets.add(target.compilations["main"].kotlinSourceSets.first())
testPresets.add(target.compilations["test"].kotlinSourceSets.first())
}
}

sourceSets {
val commonMain by getting {
dependencies {
api(project(":simbot-annotations"))
api(project(":simbot-logger"))
}
}

val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.kotlinx.coroutines.core)
implementation(libs.kotlinx.coroutines.test)
}
}

getByName("jvmMain") {
dependencies {
api(libs.kotlinx.coroutines.core)
api(libs.kotlinx.coroutines.jdk8)
}
}
getByName("jsMain") {
dependencies {
api(libs.kotlinx.coroutines.core)
}
}

val nativeMain by creating {
dependsOn(commonMain)
}
val nativeTest by creating {
dependsOn(commonTest)
}

configure(mainPresets) { dependsOn(nativeMain) }
configure(testPresets) { dependsOn(nativeTest) }

}

}

// suppress all
tasks.withType<org.jetbrains.dokka.gradle.DokkaTaskPartial>().configureEach {
dokkaSourceSets.configureEach {
suppress.set(true)
perPackageOption {
suppress.set(true)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
* You should have received a copy of the GNU Lesser General Public License along with Simple Robot. If not, see <https://www.gnu.org/licenses/>.
*/


@file:Suppress("KDocUnresolvedReference")
package love.forte.simbot

import love.forte.plugin.suspendtrans.annotation.JvmAsync
import love.forte.plugin.suspendtrans.annotation.JvmBlocking


/**
* 用于代表同时标记 [@JvmBlocking][JvmBlocking] 和 [@JvmAsync][JvmAsync] 的整合性注解。
* 用于代表一种类似同时标记
* [@JvmBlocking][love.forte.plugin.suspendtrans.annotation.JvmBlocking] 和
* [@JvmAsync][love.forte.plugin.suspendtrans.annotation.JvmAsync]
* 的整合性注解。
*
*/
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
Expand All @@ -34,15 +34,19 @@ public annotation class JvmSuspendTrans(
)

/**
* **J**vm **S**uspend **T**rans
* **J**vm **S**uspend **T**rans 的简写类型。
*
* @see JvmSuspendTrans
*/
@Suppress("SpellCheckingInspection")
internal typealias JST = JvmSuspendTrans
public typealias JST = JvmSuspendTrans


/**
* 用于代表同时标记 [@JvmBlocking][JvmBlocking] 和 [@JvmAsync][JvmAsync] 的整合性注解。
* 用于代表同时标记
* [@JvmBlocking][love.forte.plugin.suspendtrans.annotation.JvmBlocking] 和
* [@JvmAsync][love.forte.plugin.suspendtrans.annotation.JvmAsync]
* 的整合性注解。
*
* [JvmSuspendTransProperty] 默认转化为属性类型,且 blocking 的转化默认没有后缀。
*
Expand All @@ -60,8 +64,9 @@ public annotation class JvmSuspendTransProperty(
)

/**
* **J**vm **S**uspend **T**rans **P**roperty.
* **J**vm **S**uspend **T**rans **P**roperty 的简写类型。
*
* @see JvmSuspendTransProperty
*/
@Suppress("SpellCheckingInspection")
internal typealias JSTP = JvmSuspendTransProperty
public typealias JSTP = JvmSuspendTransProperty
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2023 ForteScarlet.
*
* This file is part of Simple Robot.
*
* Simple Robot is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* Simple Robot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with Simple Robot. If not, see <https://www.gnu.org/licenses/>.
*/

package love.forte.simbot.utils

import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.promise
import love.forte.simbot.InternalSimbotApi
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.js.Promise

@Suppress("unused", "ObjectPropertyName")
private val `$$DefaultScope`: CoroutineScope by lazy {
CoroutineScope(CoroutineName("Default-Promise"))
}

/**
* 执行一个异步函数,得到 [Promise].
*/
@InternalSimbotApi
public fun <T> runInPromise(
scope: CoroutineScope,
context: CoroutineContext = EmptyCoroutineContext,
block: suspend CoroutineScope.() -> T,
): Promise<T> =
scope.promise(context) { block() }

/**
* 使用一个内部默认的 [CoroutineScope] 执行一个异步函数,得到 [Promise].
*/
@InternalSimbotApi
public fun <T> runInPromise(
context: CoroutineContext = EmptyCoroutineContext,
block: suspend CoroutineScope.() -> T,
): Promise<T> = runInPromise(scope = `$$DefaultScope`, context, block)
Loading