Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Officially deprecate this compiler plugin #108

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,7 +16,11 @@

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
}
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:

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

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt#L30 <standard:string-template-indent>

Unexpected indent of raw string literal
Raw output
kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt:30:11: error: Unexpected indent of raw string literal (standard:string-template-indent)

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

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt#L31 <standard:string-template-indent>

Unexpected indent of raw string literal
Raw output
kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt:31:11: error: Unexpected indent of raw string literal (standard:string-template-indent)
plugins {

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

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt#L32 <standard:string-template-indent>

Unexpected indent of raw string literal
Raw output
kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt:32:11: error: Unexpected indent of raw string literal (standard:string-template-indent)
kotlin("plugin.power-assert") version "<kotlin-version>" // Kts format

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

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt#L33 <standard:string-template-indent>

Unexpected indent of raw string literal
Raw output
kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt:33:11: error: Unexpected indent of raw string literal (standard:string-template-indent)
id 'org.jetbrains.kotlin.plugin.power-assert' version '<kotlin-version>' // Groovy format

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

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt#L34 <standard:string-template-indent>

Unexpected indent of raw string literal
Raw output
kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt:34:11: error: Unexpected indent of raw string literal (standard:string-template-indent)
}

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

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt#L35 <standard:string-template-indent>

Unexpected indent of raw string literal
Raw output
kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt:35:11: error: Unexpected indent of raw string literal (standard:string-template-indent)
""".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) {

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

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt#L39 <standard:function-expression-body>

Function body should be replaced with body expression
Raw output
kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradlePlugin.kt:39:39: error: Function body should be replaced with body expression (standard:function-expression-body)
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,21 +16,30 @@

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

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:

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

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt#L36 <standard:string-template-indent>

Unexpected indent of raw string literal
Raw output
kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt:36:11: error: Unexpected indent of raw string literal (standard:string-template-indent)
- 'org.jetbrains.kotlin:kotlin-power-assert-compiler-plugin:<kotlin-version>'

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

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt#L37 <standard:string-template-indent>

Unexpected indent of raw string literal
Raw output
kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt:37:11: error: Unexpected indent of raw string literal (standard:string-template-indent)
- 'org.jetbrains.kotlin:kotlin-power-assert-compiler-plugin-embeddable:<kotlin-version>'

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

View workflow job for this annotation

GitHub Actions / ktlint

[ktlint] kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt#L38 <standard:string-template-indent>

Unexpected indent of raw string literal
Raw output
kotlin-power-assert-plugin/src/main/kotlin/com/bnorm/power/PowerAssertIrGenerationExtension.kt:38:11: error: Unexpected indent of raw string literal (standard:string-template-indent)
""".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("..")
Loading