-
-
Notifications
You must be signed in to change notification settings - Fork 116
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
Kotlin compiler plugin #470
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to look at something a bit more recent, you can check out piecemeal, a compiler-plugin I've been slowly working on myself. |
||
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) | ||
Comment on lines
+24
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would make these boolean properties and then convert to and from a String when creating the SubpluginOptions. That will make it more clear how to configure the Gradle options. Also, if you want to provide a default, you can use
|
||
} |
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(), | ||
), | ||
) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would drop the IR naming of the plugin and just call it "kotlin plugin" or something like that. I really should update that template and drop the IR part of the name. There's many things you can do now with a compiler plugin that have nothing to do with IR.