Skip to content

Commit 978a3cd

Browse files
committed
release: v0.0.2
1 parent 3020361 commit 978a3cd

File tree

7 files changed

+222
-34
lines changed

7 files changed

+222
-34
lines changed

README.md

Lines changed: 205 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,25 @@ class Foo {
5858
return "Hello"
5959
}
6060
@Api4Js // RequiresOptIn annotation, provide warnings to Kotlin
61-
fun waitAndGetBlocking(): Promise<String> = runInAsync { waitAndGet() } // 'runInBlocking' from the runtime provided by the plugin
61+
fun waitAndGetBlocking(): Promise<String> = runInAsync { waitAndGet() } // 'runInAsync' from the runtime provided by the plugin
6262
}
6363
```
6464

6565
> JS platform target not supported yet. see: [KT-53993](https://youtrack.jetbrains.com/issue/KT-53993)
6666
67-
6867
## Usage
6968
### Gradle
7069

71-
**Way 1:**
70+
**Using the [plugins DSL](https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block):**
71+
72+
<details open>
73+
<summary>Kotlin</summary>
7274

7375
_build.gradle.kts_
7476

7577
```kotlin
76-
plugins {
77-
kotlin("jvm") // or..?
78+
plugins {
79+
id("org.jetbrains.kotlin.jvm") version "KOTLIN_VERSION" // or js? or multiplatform?
7880
id("love.forte.plugin.suspend-transform") version "$PLUGIN_VERSION"
7981
// other...
8082
}
@@ -94,7 +96,43 @@ suspendTransform {
9496
}
9597
```
9698

97-
**Way 2:**
99+
</details>
100+
101+
<details>
102+
<summary>Groovy</summary>
103+
104+
_build.gradle_
105+
106+
```groovy
107+
plugins {
108+
id "org.jetbrains.kotlin.jvm" // or js? or multiplatform?
109+
id "love.forte.plugin.suspend-transform" version "$PLUGIN_VERSION"
110+
// other...
111+
}
112+
113+
// other...
114+
115+
// config it.
116+
suspendTransform {
117+
enabled = true // default: true
118+
includeRuntime = true // default: true
119+
jvm {
120+
// ...
121+
}
122+
js {
123+
// ...
124+
}
125+
}
126+
```
127+
128+
</details>
129+
130+
131+
132+
**Using [legacy plugin application](https://docs.gradle.org/current/userguide/plugins.html#sec:old_plugin_application):**
133+
134+
<details open>
135+
<summary>Kotlin</summary>
98136

99137
_build.gradle.kts_
100138

@@ -109,8 +147,8 @@ buildscript {
109147
}
110148
}
111149

112-
plugins {
113-
kotlin("jvm") // or..?
150+
plugins {
151+
id("org.jetbrains.kotlin.jvm") // or js? or multiplatform?
114152
id("love.forte.plugin.suspend-transform")
115153
// other...
116154
}
@@ -130,10 +168,63 @@ suspendTransform {
130168
}
131169
```
132170

171+
</details>
172+
173+
<details>
174+
<summary>Groovy</summary>
175+
176+
_build.gradle_
177+
178+
```groovy
179+
buildscript {
180+
repositories {
181+
maven {
182+
url "https://plugins.gradle.org/m2/"
183+
}
184+
}
185+
dependencies {
186+
classpath "love.forte.plugin.suspend-transform:suspend-transform-plugin-gradle:$VERSION"
187+
}
188+
}
189+
190+
191+
192+
plugins {
193+
id "org.jetbrains.kotlin.jvm" // or js? or multiplatform?
194+
id "love.forte.plugin.suspend-transform"
195+
// other...
196+
}
197+
198+
// other...
199+
200+
// config it.
201+
suspendTransform {
202+
enabled = true // default: true
203+
includeRuntime = true // default: true
204+
jvm {
205+
// ...
206+
}
207+
js {
208+
// ...
209+
}
210+
}
211+
```
212+
213+
</details>
214+
133215
### Maven
134216

135217
> Not supported yet.
136218
219+
## Cautions
220+
221+
### Gradle JVM
222+
223+
Gradle JVM must be JDK11+
224+
225+
### JS platform
226+
227+
JS platform target not supported yet. see: [KT-53993](https://youtrack.jetbrains.com/issue/KT-53993)
137228

138229
## Effect
139230

@@ -176,7 +267,7 @@ class Bar {
176267

177268
**compiled:**
178269

179-
> Simplified from decompiled results.
270+
> _Simplified from decompiled results._
180271
181272
```kotlin
182273
import love.forte.plugin.suspendtrans.annotation.JvmAsync
@@ -287,3 +378,108 @@ class Bar {
287378
fun noTrans(): Int { /* compiled code */ }
288379
}
289380
```
381+
382+
## Custom config
383+
384+
```kotlin
385+
plugin {
386+
id("love.forte.plugin.suspend-transform") version "$VERSION"
387+
}
388+
389+
390+
suspendTransform {
391+
// enabled suspend transform plugin
392+
enabled = true
393+
// include 'love.forte.plugin.suspend-transform:suspend-transform-runtime' to the runtime environment
394+
includeRuntime = true
395+
// the configuration name for including 'love.forte.plugin.suspend-transform:suspend-transform-runtime'
396+
runtimeConfigurationName = "implementation"
397+
398+
// jvm platform target config
399+
jvm {
400+
// jvm blocking annotation. default: @JvmBlocking
401+
jvmBlockingMarkAnnotation.apply {
402+
annotationName = "love.forte.plugin.suspendtrans.annotation.JvmBlocking"
403+
baseNameProperty = "baseName"
404+
suffixProperty = "suffix"
405+
asPropertyProperty = "asProperty"
406+
}
407+
408+
// jvm async annotation. default: @JvmAsync
409+
jvmAsyncMarkAnnotation.apply {
410+
annotationName = "love.forte.plugin.suspendtrans.annotation.JvmAsync"
411+
baseNameProperty = "baseName"
412+
suffixProperty = "suffix"
413+
asPropertyProperty = "asProperty"
414+
}
415+
416+
// jvm blocking function.
417+
// The function signature must satisfy: fun <T> <fun-name>(block: suspend () -> T): T
418+
jvmBlockingFunctionName = "love.forte.plugin.suspendtrans.runtime.\$runInBlocking$"
419+
420+
// jvm async function.
421+
// The function signature must satisfy: fun <T> <fun-name>(block: suspend () -> T): CompletableFuture<T>
422+
jvmAsyncFunctionName = "love.forte.plugin.suspendtrans.runtime.\$runInAsync$"
423+
424+
// annotations that to be included to the synthetic blocking functions
425+
syntheticBlockingFunctionIncludeAnnotations = listOf(
426+
SuspendTransformConfiguration.IncludeAnnotation("love.forte.plugin.suspendtrans.annotation.Api4J")
427+
)
428+
429+
// annotations that to be included to the synthetic async functions
430+
syntheticAsyncFunctionIncludeAnnotations = listOf(
431+
SuspendTransformConfiguration.IncludeAnnotation("love.forte.plugin.suspendtrans.annotation.Api4J")
432+
)
433+
434+
// copy the annotations from source function to the synthetic blocking function
435+
copyAnnotationsToSyntheticBlockingFunction = true
436+
437+
// copy the annotations from source function to the synthetic async function
438+
copyAnnotationsToSyntheticAsyncFunction = true
439+
440+
// if 'copyAnnotationsToSyntheticBlockingFunction == true',
441+
// list of annotations to be excluded in the copy process
442+
copyAnnotationsToSyntheticBlockingFunctionExcludes = listOf(
443+
SuspendTransformConfiguration.ExcludeAnnotation("kotlin.jvm.JvmSynthetic")
444+
)
445+
446+
// if 'copyAnnotationsToSyntheticAsyncFunction == true',
447+
// list of annotations to be excluded in the copy process
448+
copyAnnotationsToSyntheticAsyncFunctionExcludes = listOf(
449+
SuspendTransformConfiguration.ExcludeAnnotation("kotlin.jvm.JvmSynthetic")
450+
)
451+
}
452+
453+
js {
454+
// Roughly similar to what is in 'jvm'
455+
}
456+
457+
458+
}
459+
```
460+
461+
## License
462+
463+
see [LICENSE](LICENSE) .
464+
465+
```text
466+
Copyright (c) 2022 ForteScarlet
467+
468+
Permission is hereby granted, free of charge, to any person obtaining a copy
469+
of this software and associated documentation files (the "Software"), to deal
470+
in the Software without restriction, including without limitation the rights
471+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
472+
copies of the Software, and to permit persons to whom the Software is
473+
furnished to do so, subject to the following conditions:
474+
475+
The above copyright notice and this permission notice shall be included in all
476+
copies or substantial portions of the Software.
477+
478+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
479+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
480+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
481+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
482+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
483+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
484+
SOFTWARE.
485+
```

compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/CliOptions.kt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ object CliOptions {
5959
JVM_BLOCKING_MARK_ANNOTATION.option("asPropertyProperty") {
6060
withProp { jvm.jvmBlockingMarkAnnotation::asPropertyProperty }
6161
}
62-
val JVM_BLOCKING_MARK_ANNOTATION_FUNCTION_INHERITABLE =
63-
JVM_BLOCKING_MARK_ANNOTATION.option("functionInheritable") {
64-
inc { jvm.jvmBlockingMarkAnnotation.functionInheritable = it.toBoolean() }
65-
out { jvm.jvmBlockingMarkAnnotation.functionInheritable.toString() }
66-
}
6762
//endregion
6863

6964
val COPY_ANNOTATIONS_TO_SYNTHETIC_BLOCKING_FUNCTION =
@@ -114,11 +109,6 @@ object CliOptions {
114109
JVM_ASYNC_MARK_ANNOTATION.option("asPropertyProperty") {
115110
withProp { jvm.jvmAsyncMarkAnnotation::asPropertyProperty }
116111
}
117-
val JVM_ASYNC_MARK_ANNOTATION_FUNCTION_INHERITABLE =
118-
JVM_ASYNC_MARK_ANNOTATION.option("functionInheritable") {
119-
inc { jvm.jvmAsyncMarkAnnotation.functionInheritable = it.toBoolean() }
120-
out { jvm.jvmAsyncMarkAnnotation.functionInheritable.toString() }
121-
}
122112
//endregion
123113

124114

@@ -157,7 +147,6 @@ object CliOptions {
157147
Jvm.JVM_BLOCKING_MARK_ANNOTATION_BASE_NAME_PROPERTY,
158148
Jvm.JVM_BLOCKING_MARK_ANNOTATION_SUFFIX_PROPERTY,
159149
Jvm.JVM_BLOCKING_MARK_ANNOTATION_AS_PROPERTY_PROPERTY,
160-
Jvm.JVM_BLOCKING_MARK_ANNOTATION_FUNCTION_INHERITABLE,
161150
Jvm.COPY_ANNOTATIONS_TO_SYNTHETIC_BLOCKING_FUNCTION,
162151
Jvm.COPY_ANNOTATIONS_TO_SYNTHETIC_BLOCKING_FUNCTION_EXCLUDES_NAME,
163152
Jvm.SYNTHETIC_BLOCKING_FUNCTION_INCLUDE_ANNOTATIONS,
@@ -166,7 +155,6 @@ object CliOptions {
166155
Jvm.JVM_ASYNC_MARK_ANNOTATION_BASE_NAME_PROPERTY,
167156
Jvm.JVM_ASYNC_MARK_ANNOTATION_SUFFIX_PROPERTY,
168157
Jvm.JVM_ASYNC_MARK_ANNOTATION_AS_PROPERTY_PROPERTY,
169-
Jvm.JVM_ASYNC_MARK_ANNOTATION_FUNCTION_INHERITABLE,
170158
Jvm.SYNTHETIC_ASYNC_FUNCTION_INCLUDE_ANNOTATIONS,
171159
Jvm.COPY_ANNOTATIONS_TO_SYNTHETIC_ASYNC_FUNCTION,
172160
Jvm.COPY_ANNOTATIONS_TO_SYNTHETIC_ASYNC_FUNCTION_EXCLUDES_NAME,

compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/SuspendTransformConfiguration.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ open class SuspendTransformConfiguration @JvmOverloads constructor(var enabled:
184184
var baseNameProperty: String = "baseName",
185185
var suffixProperty: String = "suffix",
186186
var asPropertyProperty: String = "asProperty",
187-
// TODO ?
188-
var functionInheritable: Boolean = false
189187
)
190188
}
191189

compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/utils/AnnotationDescriptorUtils.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ data class TransformAnnotationData(
3838
val suffix: String?,
3939
val asProperty: Boolean?,
4040
val functionName: String,
41-
val functionInheritable: Boolean,
4241
) {
42+
// TODO remove.
43+
val functionInheritable: Boolean = false
44+
4345
companion object {
4446
fun of(
4547
annotationDescriptor: AnnotationDescriptor,
@@ -48,7 +50,6 @@ data class TransformAnnotationData(
4850
annotationAsPropertyPropertyName: String = "asProperty",
4951
defaultBaseName: String,
5052
defaultSuffix: String,
51-
functionInheritable: Boolean,
5253
): TransformAnnotationData {
5354
val baseName = annotationDescriptor.argumentValue(annotationBaseNamePropertyName)
5455
?.accept(AbstractNullableAnnotationArgumentVoidDataVisitor.stringOnly, null)
@@ -66,7 +67,6 @@ data class TransformAnnotationData(
6667
suffix,
6768
asProperty,
6869
functionName,
69-
functionInheritable
7070
)
7171
}
7272
}
@@ -143,15 +143,12 @@ private operator fun TransformAnnotationData?.plus(other: TransformAnnotationDat
143143
suffix?.also(::append)
144144
}
145145

146-
val functionInheritable = other.functionInheritable.takeIf { it } ?: this.functionInheritable
147-
148146
return TransformAnnotationData(
149147
annotationDescriptor = other.annotationDescriptor,
150148
baseName = baseName,
151149
suffix = suffix,
152150
asProperty = asProperty,
153151
functionName = functionName,
154-
functionInheritable = functionInheritable
155152
)
156153

157154
}
@@ -176,7 +173,6 @@ private fun Annotations.resolveToTransformAnnotations(
176173
annotationAsPropertyPropertyName,
177174
defaultBaseName,
178175
defaultSuffix,
179-
functionInheritable
180176
)
181177
}
182178
}

compiler/suspend-transform-plugin/src/test/kotlin/love/forte/plugin/suspendtrans/test/Test.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ class Test {
4242
val modules = sourceModuleInfos.map {
4343
KotlinModule(it, componentRegistrars = listOf(SuspendTransformComponentRegistrar().apply {
4444
defaultConfiguration = SuspendTransformConfiguration().apply {
45-
jvm {
46-
jvmBlockingMarkAnnotation.functionInheritable = true
47-
jvmAsyncMarkAnnotation.functionInheritable = true
48-
}
45+
4946
}
5047
})).apply {
5148
compilation.apply {

plugins/suspend-transform-plugin-gradle/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ buildConfig {
2121

2222
val project = project(":compiler:suspend-transform-plugin-embeddable")
2323
buildConfigField("String", "KOTLIN_PLUGIN_ID", "\"${rootProject.extra["kotlin_plugin_id"]}\"")
24+
buildConfigField("String", "PLUGIN_VERSION", "\"${version}\"")
2425
buildConfigField("String", "KOTLIN_PLUGIN_GROUP", "\"${project.group}\"")
2526
buildConfigField("String", "KOTLIN_PLUGIN_NAME", "\"${project.name}\"")
2627
buildConfigField("String", "KOTLIN_PLUGIN_VERSION", "\"${project.version}\"")

0 commit comments

Comments
 (0)