Skip to content

Commit

Permalink
Merge pull request #108 from bnorm/deprecate
Browse files Browse the repository at this point in the history
Officially deprecate this compiler plugin
  • Loading branch information
bnorm authored Jun 20, 2024
2 parents 9d2ff1f + 9a3b266 commit 7ee0c0a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 52 deletions.
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

[![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)

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

| Kotlin Version | Plugin Version |
|----------------|----------------|
| 1.3.60 | 0.1.0 |
| 1.3.70 | 0.3.0 |
| 1.4.0 | 0.4.0 |
| 1.4.20 | 0.6.0 |
| 1.4.30 | 0.7.0 |
| 1.5.0 | 0.8.0 |
| 1.5.10 | 0.9.0 |
| 1.5.20 | 0.10.0 |
| 1.6.0 | 0.11.0 |
| 1.7.0 | 0.12.0 |
| 1.8.20 | 0.13.0 |
| Kotlin Version | Plugin Version |
|------------------|----------------------------------------------------------|
| 1.3.60 | 0.1.0 |
| 1.3.70 | 0.3.0 |
| 1.4.0 | 0.4.0 |
| 1.4.20 | 0.6.0 |
| 1.4.30 | 0.7.0 |
| 1.5.0 | 0.8.0 |
| 1.5.10 | 0.9.0 |
| 1.5.20 | 0.10.0 |
| 1.6.0 | 0.11.0 |
| 1.7.0 | 0.12.0 |
| 1.8.20 | 0.13.0 |
| 2.0.0 and beyond | Official support by Kotlin: https://kotl.in/power-assert |

## Kotlin IR

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

package com.bnorm.power

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

Check warning on line 24 in kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradleExtension.kt

View workflow job for this annotation

GitHub Actions / Qodana

Unused symbol

Property "functions" is never used
var excludedSourceSets: List<String> = listOf()

Check warning on line 25 in kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradleExtension.kt

View workflow job for this annotation

GitHub Actions / Qodana

Unused symbol

Property "excludedSourceSets" is never used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,27 @@

package com.bnorm.power

import org.gradle.api.GradleException
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.provider.Provider
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerPluginSupportPlugin
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact
import org.jetbrains.kotlin.gradle.plugin.SubpluginOption

class PowerAssertGradlePlugin : KotlinCompilerPluginSupportPlugin {
override fun apply(target: Project): Unit = with(target) {
extensions.create("kotlinPowerAssert", PowerAssertGradleExtension::class.java)
class PowerAssertGradlePlugin : Plugin<Project> {

Check warning on line 23 in kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt

View workflow job for this annotation

GitHub Actions / Qodana

Unused symbol

Class "PowerAssertGradlePlugin" is never used
companion object {
private val DEPRECATION_EXCEPTION_MESSAGE =
"Starting with Kotlin 2.0.0, kotlin-power-assert is no longer supported. " +
"Please switch to the official Kotlin power-assert compiler plugin: https://kotl.in/power-assert" +
"\n\n" +
"""
Replace the kotlin-power-assert Gradle plugin with one of the following:
plugins {
kotlin("plugin.power-assert") version "<kotlin-version>" // Kts format
id 'org.jetbrains.kotlin.plugin.power-assert' version '<kotlin-version>' // Groovy format
}
""".trimIndent()
}

override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean {
val project = kotlinCompilation.target.project
val extension = project.extensions.getByType(PowerAssertGradleExtension::class.java)
return extension.excludedSourceSets.none { it == kotlinCompilation.defaultSourceSet.name }
}

override fun getCompilerPluginId(): String = "com.bnorm.kotlin-power-assert"

override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact(
groupId = BuildConfig.PLUGIN_GROUP_ID,
artifactId = BuildConfig.PLUGIN_ARTIFACT_ID,
version = BuildConfig.PLUGIN_VERSION,
)

override fun applyToCompilation(
kotlinCompilation: KotlinCompilation<*>,
): Provider<List<SubpluginOption>> {
val project = kotlinCompilation.target.project
val extension = project.extensions.getByType(PowerAssertGradleExtension::class.java)
return project.provider {
extension.functions.map {
SubpluginOption(key = "function", value = it)
}
}
override fun apply(target: Project) {
throw GradleException(DEPRECATION_EXCEPTION_MESSAGE)
}
}
1 change: 1 addition & 0 deletions kotlin-power-assert-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ tasks.withType<KotlinCompile> {
}

tasks.withType<Test> {
enabled = false
useJUnitPlatform()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package com.bnorm.power

import com.bnorm.power.diagram.SourceFile
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.name.FqName
Expand All @@ -27,10 +27,19 @@ class PowerAssertIrGenerationExtension(
private val messageCollector: MessageCollector,
private val functions: Set<FqName>,

Check warning on line 28 in kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt

View workflow job for this annotation

GitHub Actions / Qodana

Unused symbol

Property "functions" is never used
) : IrGenerationExtension {
companion object {
private val DEPRECATION_EXCEPTION_MESSAGE =
"Starting with Kotlin 2.0.0, kotlin-power-assert is no longer supported. " +
"Please switch to the official Kotlin power-assert compiler plugin: https://kotl.in/power-assert" +
"\n\n" +
"""
Replace the kotlin-power-assert compiler plugin artifact with one of the following:
- 'org.jetbrains.kotlin:kotlin-power-assert-compiler-plugin:<kotlin-version>'
- 'org.jetbrains.kotlin:kotlin-power-assert-compiler-plugin-embeddable:<kotlin-version>'
""".trimIndent()
}

override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) {
for (file in moduleFragment.files) {
PowerAssertCallTransformer(SourceFile(file), pluginContext, messageCollector, functions)
.visitFile(file)
}
messageCollector.report(CompilerMessageSeverity.ERROR, DEPRECATION_EXCEPTION_MESSAGE)
}
}
2 changes: 0 additions & 2 deletions sample/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
rootProject.name = "kotlin-power-assert-sample"

includeBuild("..")

0 comments on commit 7ee0c0a

Please sign in to comment.