Skip to content

Commit

Permalink
Kotlin compiler plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Neeme Praks committed Jan 14, 2025
1 parent e14380d commit e77837f
Show file tree
Hide file tree
Showing 31 changed files with 296,309 additions and 4 deletions.
9 changes: 8 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {
extra["kotlin_plugin_id"] = "io.github.oshai.kotlinlogging.kotlin-ir-plugin"
extra["kotlin_plugin_package_name"] = "io.github.oshai.kotlinlogging.irplugin"
}

plugins {
kotlin("multiplatform") version "2.0.21"
// This version is dependent on the maximum tested version
Expand All @@ -14,9 +19,11 @@ plugins {

id("org.jetbrains.dokka") version "2.0.0"

id("com.diffplug.spotless") version "7.0.1"
id("com.diffplug.spotless")

id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
id("com.gradle.plugin-publish") version "1.2.1" apply false
id("com.github.gmazzo.buildconfig") version "5.3.5" apply false
`maven-publish`
signing
}
Expand Down
4 changes: 4 additions & 0 deletions kotlin-ir-plugin-gradle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Gradle wrapper plugin for Kotlin (IR) compiler plugin for kotlin-logging

Just a Gradle wrapper for the Kotlin (IR) Compiler plugin for kotlin-logging,
see [kotlin-ir-plugin](../kotlin-ir-plugin) for the actual Kotlin (IR) compiler plugin.
52 changes: 52 additions & 0 deletions kotlin-ir-plugin-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
plugins {
id("java-gradle-plugin")
id("com.gradle.plugin-publish") version "1.2.1"
kotlin("jvm")
id("com.github.gmazzo.buildconfig")
id("com.diffplug.spotless")

}
repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("gradle-plugin-api"))
}

buildConfig {
val project = project(":kotlin-ir-plugin")
packageName("${rootProject.extra["kotlin_plugin_package_name"]}")
buildConfigField("String", "KOTLIN_PLUGIN_ID", "\"${rootProject.extra["kotlin_plugin_id"]}\"")
buildConfigField("String", "KOTLIN_PLUGIN_GROUP", "\"${project.group}\"")
buildConfigField("String", "KOTLIN_PLUGIN_NAME", "\"${project.name}\"")
buildConfigField("String", "KOTLIN_PLUGIN_VERSION", "\"${project.version}\"")
}

gradlePlugin {
plugins {
create("kotlinLoggingIrPlugin") {
id = rootProject.extra["kotlin_plugin_id"] as String
displayName = "kotlin-logging IR plugin"
description = "Collects metadata about logging calls from the source code and adds it to the respective calls"
implementationClass = "io.github.oshai.kotlinlogging.irplugin.KotlinLoggingGradlePlugin"
}
}
}

publishing {
repositories {
maven {
name = "localPluginRepository"
url = uri(rootProject.layout.buildDirectory.dir("local-plugin-repository"))
}
}
}

// Static code analysis tools
spotless {
kotlin {
target("src/**/*.kt")
ktfmt("0.47").googleStyle()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2020 Brian Norman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.oshai.kotlinlogging.irplugin

import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property

// Based on https://github.com/bnorm/kotlin-ir-plugin-template
open class KotlinLoggingGradleExtension(objects: ObjectFactory) {
val disableAll: Property<String> = objects.property(String::class.java)
val disableTransformingDeprecatedApi: Property<String> = objects.property(String::class.java)
val disableTransformingNotImplementedApi: Property<String> = objects.property(String::class.java)
val disableTransformingEntryExitApi: Property<String> = objects.property(String::class.java)
val disableTransformingThrowingCatchingApi: Property<String> =
objects.property(String::class.java)
val disableCollectingCallSiteInformation: Property<String> = objects.property(String::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2020 Brian Norman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.github.oshai.kotlinlogging.irplugin

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

// Based on https://github.com/bnorm/kotlin-ir-plugin-template
class KotlinLoggingGradlePlugin : KotlinCompilerPluginSupportPlugin {
override fun apply(target: Project): Unit =
with(target) { extensions.create("kotlinlogging", KotlinLoggingGradleExtension::class.java) }

override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = true

override fun getCompilerPluginId(): String = BuildConfig.KOTLIN_PLUGIN_ID

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

override fun applyToCompilation(
kotlinCompilation: KotlinCompilation<*>
): Provider<List<SubpluginOption>> {
val project = kotlinCompilation.target.project
val extension = project.extensions.getByType(KotlinLoggingGradleExtension::class.java)
return project.provider {
listOf(
SubpluginOption(key = "disableAll", value = extension.disableAll.get()),
SubpluginOption(
key = "disableTransformingDeprecatedApi",
value = extension.disableTransformingDeprecatedApi.get(),
),
SubpluginOption(
key = "disableTransformingNotImplementedApi",
value = extension.disableTransformingNotImplementedApi.get(),
),
SubpluginOption(
key = "disableTransformingEntryExitApi",
value = extension.disableTransformingEntryExitApi.get(),
),
SubpluginOption(
key = "disableTransformingThrowingCatchingApi",
value = extension.disableTransformingThrowingCatchingApi.get(),
),
SubpluginOption(
key = "disableCollectingCallSiteInformation",
value = extension.disableCollectingCallSiteInformation.get(),
),
)
}
}
}
Loading

0 comments on commit e77837f

Please sign in to comment.