Skip to content

Commit 7ee0c0a

Browse files
authored
Merge pull request #108 from bnorm/deprecate
Officially deprecate this compiler plugin
2 parents 9d2ff1f + 9a3b266 commit 7ee0c0a

File tree

6 files changed

+56
-52
lines changed

6 files changed

+56
-52
lines changed

README.md

+19-13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.bnorm.power/kotlin-power-assert-plugin/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.bnorm.power/kotlin-power-assert-plugin)
44

5+
> [!IMPORTANT]
6+
> Starting with Kotlin 2.0.0, this compiler plugin has been replaced with an official Kotlin Power-Assert compiler
7+
> plugin. As such, this compiler plugin is no longer supported, and any usage should be replaced with the official
8+
> plugin. See https://kotl.in/power-assert for more information on build setup.
9+
510
Kotlin Compiler Plugin which high-jacks Kotlin assert function calls and
611
transforms them similar to [Groovy's Power Assert feature][groovy-power-assert].
712
This plugin uses the IR backend for the Kotlin compiler and supports all
@@ -155,19 +160,20 @@ used. Check the table below to find when support for a particular version of
155160
Kotlin was first introduced. If a version of Kotlin or this plugin is not listed
156161
it can be assumed to maintain compatibility with the next oldest version listed.
157162

158-
| Kotlin Version | Plugin Version |
159-
|----------------|----------------|
160-
| 1.3.60 | 0.1.0 |
161-
| 1.3.70 | 0.3.0 |
162-
| 1.4.0 | 0.4.0 |
163-
| 1.4.20 | 0.6.0 |
164-
| 1.4.30 | 0.7.0 |
165-
| 1.5.0 | 0.8.0 |
166-
| 1.5.10 | 0.9.0 |
167-
| 1.5.20 | 0.10.0 |
168-
| 1.6.0 | 0.11.0 |
169-
| 1.7.0 | 0.12.0 |
170-
| 1.8.20 | 0.13.0 |
163+
| Kotlin Version | Plugin Version |
164+
|------------------|----------------------------------------------------------|
165+
| 1.3.60 | 0.1.0 |
166+
| 1.3.70 | 0.3.0 |
167+
| 1.4.0 | 0.4.0 |
168+
| 1.4.20 | 0.6.0 |
169+
| 1.4.30 | 0.7.0 |
170+
| 1.5.0 | 0.8.0 |
171+
| 1.5.10 | 0.9.0 |
172+
| 1.5.20 | 0.10.0 |
173+
| 1.6.0 | 0.11.0 |
174+
| 1.7.0 | 0.12.0 |
175+
| 1.8.20 | 0.13.0 |
176+
| 2.0.0 and beyond | Official support by Kotlin: https://kotl.in/power-assert |
171177

172178
## Kotlin IR
173179

kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradleExtension.kt

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
package com.bnorm.power
1818

19+
@Deprecated(
20+
message = "Replace with the official Kotlin Power-Assert compiler plugin: https://kotl.in/power-assert",
21+
level = DeprecationLevel.ERROR,
22+
)
1923
open class PowerAssertGradleExtension {
2024
var functions: List<String> = listOf("kotlin.assert")
2125
var excludedSourceSets: List<String> = listOf()

kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt

+18-32
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,27 @@
1616

1717
package com.bnorm.power
1818

19+
import org.gradle.api.GradleException
20+
import org.gradle.api.Plugin
1921
import org.gradle.api.Project
20-
import org.gradle.api.provider.Provider
21-
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
22-
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin
23-
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact
24-
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
2522

26-
class PowerAssertGradlePlugin : KotlinCompilerPluginSupportPlugin {
27-
override fun apply(target: Project): Unit = with(target) {
28-
extensions.create("kotlinPowerAssert", PowerAssertGradleExtension::class.java)
23+
class PowerAssertGradlePlugin : Plugin<Project> {
24+
companion object {
25+
private val DEPRECATION_EXCEPTION_MESSAGE =
26+
"Starting with Kotlin 2.0.0, kotlin-power-assert is no longer supported. " +
27+
"Please switch to the official Kotlin power-assert compiler plugin: https://kotl.in/power-assert" +
28+
"\n\n" +
29+
"""
30+
Replace the kotlin-power-assert Gradle plugin with one of the following:
31+
32+
plugins {
33+
kotlin("plugin.power-assert") version "<kotlin-version>" // Kts format
34+
id 'org.jetbrains.kotlin.plugin.power-assert' version '<kotlin-version>' // Groovy format
35+
}
36+
""".trimIndent()
2937
}
3038

31-
override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean {
32-
val project = kotlinCompilation.target.project
33-
val extension = project.extensions.getByType(PowerAssertGradleExtension::class.java)
34-
return extension.excludedSourceSets.none { it == kotlinCompilation.defaultSourceSet.name }
35-
}
36-
37-
override fun getCompilerPluginId(): String = "com.bnorm.kotlin-power-assert"
38-
39-
override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact(
40-
groupId = BuildConfig.PLUGIN_GROUP_ID,
41-
artifactId = BuildConfig.PLUGIN_ARTIFACT_ID,
42-
version = BuildConfig.PLUGIN_VERSION,
43-
)
44-
45-
override fun applyToCompilation(
46-
kotlinCompilation: KotlinCompilation<*>,
47-
): Provider<List<SubpluginOption>> {
48-
val project = kotlinCompilation.target.project
49-
val extension = project.extensions.getByType(PowerAssertGradleExtension::class.java)
50-
return project.provider {
51-
extension.functions.map {
52-
SubpluginOption(key = "function", value = it)
53-
}
54-
}
39+
override fun apply(target: Project) {
40+
throw GradleException(DEPRECATION_EXCEPTION_MESSAGE)
5541
}
5642
}

kotlin-power-assert-plugin/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ tasks.withType<KotlinCompile> {
2929
}
3030

3131
tasks.withType<Test> {
32+
enabled = false
3233
useJUnitPlatform()
3334
}
3435

kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt

+14-5
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package com.bnorm.power
1818

19-
import com.bnorm.power.diagram.SourceFile
2019
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
2120
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
21+
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
2222
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
2323
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
2424
import org.jetbrains.kotlin.name.FqName
@@ -27,10 +27,19 @@ class PowerAssertIrGenerationExtension(
2727
private val messageCollector: MessageCollector,
2828
private val functions: Set<FqName>,
2929
) : IrGenerationExtension {
30+
companion object {
31+
private val DEPRECATION_EXCEPTION_MESSAGE =
32+
"Starting with Kotlin 2.0.0, kotlin-power-assert is no longer supported. " +
33+
"Please switch to the official Kotlin power-assert compiler plugin: https://kotl.in/power-assert" +
34+
"\n\n" +
35+
"""
36+
Replace the kotlin-power-assert compiler plugin artifact with one of the following:
37+
- 'org.jetbrains.kotlin:kotlin-power-assert-compiler-plugin:<kotlin-version>'
38+
- 'org.jetbrains.kotlin:kotlin-power-assert-compiler-plugin-embeddable:<kotlin-version>'
39+
""".trimIndent()
40+
}
41+
3042
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
31-
for (file in moduleFragment.files) {
32-
PowerAssertCallTransformer(SourceFile(file), pluginContext, messageCollector, functions)
33-
.visitFile(file)
34-
}
43+
messageCollector.report(CompilerMessageSeverity.ERROR, DEPRECATION_EXCEPTION_MESSAGE)
3544
}
3645
}

sample/settings.gradle.kts

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
rootProject.name = "kotlin-power-assert-sample"
2-
3-
includeBuild("..")

0 commit comments

Comments
 (0)