22
22
*/
23
23
24
24
import io.gitlab.arturbosch.detekt.Detekt
25
+ import love.forte.plugin.suspendtrans.*
26
+ import love.forte.plugin.suspendtrans.gradle.SuspendTransformGradleExtension
25
27
26
28
plugins {
27
29
idea
@@ -30,6 +32,9 @@ plugins {
30
32
alias(libs.plugins.detekt)
31
33
id(" simbot.nexus-publish" )
32
34
id(" simbot.changelog-generator" )
35
+ alias(libs.plugins.suspendTransform) apply false
36
+ // id("love.forte.plugin.suspend-transform") version "2.1.0-0.9.4" apply false
37
+
33
38
34
39
// https://www.jetbrains.com/help/qodana/code-coverage.html
35
40
// https://github.com/Kotlin/kotlinx-kover
@@ -81,8 +86,11 @@ subprojects {
81
86
}
82
87
83
88
applyKover(root)
84
- }
85
89
90
+ if (plugins.hasPlugin(libs.plugins.suspendTransform.get().pluginId)) {
91
+ configureSuspendTransform()
92
+ }
93
+ }
86
94
}
87
95
88
96
dependencies {
@@ -173,12 +181,199 @@ idea {
173
181
}
174
182
175
183
// https://kotlinlang.org/docs/js-project-setup.html#node-js
176
- rootProject.plugins.withType< org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin > {
177
- rootProject.the< org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension > ().apply {
178
- // CI 中配置环境,不再单独下载
179
- if (isCi) {
180
- download = false
181
- }
184
+ // rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
185
+ // rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().apply {
186
+ // // CI 中配置环境,不再单独下载
187
+ // // if (isCi) {
188
+ // // download = false
189
+ // // }
190
+ // }
191
+ // // "true" for default behavior
192
+ // }
193
+
194
+ // region Suspend Transform configs
195
+ @Suppress(" MaxLineLength" )
196
+ object SuspendTransforms {
197
+ private val javaIncludeAnnotationApi4JClassInfo = ClassInfo (" love.forte.simbot.annotations" , " Api4J" )
198
+ private val javaIncludeAnnotationApi4J = IncludeAnnotation (javaIncludeAnnotationApi4JClassInfo).apply {
199
+ includeProperty = true
200
+ }
201
+ private val javaIncludeAnnotations = listOf (javaIncludeAnnotationApi4J)
202
+
203
+ private val jsIncludeAnnotationApi4JsClassInfo = ClassInfo (" love.forte.simbot.annotations" , " Api4Js" )
204
+ private val jsIncludeAnnotationApi4Js = IncludeAnnotation (jsIncludeAnnotationApi4JsClassInfo).apply {
205
+ includeProperty = true
206
+ }
207
+ private val jsIncludeAnnotations = listOf (jsIncludeAnnotationApi4Js)
208
+
209
+
210
+ private val SuspendReserveClassInfo = ClassInfo (
211
+ packageName = " love.forte.simbot.suspendrunner.reserve" ,
212
+ className = " SuspendReserve" ,
213
+ )
214
+
215
+ /* *
216
+ * JvmBlocking
217
+ */
218
+ val jvmBlockingTransformer = SuspendTransformConfiguration .jvmBlockingTransformer.copy(
219
+ syntheticFunctionIncludeAnnotations = javaIncludeAnnotations,
220
+ transformFunctionInfo = FunctionInfo (" love.forte.simbot.suspendrunner" , null , " $\$ runInBlocking" ),
221
+ copyAnnotationExcludes = SuspendTransformConfiguration .jvmBlockingTransformer.copyAnnotationExcludes + SuspendTransformConfiguration .jvmBlockingTransformer.markAnnotation.classInfo
222
+ )
223
+
224
+ /* *
225
+ * JvmAsync
226
+ */
227
+ val jvmAsyncTransformer = SuspendTransformConfiguration .jvmAsyncTransformer.copy(
228
+ syntheticFunctionIncludeAnnotations = javaIncludeAnnotations,
229
+ transformFunctionInfo = FunctionInfo (" love.forte.simbot.suspendrunner" , null , " $\$ runInAsyncNullable" ),
230
+ copyAnnotationExcludes = SuspendTransformConfiguration .jvmAsyncTransformer.copyAnnotationExcludes + SuspendTransformConfiguration .jvmAsyncTransformer.markAnnotation.classInfo
231
+ )
232
+
233
+ /* *
234
+ * JvmReserve
235
+ */
236
+ val jvmReserveTransformer = SuspendTransformConfiguration .jvmAsyncTransformer.copy(
237
+ syntheticFunctionIncludeAnnotations = javaIncludeAnnotations,
238
+ transformFunctionInfo = FunctionInfo (" love.forte.simbot.suspendrunner" , null , " $\$ asReserve" ),
239
+ copyAnnotationExcludes = SuspendTransformConfiguration .jvmAsyncTransformer.copyAnnotationExcludes + SuspendTransformConfiguration .jvmAsyncTransformer.markAnnotation.classInfo,
240
+ transformReturnType = SuspendReserveClassInfo ,
241
+ transformReturnTypeGeneric = true ,
242
+ )
243
+
244
+ /* *
245
+ * JsPromise
246
+ */
247
+ val jsPromiseTransformer = SuspendTransformConfiguration .jsPromiseTransformer.copy(
248
+ syntheticFunctionIncludeAnnotations = javaIncludeAnnotations,
249
+ transformFunctionInfo = FunctionInfo (" love.forte.simbot.suspendrunner" , null , " $\$ runInPromise" ),
250
+ copyAnnotationExcludes = SuspendTransformConfiguration .jsPromiseTransformer.copyAnnotationExcludes + SuspendTransformConfiguration .jsPromiseTransformer.markAnnotation.classInfo,
251
+ )
252
+
253
+ // region @JvmSuspendTrans
254
+ private val suspendTransMarkAnnotationClassInfo = ClassInfo (" love.forte.simbot.suspendrunner" , " SuspendTrans" )
255
+
256
+ private val jvmSuspendTransMarkAnnotationForBlocking = MarkAnnotation (
257
+ suspendTransMarkAnnotationClassInfo,
258
+ baseNameProperty = " blockingBaseName" ,
259
+ suffixProperty = " blockingSuffix" ,
260
+ asPropertyProperty = " blockingAsProperty" ,
261
+ defaultSuffix = SuspendTransformConfiguration .jvmBlockingAnnotationInfo.defaultSuffix,
262
+ )
263
+ private val jvmSuspendTransMarkAnnotationForAsync = MarkAnnotation (
264
+ suspendTransMarkAnnotationClassInfo,
265
+ baseNameProperty = " asyncBaseName" ,
266
+ suffixProperty = " asyncSuffix" ,
267
+ asPropertyProperty = " asyncAsProperty" ,
268
+ defaultSuffix = SuspendTransformConfiguration .jvmAsyncAnnotationInfo.defaultSuffix,
269
+ )
270
+ private val jvmSuspendTransMarkAnnotationForReserve = MarkAnnotation (
271
+ suspendTransMarkAnnotationClassInfo,
272
+ baseNameProperty = " reserveBaseName" ,
273
+ suffixProperty = " reserveSuffix" ,
274
+ asPropertyProperty = " reserveAsProperty" ,
275
+ defaultSuffix = " Reserve" ,
276
+ )
277
+ private val jsSuspendTransMarkAnnotationForPromise = MarkAnnotation (
278
+ suspendTransMarkAnnotationClassInfo,
279
+ baseNameProperty = " jsPromiseBaseName" ,
280
+ suffixProperty = " jsPromiseSuffix" ,
281
+ asPropertyProperty = " jsPromiseAsProperty" ,
282
+ defaultSuffix = " Async" ,
283
+ )
284
+
285
+ val suspendTransTransformerForJvmBlocking = jvmBlockingTransformer.copy(
286
+ markAnnotation = jvmSuspendTransMarkAnnotationForBlocking,
287
+ copyAnnotationExcludes = SuspendTransformConfiguration .jvmBlockingTransformer.copyAnnotationExcludes + jvmSuspendTransMarkAnnotationForBlocking.classInfo
288
+ )
289
+
290
+ val suspendTransTransformerForJvmAsync = jvmAsyncTransformer.copy(
291
+ markAnnotation = jvmSuspendTransMarkAnnotationForAsync,
292
+ copyAnnotationExcludes = SuspendTransformConfiguration .jvmAsyncTransformer.copyAnnotationExcludes + jvmSuspendTransMarkAnnotationForAsync.classInfo
293
+ )
294
+
295
+ val suspendTransTransformerForJvmReserve = jvmReserveTransformer.copy(
296
+ markAnnotation = jvmSuspendTransMarkAnnotationForReserve,
297
+ copyAnnotationExcludes = jvmReserveTransformer.copyAnnotationExcludes + jvmSuspendTransMarkAnnotationForReserve.classInfo,
298
+ )
299
+
300
+ val suspendTransTransformerForJsPromise = jsPromiseTransformer.copy(
301
+ markAnnotation = jvmSuspendTransMarkAnnotationForReserve,
302
+ copyAnnotationExcludes = jsPromiseTransformer.copyAnnotationExcludes + jsSuspendTransMarkAnnotationForPromise.classInfo,
303
+ )
304
+ // endregion
305
+
306
+ // region @JvmSuspendTransProperty
307
+ private val jvmSuspendTransPropMarkAnnotationClassInfo =
308
+ ClassInfo (" love.forte.simbot.suspendrunner" , " SuspendTransProperty" )
309
+
310
+ private val jvmSuspendTransPropMarkAnnotationForBlocking = MarkAnnotation (
311
+ jvmSuspendTransPropMarkAnnotationClassInfo,
312
+ baseNameProperty = " blockingBaseName" ,
313
+ suffixProperty = " blockingSuffix" ,
314
+ asPropertyProperty = " blockingAsProperty" ,
315
+ defaultSuffix = " " ,
316
+ defaultAsProperty = true
317
+ )
318
+ private val jvmSuspendTransPropMarkAnnotationForAsync = MarkAnnotation (
319
+ jvmSuspendTransPropMarkAnnotationClassInfo,
320
+ baseNameProperty = " asyncBaseName" ,
321
+ suffixProperty = " asyncSuffix" ,
322
+ asPropertyProperty = " asyncAsProperty" ,
323
+ defaultSuffix = SuspendTransformConfiguration .jvmAsyncAnnotationInfo.defaultSuffix,
324
+ defaultAsProperty = true
325
+ )
326
+ private val jvmSuspendTransPropMarkAnnotationForReserve = MarkAnnotation (
327
+ jvmSuspendTransPropMarkAnnotationClassInfo,
328
+ baseNameProperty = " reserveBaseName" ,
329
+ suffixProperty = " reserveSuffix" ,
330
+ asPropertyProperty = " reserveAsProperty" ,
331
+ defaultSuffix = " Reserve" ,
332
+ defaultAsProperty = true
333
+ )
334
+
335
+ val jvmSuspendTransPropTransformerForBlocking = jvmBlockingTransformer.copy(
336
+ markAnnotation = jvmSuspendTransPropMarkAnnotationForBlocking,
337
+ copyAnnotationExcludes = SuspendTransformConfiguration .jvmBlockingTransformer.copyAnnotationExcludes + jvmSuspendTransPropMarkAnnotationForBlocking.classInfo
338
+ )
339
+
340
+ val jvmSuspendTransPropTransformerForAsync = jvmAsyncTransformer.copy(
341
+ markAnnotation = jvmSuspendTransPropMarkAnnotationForAsync,
342
+ copyAnnotationExcludes = SuspendTransformConfiguration .jvmAsyncTransformer.copyAnnotationExcludes + jvmSuspendTransPropMarkAnnotationForAsync.classInfo
343
+ )
344
+
345
+ val jvmSuspendTransPropTransformerForReserve = jvmReserveTransformer.copy(
346
+ markAnnotation = jvmSuspendTransPropMarkAnnotationForReserve,
347
+ copyAnnotationExcludes = jvmReserveTransformer.copyAnnotationExcludes + jvmSuspendTransPropMarkAnnotationForReserve.classInfo
348
+ )
349
+ // endregion
350
+ }
351
+
352
+ fun Project.configureSuspendTransform () {
353
+ extensions.configure<SuspendTransformGradleExtension >(" suspendTransform" ) {
354
+ includeRuntime = false
355
+ includeAnnotation = false
356
+
357
+ addJvmTransformers(
358
+ // @JvmBlocking
359
+ SuspendTransforms .jvmBlockingTransformer,
360
+ // @JvmAsync
361
+ SuspendTransforms .jvmAsyncTransformer,
362
+
363
+ // @JvmSuspendTrans
364
+ SuspendTransforms .suspendTransTransformerForJvmBlocking,
365
+ SuspendTransforms .suspendTransTransformerForJvmAsync,
366
+ SuspendTransforms .suspendTransTransformerForJvmReserve,
367
+
368
+ // @JvmSuspendTransProperty
369
+ SuspendTransforms .jvmSuspendTransPropTransformerForBlocking,
370
+ SuspendTransforms .jvmSuspendTransPropTransformerForAsync,
371
+ SuspendTransforms .jvmSuspendTransPropTransformerForReserve,
372
+ )
373
+
374
+ // addJsTransformers(
375
+ // SuspendTransforms.suspendTransTransformerForJsPromise,
376
+ // )
182
377
}
183
- // "true" for default behavior
184
378
}
379
+ // endregion
0 commit comments