Skip to content

Commit

Permalink
v0.6.0-beta4
Browse files Browse the repository at this point in the history
  • Loading branch information
ForteScarlet committed Jan 12, 2024
1 parent 612fe44 commit 5582a04
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 44 deletions.
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/IProject.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import love.forte.gradle.common.core.project.ProjectDetail
import love.forte.gradle.common.core.project.Version
import love.forte.gradle.common.core.project.minus
import love.forte.gradle.common.core.project.version

object IProject : ProjectDetail() {
Expand All @@ -8,7 +9,7 @@ object IProject : ProjectDetail() {
const val DESCRIPTION = "Generate platform-compatible functions for Kotlin suspend functions"
const val HOMEPAGE = "https://github.com/ForteScarlet/kotlin-suspend-transform-compiler-plugin"

override val version: Version = version(0, 6, 0)
override val version: Version = version(0, 6, 0) - version("beta4")

override val homepage: String get() = HOMEPAGE

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package love.forte.plugin.suspendtrans

import BuildConfig
import com.google.auto.service.AutoService
import org.jetbrains.kotlin.compiler.plugin.AbstractCliOption
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
Expand All @@ -17,7 +16,7 @@ class SuspendTransformCommandLineProcessor : CommandLineProcessor {
CompilerConfigurationKey.create(CliOptions.CONFIGURATION)
}

override val pluginId: String = BuildConfig.KOTLIN_PLUGIN_ID
override val pluginId: String = SuspendTransPluginConstants.KOTLIN_PLUGIN_ID

override val pluginOptions: Collection<SimpleCliOption> = CliOptions.allOptions.map { it as SimpleCliOption }

Expand Down
5 changes: 3 additions & 2 deletions plugins/suspend-transform-plugin-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ dependencies {
}

buildConfig {
className("SuspendTransPluginConstants")
useKotlinOutput {
internalVisibility = true
internalVisibility = false
}
withoutPackage()
packageName("love.forte.plugin.suspendtrans.gradle")

val project = project(":compiler:suspend-transform-plugin-embeddable")
buildConfigField("String", "KOTLIN_PLUGIN_ID", "\"${rootProject.extra["kotlin_plugin_id"]}\"")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import love.forte.plugin.suspendtrans.gradle.SuspendTransPluginConstants

@Deprecated(
"Use SuspendTransPluginConstants",
ReplaceWith(
"SuspendTransPluginConstants",
imports = ["love.forte.plugin.suspendtrans.gradle.SuspendTransPluginConstants"]
)
)
internal object BuildConfig {
internal const val KOTLIN_PLUGIN_ID: String = SuspendTransPluginConstants.KOTLIN_PLUGIN_ID

internal const val PLUGIN_VERSION: String = SuspendTransPluginConstants.PLUGIN_VERSION

internal const val KOTLIN_PLUGIN_GROUP: String = SuspendTransPluginConstants.KOTLIN_PLUGIN_GROUP

internal const val KOTLIN_PLUGIN_NAME: String = SuspendTransPluginConstants.KOTLIN_PLUGIN_NAME

internal const val KOTLIN_PLUGIN_VERSION: String = SuspendTransPluginConstants.KOTLIN_PLUGIN_VERSION

internal const val ANNOTATION_GROUP: String = SuspendTransPluginConstants.ANNOTATION_GROUP

internal const val ANNOTATION_NAME: String = SuspendTransPluginConstants.ANNOTATION_NAME

internal const val ANNOTATION_VERSION: String = SuspendTransPluginConstants.ANNOTATION_VERSION

internal const val RUNTIME_GROUP: String = SuspendTransPluginConstants.RUNTIME_GROUP

internal const val RUNTIME_NAME: String = SuspendTransPluginConstants.RUNTIME_NAME

internal const val RUNTIME_VERSION: String = SuspendTransPluginConstants.RUNTIME_VERSION
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

package love.forte.plugin.suspendtrans.gradle

import BuildConfig.KOTLIN_PLUGIN_ID
import BuildConfig.PLUGIN_VERSION
import love.forte.plugin.suspendtrans.gradle.SuspendTransPluginConstants.KOTLIN_PLUGIN_ID
import love.forte.plugin.suspendtrans.gradle.SuspendTransPluginConstants.PLUGIN_VERSION


val org.gradle.plugin.use.PluginDependenciesSpec.`suspend-transform`: org.gradle.plugin.use.PluginDependencySpec
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package love.forte.plugin.suspendtrans.gradle

import BuildConfig
import love.forte.plugin.suspendtrans.SuspendTransformConfiguration


Expand All @@ -15,7 +14,7 @@ open class SuspendTransformGradleExtension : SuspendTransformConfiguration() {
*/
var includeAnnotation: Boolean = true

var annotationDependencyVersion: String = BuildConfig.ANNOTATION_VERSION
var annotationDependencyVersion: String = SuspendTransPluginConstants.ANNOTATION_VERSION

/**
* 当 [includeAnnotation] 为 true 时,配置runtime环境的依赖方式。默认为 `compileOnly` (在JVM中) 。
Expand All @@ -27,7 +26,7 @@ open class SuspendTransformGradleExtension : SuspendTransformConfiguration() {
*/
var includeRuntime: Boolean = true

var runtimeDependencyVersion: String = BuildConfig.RUNTIME_VERSION
var runtimeDependencyVersion: String = SuspendTransPluginConstants.RUNTIME_VERSION

/**
* 当 [includeRuntime] 为 true 时,配置runtime环境的依赖方式。默认为 `implementation` (在JVM中)。
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package love.forte.plugin.suspendtrans.gradle

import BuildConfig
import love.forte.plugin.suspendtrans.CliOptions
import org.gradle.api.Project
import org.gradle.api.provider.Provider
Expand All @@ -22,13 +21,13 @@ open class SuspendTransformGradlePlugin : KotlinCompilerPluginSupportPlugin {
return kotlinCompilation.target.project.plugins.hasPlugin(SuspendTransformGradlePlugin::class.java)
}

override fun getCompilerPluginId(): String = BuildConfig.KOTLIN_PLUGIN_ID
override fun getCompilerPluginId(): String = SuspendTransPluginConstants.KOTLIN_PLUGIN_ID

override fun getPluginArtifact(): SubpluginArtifact {
return SubpluginArtifact(
groupId = BuildConfig.KOTLIN_PLUGIN_GROUP,
artifactId = BuildConfig.KOTLIN_PLUGIN_NAME,
version = BuildConfig.KOTLIN_PLUGIN_VERSION
groupId = SuspendTransPluginConstants.KOTLIN_PLUGIN_GROUP,
artifactId = SuspendTransPluginConstants.KOTLIN_PLUGIN_NAME,
version = SuspendTransPluginConstants.KOTLIN_PLUGIN_VERSION
)
}

Expand All @@ -42,12 +41,12 @@ open class SuspendTransformGradlePlugin : KotlinCompilerPluginSupportPlugin {
// val dependencies = project.dependencies
// dependencies.add(
// "compileOnly",
// "${BuildConfig.ANNOTATION_GROUP}:${BuildConfig.ANNOTATION_NAME}:${BuildConfig.ANNOTATION_VERSION}"
// "${SuspendTransPluginConstants.ANNOTATION_GROUP}:${SuspendTransPluginConstants.ANNOTATION_NAME}:${SuspendTransPluginConstants.ANNOTATION_VERSION}"
// )
// if (extension.includeRuntime) {
// dependencies.add(
// extension.runtimeConfigurationName,
// "${BuildConfig.RUNTIME_GROUP}:${BuildConfig.RUNTIME_NAME}:${BuildConfig.RUNTIME_VERSION}"
// "${SuspendTransPluginConstants.RUNTIME_GROUP}:${SuspendTransPluginConstants.RUNTIME_NAME}:${SuspendTransPluginConstants.RUNTIME_VERSION}"
// )
// }

Expand All @@ -71,18 +70,23 @@ private fun Project.configureDependencies() {
fun Project.include(platform: Platform, conf: SuspendTransformGradleExtension) {
if (conf.includeAnnotation) {
val notation = getDependencyNotation(
BuildConfig.ANNOTATION_GROUP,
BuildConfig.ANNOTATION_NAME,
SuspendTransPluginConstants.ANNOTATION_GROUP,
SuspendTransPluginConstants.ANNOTATION_NAME,
platform,
conf.annotationDependencyVersion
)
dependencies.add(conf.annotationConfigurationName, notation)
if (platform == Platform.JVM) {
dependencies.add(conf.annotationConfigurationName, notation)
} else {
// JS, native 似乎不支持其他的 name,例如 compileOnly
dependencies.add("implementation", notation)
}
dependencies.add("testImplementation", notation)
}
if (conf.includeRuntime) {
val notation = getDependencyNotation(
BuildConfig.RUNTIME_GROUP,
BuildConfig.RUNTIME_NAME,
SuspendTransPluginConstants.RUNTIME_GROUP,
SuspendTransPluginConstants.RUNTIME_NAME,
platform,
conf.runtimeDependencyVersion
)
Expand Down Expand Up @@ -129,45 +133,48 @@ fun Project.withPluginWhenEvaluatedConf(

fun Project.configureMultiplatformDependency(conf: SuspendTransformGradleExtension) {
if (rootProject.getBooleanProperty("kotlin.mpp.enableGranularSourceSetsMetadata")) {
val mainSourceSets = project.extensions.getByType(KotlinMultiplatformExtension::class.java).sourceSets
.getByName(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME)
val testSourceSets = project.extensions.getByType(KotlinMultiplatformExtension::class.java).sourceSets
.getByName(KotlinSourceSet.COMMON_TEST_SOURCE_SET_NAME)
val multiplatformExtensions = project.extensions.getByType(KotlinMultiplatformExtension::class.java)

val commonMainSourceSets =
multiplatformExtensions.sourceSets.getByName(KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME)
val commonTestSourceSets =
multiplatformExtensions.sourceSets.getByName(KotlinSourceSet.COMMON_TEST_SOURCE_SET_NAME)

if (conf.includeAnnotation) {
val notation = getDependencyNotation(
BuildConfig.ANNOTATION_GROUP,
BuildConfig.ANNOTATION_NAME,
SuspendTransPluginConstants.ANNOTATION_GROUP,
SuspendTransPluginConstants.ANNOTATION_NAME,
Platform.MULTIPLATFORM,
conf.annotationDependencyVersion
)
dependencies.add(mainSourceSets.compileOnlyConfigurationName, notation)
dependencies.add(testSourceSets.implementationConfigurationName, notation)
dependencies.add(commonMainSourceSets.compileOnlyConfigurationName, notation)
dependencies.add(commonTestSourceSets.implementationConfigurationName, notation)
}

if (conf.includeRuntime) {
val notation = getDependencyNotation(
BuildConfig.RUNTIME_GROUP,
BuildConfig.RUNTIME_NAME,
SuspendTransPluginConstants.RUNTIME_GROUP,
SuspendTransPluginConstants.RUNTIME_NAME,
Platform.MULTIPLATFORM,
conf.annotationDependencyVersion
)
dependencies.add(mainSourceSets.implementationConfigurationName, notation)
dependencies.add(testSourceSets.implementationConfigurationName, notation)
dependencies.add(commonMainSourceSets.implementationConfigurationName, notation)
dependencies.add(commonTestSourceSets.implementationConfigurationName, notation)
}

// For each source set that is only used in Native compilations, add an implementation dependency so that it
// gets published and is properly consumed as a transitive dependency:
sourceSetsByCompilation().forEach { (sourceSet, compilations) ->
val isSharedNativeSourceSet = compilations.all {
val isSharedSourceSet = compilations.all {
it.platformType == KotlinPlatformType.common || it.platformType == KotlinPlatformType.native
|| it.platformType == KotlinPlatformType.js || it.platformType == KotlinPlatformType.wasm
}
if (isSharedNativeSourceSet) {

if (isSharedSourceSet) {
if (conf.includeAnnotation) {
val notation = getDependencyNotation(
BuildConfig.ANNOTATION_GROUP,
BuildConfig.ANNOTATION_NAME,
SuspendTransPluginConstants.ANNOTATION_GROUP,
SuspendTransPluginConstants.ANNOTATION_NAME,
Platform.MULTIPLATFORM,
conf.annotationDependencyVersion
)
Expand All @@ -177,8 +184,8 @@ fun Project.configureMultiplatformDependency(conf: SuspendTransformGradleExtensi

if (conf.includeRuntime) {
val notation = getDependencyNotation(
BuildConfig.RUNTIME_GROUP,
BuildConfig.RUNTIME_NAME,
SuspendTransPluginConstants.RUNTIME_GROUP,
SuspendTransPluginConstants.RUNTIME_NAME,
Platform.MULTIPLATFORM,
conf.annotationDependencyVersion
)
Expand Down Expand Up @@ -215,8 +222,8 @@ fun Project.configureMultiplatformDependency(conf: SuspendTransformGradleExtensi
}

val notation = getDependencyNotation(
BuildConfig.ANNOTATION_GROUP,
BuildConfig.ANNOTATION_NAME,
SuspendTransPluginConstants.ANNOTATION_GROUP,
SuspendTransPluginConstants.ANNOTATION_NAME,
platform,
conf.annotationDependencyVersion
)
Expand All @@ -227,8 +234,8 @@ fun Project.configureMultiplatformDependency(conf: SuspendTransformGradleExtensi
val configurationName = sourceSet.implementationConfigurationName

val notation = getDependencyNotation(
BuildConfig.RUNTIME_GROUP,
BuildConfig.RUNTIME_NAME,
SuspendTransPluginConstants.RUNTIME_GROUP,
SuspendTransPluginConstants.RUNTIME_NAME,
platform,
conf.runtimeDependencyVersion
)
Expand Down

0 comments on commit 5582a04

Please sign in to comment.