Compare commits

...

101 Commits
v0.1.2 ... main

Author SHA1 Message Date
renovate[bot] 9c82a57cb1
chore(deps): update dependency gradle to v8.8 2024-06-01 11:56:14 +00:00
renovate[bot] 62ffd333f4
fix(deps): update dependency com.github.ajalt.mordant:mordant to v2.6.0 2024-05-25 02:27:34 +00:00
renovate[bot] 7f359510c4
fix(deps): update dependency com.android.tools.build:gradle to v8.4.1 2024-05-24 05:50:27 +00:00
renovate[bot] 794b269673
chore(deps): update plugin android-library to v8.4.1 2024-05-23 17:50:57 +00:00
renovate[bot] 3e18628994
chore(deps): update actions/checkout action to v4.1.6 2024-05-22 20:50:54 +00:00
renovate[bot] 7c7671be48
chore(deps): update actions/checkout action to v4.1.5 2024-05-09 05:31:37 +00:00
renovate[bot] 96a4ba1473
fix(deps): update dependency com.android.tools.build:gradle to v8.4.0 2024-05-01 05:23:19 +00:00
renovate[bot] 66d7a729a8
chore(deps): update plugin android-library to v8.4.0 2024-04-30 17:52:28 +00:00
renovate[bot] ccd8ed65aa
chore(deps): update gradle/gradle-build-action action to v3.3.2 2024-04-28 20:43:02 +00:00
renovate[bot] 61b96c7457
chore(deps): update actions/checkout action to v4.1.4 2024-04-27 05:48:10 +00:00
renovate[bot] 47650c0f52
fix(deps): update dependency com.github.ajalt.mordant:mordant to v2.5.0 2024-04-24 23:28:55 +00:00
renovate[bot] 0d082f62a8
chore(deps): update dependency macos to v14 2024-04-23 05:38:05 +00:00
renovate[bot] 49081d99eb
chore(deps): update actions/checkout action to v4.1.3 2024-04-22 23:30:56 +00:00
renovate[bot] 0800c8c991
chore(deps): update gradle/gradle-build-action action to v3.3.1 2024-04-19 20:30:53 +00:00
renovate[bot] ad8056153e
chore(deps): update gradle/gradle-build-action action to v3.3.0 2024-04-14 20:54:17 +00:00
renovate[bot] c8e5499614
fix(deps): update dependency com.android.tools.build:gradle to v8.3.2 2024-04-13 09:00:03 +00:00
renovate[bot] bc832aef86
chore(deps): update plugin android-library to v8.3.2 2024-04-10 01:35:32 +00:00
renovate[bot] 533738b0fc
chore(deps): update gradle/gradle-build-action action to v3.2.1 2024-04-08 20:54:37 +00:00
renovate[bot] 3bcf79bd7f
fix(deps): update dependency dev.zacsweers.kctfork:core to v0.4.1 2024-03-27 02:57:50 +00:00
renovate[bot] e6134ce457
chore(deps): update dependency gradle to v8.7 2024-03-24 09:03:28 +00:00
renovate[bot] 781775052a
fix(deps): update dependency com.android.tools.build:gradle to v8.3.1 2024-03-23 23:34:04 +00:00
renovate[bot] 91491709f5
chore(deps): update plugin android-library to v8.3.1 2024-03-22 08:57:27 +00:00
renovate[bot] 2806836307
chore(deps): update actions/cache action to v4.0.2 2024-03-20 05:35:41 +00:00
renovate[bot] 9038384337
fix(deps): update dependency com.github.ajalt.mordant:mordant to v2.4.0 2024-03-16 08:55:21 +00:00
renovate[bot] 9c0f35ab8c
chore(deps): update actions/setup-java action to v4.2.1 2024-03-15 05:57:07 +00:00
renovate[bot] 039a714f52
fix(deps): update dependency com.android.tools.build:gradle to v8.3.0 2024-03-07 20:42:48 +00:00
renovate[bot] eec5dbbba0
chore(deps): update plugin dokka to v1.9.20 2024-03-05 05:51:05 +00:00
renovate[bot] adf6fdc1f6
chore(deps): update plugin android-library to v8.3.0 2024-03-03 02:18:19 +00:00
renovate[bot] 2fc9e10428
fix(deps): update dependency com.google.truth:truth to v1.4.2 2024-03-02 05:50:24 +00:00
renovate[bot] c7c6647599
chore(deps): update actions/cache action to v4.0.1 2024-03-01 05:27:28 +00:00
renovate[bot] bf6a47c16a
chore(deps): update actions/setup-java action to v4.1.0 2024-02-29 11:59:42 +00:00
renovate[bot] bad82d6cc4
fix(deps): update dependency com.google.truth:truth to v1.4.1 2024-02-17 11:30:51 +00:00
renovate[bot] 51e75f15cd
chore(deps): update gradle/gradle-build-action action to v3.1.0 2024-02-14 02:29:11 +00:00
renovate[bot] ababb56266
chore(deps): update gradle/gradle-build-action action to v3 2024-02-06 05:40:14 +00:00
renovate[bot] e1b5f2cedb
fix(deps): update junit5 monorepo to v5.10.2 2024-02-05 02:13:24 +00:00
renovate[bot] 33dd3657ce
fix(deps): update dependency com.google.truth:truth to v1.4.0 2024-02-04 02:59:55 +00:00
renovate[bot] e8d8a55be9
chore(deps): update dependency gradle to v8.6 2024-02-03 02:03:36 +00:00
renovate[bot] 37c182fc6c
fix(deps): update dependency com.github.ajalt.mordant:mordant to v2.3.0 2024-02-02 05:18:54 +00:00
renovate[bot] 170f307b02
chore(deps): update plugin spotless to v6.25.0 2024-02-01 05:45:40 +00:00
renovate[bot] 575f6ce328
chore(deps): update plugin kotlinx-binarycompatibilityvalidator to v0.14.0 2024-01-31 02:45:33 +00:00
renovate[bot] 907755866d
chore(deps): update gradle/gradle-build-action action to v2.12.0 2024-01-29 23:43:54 +00:00
renovate[bot] 7f25eaecdc
fix(deps): update dependency com.android.tools.build:gradle to v8.2.2 2024-01-25 05:33:05 +00:00
renovate[bot] 34e45744e8
chore(deps): update plugin android-library to v8.2.2 2024-01-24 05:25:20 +00:00
renovate[bot] fd2a594ba9
fix(deps): update dependency com.google.truth:truth to v1.3.0 2024-01-20 08:47:54 +00:00
renovate[bot] 19c9345489
chore(deps): update actions/cache action to v4 2024-01-19 02:39:31 +00:00
renovate[bot] 2ad953292d
chore(deps): update plugin spotless to v6.24.0 2024-01-15 20:51:46 +00:00
renovate[bot] 309078083d
chore(deps): update plugin org.gradle.toolchains.foojay-resolver-convention to v0.8.0 2024-01-14 02:57:00 +00:00
renovate[bot] 09324c4290
chore(deps): update plugin buildconfig to v5.3.5 2024-01-13 17:39:32 +00:00
renovate[bot] a988b9154d
chore(deps): update actions/cache action to v3.3.3 2024-01-12 14:57:49 +00:00
renovate[bot] 8dcca4abef
chore(deps): update plugin buildconfig to v5.3.3 2024-01-08 08:13:34 +00:00
renovate[bot] f22cff890a
chore(deps): update plugin mavenpublish to v0.27.0 2024-01-07 14:21:53 +00:00
renovate[bot] 43ac9253f8
chore(deps): update plugin buildconfig to v5.3.2 2024-01-06 17:54:53 +00:00
renovate[bot] c4be78d082
fix(deps): update dependency com.android.tools.build:gradle to v8.2.1 2024-01-05 08:15:12 +00:00
renovate[bot] d759c6addb
chore(deps): update plugin android-library to v8.2.1 2024-01-04 08:33:18 +00:00
renovate[bot] 6d83fb151d
chore(deps): update plugin buildconfig to v5.2.0 2023-12-29 11:20:39 +00:00
renovate[bot] a1bb2a60bb
chore(deps): update plugin buildconfig to v5 2023-12-24 02:28:35 +00:00
renovate[bot] 88f7b103bc
fix(deps): update dependency com.google.truth:truth to v1.2.0 2023-12-22 02:31:04 +00:00
renovate[bot] 29bf7c83c9
chore(deps): update gradle/gradle-build-action action to v2.11.1 2023-12-21 08:51:46 +00:00
renovate[bot] 8c323b5546
chore(deps): update plugin mavenpublish to v0.26.0 2023-12-20 02:45:39 +00:00
renovate[bot] 0b530fdb31
chore(deps): update gradle/gradle-build-action action to v2.11.0 2023-12-13 02:46:05 +00:00
renovate[bot] 208435b4cc
fix(deps): update dependency com.android.tools.build:gradle to v8.2.0 2023-12-05 17:50:50 +00:00
renovate[bot] 02cec35a69
chore(deps): update plugin spotless to v6.23.3 2023-12-04 23:52:06 +00:00
renovate[bot] dd43e7a15e
chore(deps): update actions/setup-java action to v4 2023-12-03 02:42:14 +00:00
renovate[bot] c0ce021bd0
chore(deps): update plugin spotless to v6.23.2 2023-12-02 05:36:44 +00:00
renovate[bot] 9f2461f4de
chore(deps): update plugin android-library to v8.2.0 2023-12-01 04:51:32 +00:00
renovate[bot] 33a54ed1e0
chore(deps): update dependency gradle to v8.5 2023-11-30 08:51:26 +00:00
renovate[bot] f14d0164de
chore(deps): update gradle/gradle-build-action action to v2.10.0 2023-11-27 11:50:58 +00:00
renovate[bot] faec7eb697
chore(deps): update plugin buildconfig to v4.2.0 2023-11-21 20:33:28 +00:00
renovate[bot] e9bbbd06e7
chore(deps): update plugin android-library to v8.1.4 2023-11-17 08:27:03 +00:00
renovate[bot] 399f9bf019
chore(deps): update plugin android-library to v8.1.3 2023-11-08 08:45:24 +00:00
renovate[bot] a149baf71a
fix(deps): update junit5 monorepo to v5.10.1 2023-11-06 05:30:55 +00:00
renovate[bot] 5912780717
fix(deps): update dependency dev.zacsweers.kctfork:core to v0.4.0 2023-11-01 05:27:03 +00:00
renovate[bot] 8a007da8fe
chore(deps): update actions/checkout action to v4.1.1 2023-10-18 05:58:58 +00:00
renovate[bot] 1b82638170
chore(deps): update plugin dokka to v1.9.10 2023-10-17 05:05:27 +00:00
renovate[bot] 4a3d164d57
chore(deps): update dependency gradle to v8.4 2023-10-05 08:54:37 +00:00
renovate[bot] e84bce1e4a
fix(deps): update dependency com.github.ajalt.mordant:mordant to v2.2.0 2023-10-03 08:26:07 +00:00
renovate[bot] 8048f7f731
chore(deps): update gradle/gradle-build-action action to v2.9.0 2023-10-01 05:09:21 +00:00
renovate[bot] 26efc9f4bc
chore(deps): update plugin spotless to v6.22.0 2023-09-30 02:49:13 +00:00
renovate[bot] 6ff81fe7c0
chore(deps): update plugin android-library to v8.1.2 2023-09-29 20:39:44 +00:00
renovate[bot] 47058bb4a4
chore(deps): update gradle/gradle-build-action action to v2.8.1 2023-09-26 02:28:00 +00:00
renovate[bot] 0f7b00dae5
chore(deps): update actions/checkout action to v4.1.0 2023-09-23 02:35:47 +00:00
renovate[bot] 3fb90ff996
chore(deps): update actions/setup-java action to v3.13.0 2023-09-21 08:56:04 +00:00
Harsh Shandilya ebb597db59
fix(sample-jvm): setup shadow plugin 2023-09-14 23:28:37 +05:30
Harsh Shandilya 7a28726a2a
chore: suppress unused parameter warnings 2023-09-14 23:28:37 +05:30
Harsh Shandilya a24d5102bf
fix(sample-kmp): demonstrate throwing functions 2023-09-14 23:28:37 +05:30
Harsh Shandilya 9013544898
fix(sample-kmp): make LogPrinter work with parameter-less methods 2023-09-14 23:28:37 +05:30
Harsh Shandilya e19979d781 refactor(sample-kmp): extract log wrangling to its own class 2023-09-12 01:45:09 +05:30
Harsh Shandilya 174f672291
chore(README): document `loggerFunction` parameter 2023-09-10 14:22:30 +05:30
Harsh Shandilya eb583b983c
fix(compiler-plugin): add workaround for nested logger resolution 2023-09-10 14:14:23 +05:30
Harsh Shandilya 2913b1e92d
fix(compiler-plugin): relax `debugAnnotation` requirements 2023-09-10 13:38:33 +05:30
renovate[bot] 72ede4b5f6
chore(deps): update actions/cache action to v3.3.2 2023-09-09 05:57:05 +00:00
renovate[bot] 8f42f73da7
chore(deps): update actions/checkout action to v4 2023-09-04 17:56:45 +00:00
Harsh Shandilya e8648924b2
feat(compiler-plugin): add a failing test for nested logger functions 2023-09-03 19:59:52 +05:30
Harsh Shandilya 6b00666b7f
refactor(sample-kmp): apply compiler plugin manually 2023-09-03 19:59:52 +05:30
Harsh Shandilya 621cb5d62a
refactor(sample-jvm): apply compiler plugin manually 2023-09-03 19:31:23 +05:30
Harsh Shandilya b65e3432f4
chore: refresh README 2023-09-02 13:50:46 +05:30
renovate[bot] 0e9d320ef0
chore(deps): update plugin dokka to v1.9.0 2023-08-31 19:53:27 +00:00
Harsh Shandilya 4465f3df1d
chore(release): start next development iteration 2023-09-01 01:02:39 +05:30
Harsh Shandilya bea7990783
chore: release v0.1.3 2023-09-01 01:02:06 +05:30
Harsh Shandilya 334dfe095b
fix(gradle-plugin): source `runtime` dependency from `ArtifactInfo` 2023-09-01 01:01:51 +05:30
Harsh Shandilya c47e92ad9b chore: prepare next development iteration 2023-08-31 23:53:49 +05:30
17 changed files with 295 additions and 97 deletions

View File

@ -20,22 +20,22 @@ jobs:
actions: read
steps:
- name: Checkout repository
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Set up JDK
uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 18
- name: Cache Kotlin/Native compiler
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ~/.konan
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties', 'gradle/libs.versions.toml') }}
- name: Setup Gradle caching
uses: gradle/gradle-build-action@ef76a971e2fa3f867b617efd72f2fbd72cf6f8bc # v2.8.0
uses: gradle/gradle-build-action@4c39dd82cd5e1ec7c6fa0173bb41b4b6bb3b86ff # v3.3.2
with:
gradle-home-cache-cleanup: true
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
@ -50,28 +50,28 @@ jobs:
if: "github.event_name == 'push' && github.event.ref == 'refs/heads/main'"
needs:
- "check"
runs-on: macos-13
runs-on: macos-14
permissions:
actions: read
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Set up JDK
uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 18
- name: Cache Kotlin/Native compiler
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ~/.konan
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties', 'gradle/libs.versions.toml') }}
- name: Setup Gradle caching
uses: gradle/gradle-build-action@ef76a971e2fa3f867b617efd72f2fbd72cf6f8bc # v2.8.0
uses: gradle/gradle-build-action@4c39dd82cd5e1ec7c6fa0173bb41b4b6bb3b86ff # v3.3.2
with:
gradle-home-cache-cleanup: true
cache-read-only: ${{ github.ref != 'refs/heads/main' }}

View File

@ -20,26 +20,26 @@ jobs:
description: ${{ github.repository }}/${{ github.workflow }}#${{ github.run_number }}
publish:
runs-on: macos-13
runs-on: macos-14
needs: create_staging_repository
steps:
- name: Checkout repository
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Set up JDK
uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 18
- name: Cache Kotlin/Native compiler
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ~/.konan
key: ${{ runner.os }}-gradle-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties', 'gradle/libs.versions.toml') }}
- name: Publish
uses: gradle/gradle-build-action@ef76a971e2fa3f867b617efd72f2fbd72cf6f8bc # v2.8.0
uses: gradle/gradle-build-action@4c39dd82cd5e1ec7c6fa0173bb41b4b6bb3b86ff # v3.3.2
with:
arguments: publish :gradle-plugin:publish
env:

View File

@ -1,6 +1,39 @@
# TraceLog
# TraceLog ![Maven Central](https://img.shields.io/maven-central/v/dev.msfjarvis.tracelog/dev.msfjarvis.tracelog.gradle.plugin?style=flat-square&label=Latest%20version)
PoC Kotlin compiler plugin to emit [OpenTelemetry](https://opentelemetry.io/)-compatible logging metadata from Kotlin projects.
Kotlin compiler plugin to automate `println` debugging, because debuggers are for people smarter than me.
## Installation
Apply the Gradle plugin to your Kotlin project
```kotlin
plugins {
id("dev.msfjarvis.tracelog") version "0.1.3"
}
```
Optionally configure the annotation class and logger method (defaults shown below)
```kotlin
traceLog {
loggerFunction.set("kotlin.io.println")
annotationClass.set("dev/msfjarvis/tracelog/runtime/annotations/DebugLog")
}
```
The `loggerFunction` parameter must be a fully qualified to a static method with a single parameter of the type `Any?`.
```kotlin
fun recordMessage() {} // Bad, no parameter
fun recordMessage(p0: String, p1: Int) {} // Bad, multiple parameters and incorrect types
fun recordMessage(p0: Any?) {} // Good, single parameter with correct type
```
> [!NOTE]
> Due to a limitation in how TraceLog resolves the logger function, you might need to add `@JvmStatic` on the method
> for TraceLog to be able to find it. This will be fixed in a future release.
## Usage
Currently, this prints out a basic textual representation of the method's inputs and execution time. That is,
given this code:
@ -10,6 +43,10 @@ given this code:
fun debuggableFunction(p0: String): String {
return "Debugging is cool!"
}
fun main() {
debuggableFunction("First parameter")
}
```
The compiler plugin will generate code that writes the following messages
@ -18,3 +55,9 @@ The compiler plugin will generate code that writes the following messages
⇢ debuggableFunction(p0=First parameter)
⇠ debuggableFunction [214.209us] = Debugging is cool!
```
## Compatibility
| Kotlin Version | TraceLog Version |
|----------------|------------------|
| 1.9.0 | 0.1.x |

View File

@ -28,7 +28,7 @@ public class TracingCommandLineProcessor : CommandLineProcessor {
optionName = "debugAnnotation",
valueDescription = ArtifactInfo.DEFAULT_TRACELOG_ANNOTATION,
description = ANNOTATION_NAME.toString(),
required = true,
required = false,
allowMultipleOccurrences = false,
)
val OPTION_LOGGER_FUNCTION =

View File

@ -1,6 +1,7 @@
package dev.msfjarvis.tracelog.compiler.plugin
import com.google.auto.service.AutoService
import dev.msfjarvis.tracelog.ArtifactInfo
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
@ -18,7 +19,7 @@ public class TracingCompilerPluginRegistrar : CompilerPluginRegistrar() {
val messageCollector =
configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
val loggerFunction = configuration[LOGGER_FUNCTION] ?: "kotlin.io.println"
val annotationName = requireNotNull(configuration[ANNOTATION_NAME])
val annotationName = configuration[ANNOTATION_NAME] ?: ArtifactInfo.DEFAULT_TRACELOG_ANNOTATION
IrGenerationExtension.registerExtension(
TracingIrGenerationExtension(messageCollector, loggerFunction, annotationName)

View File

@ -8,7 +8,6 @@ import com.tschuchort.compiletesting.SourceFile.Companion.kotlin
import org.jetbrains.kotlin.compiler.plugin.CliOption
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
@OptIn(ExperimentalCompilerApi::class)
@ -88,7 +87,7 @@ class DebugLogTransformerTest {
messageOutputStream = System.out
}
.compile()
assertEquals(ExitCode.OK, result.exitCode)
assertThat(result.exitCode).isEqualTo(ExitCode.OK)
val kClazz = result.classLoader.loadClass("SourceFileKt")
val transformableWithReturnValue =
@ -107,6 +106,116 @@ class DebugLogTransformerTest {
)
}
@Test
fun `nested logger function`() {
val annotationSrcFile =
kotlin(
"DebugLog.kt",
"""
package dev.msfjarvis.annotation
annotation class DebugLog
"""
.trimIndent()
)
val srcFile =
kotlin(
"SourceFile.kt",
"""
import dev.msfjarvis.annotation.DebugLog
@DebugLog
fun transformable() {
println("In a transformable function!")
}
@DebugLog
fun transformableWithReturnValue(): String {
println("In a transformable function!")
return "Return value!"
}
fun nonTransformable() {
println("Not in a transformable function!")
}
class TracingTest {
@DebugLog
fun transformableInClass() {
println("In a transformable function!")
}
fun nonTransformable() {
println("Not in a transformable function!")
}
}
"""
.trimIndent()
)
val loggerFile =
kotlin(
"Logger.kt",
"""
package com.example
object Logger {
val messages = mutableListOf<String>()
@JvmStatic
fun recordMessage(message: Any?) {
messages += message.toString()
}
}
"""
.trimIndent()
)
val result =
KotlinCompilation()
.apply {
val processor = TracingCommandLineProcessor()
pluginOptions = buildList {
add(
processor.option(
TracingCommandLineProcessor.OPTION_LOGGER_FUNCTION,
"com.example.Logger.recordMessage"
)
)
add(
processor.option(
TracingCommandLineProcessor.OPTION_ANNOTATION_NAME,
"dev/msfjarvis/annotation/DebugLog"
)
)
}
sources = listOf(annotationSrcFile, srcFile, loggerFile)
compilerPluginRegistrars = listOf(TracingCompilerPluginRegistrar())
commandLineProcessors = listOf(processor)
noOptimize = true
inheritClassPath = true
messageOutputStream = System.out
}
.compile()
assertThat(result.exitCode).isEqualTo(ExitCode.OK)
val kClazz = result.classLoader.loadClass("SourceFileKt")
val transformableWithReturnValue =
kClazz.declaredMethods.first { it.name == "transformableWithReturnValue" }
val retVal = transformableWithReturnValue.invoke(null)
assertThat(retVal).isInstanceOf(String::class.java)
assertThat(retVal).isEqualTo("Return value!")
val loggerClazz = result.classLoader.loadClass("com.example.Logger")
val msgField = loggerClazz.declaredFields.first { it.name == "messages" }
msgField.isAccessible = true
val messages = msgField.get(null) as? List<*>
assertThat(messages).isNotNull()
assertThat(messages).contains("⇢ transformableWithReturnValue()")
assertThat((messages?.last() as? String)?.replace("\\[.*]".toRegex(), "[]"))
.isEqualTo(
"⇠ transformableWithReturnValue [] = Return value!",
)
}
private fun CommandLineProcessor.option(key: CliOption, value: Any?): PluginOption {
return PluginOption(pluginId, key.optionName, value.toString())
}

View File

@ -1,7 +1,7 @@
@file:Suppress("UnstableApiUsage")
pluginManagement {
plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0" }
plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" }
repositories {
includeBuild("../build-logic")
mavenCentral()

View File

@ -32,7 +32,7 @@ public class TraceLogGradlePlugin : KotlinCompilerPluginSupportPlugin {
if (useLocal) {
it.project(":runtime")
} else {
"dev.msfjarvis.tracelog:runtime:1.0.0-SNAPSHOT"
"${ArtifactInfo.GROUP}:${ArtifactInfo.RUNTIME_ARTIFACT}:${ArtifactInfo.VERSION}"
}
else -> null
}

View File

@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx2048m
kotlin.code.style=official
# Library Information
GROUP=dev.msfjarvis.tracelog
VERSION_NAME=0.1.2
VERSION_NAME=0.2.0-SNAPSHOT
# Maven central
POM_INCEPTION_YEAR=2023
RELEASE_SIGNING_ENABLED=true

View File

@ -1,30 +1,31 @@
[versions]
kotlin = "1.9.0"
junit = "5.10.0"
junit = "5.10.2"
[plugins]
android-library = { id = "com.android.library", version = "8.1.1" }
buildconfig = "com.github.gmazzo.buildconfig:4.1.2"
dokka = { id = "org.jetbrains.dokka", version = "1.8.20" }
android-library = { id = "com.android.library", version = "8.4.1" }
buildconfig = "com.github.gmazzo.buildconfig:5.3.5"
dokka = { id = "org.jetbrains.dokka", version = "1.9.20" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlinx-binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.13.2" }
kotlinx-binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.14.0" }
ksp = "com.google.devtools.ksp:1.9.0-1.0.13"
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.25.3" }
spotless = "com.diffplug.spotless:6.21.0"
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.27.0" }
shadow = "com.github.johnrengelman.shadow:8.1.1"
spotless = "com.diffplug.spotless:6.25.0"
[libraries]
android-gradle-plugin = "com.android.tools.build:gradle:8.1.1"
android-gradle-plugin = "com.android.tools.build:gradle:8.4.1"
auto-annotations = "com.google.auto.service:auto-service-annotations:1.1.1"
auto-ksp = "dev.zacsweers.autoservice:auto-service-ksp:1.1.0"
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
junit-legacy = "junit:junit:4.13.2"
kct = "dev.zacsweers.kctfork:core:0.3.2"
kct = "dev.zacsweers.kctfork:core:0.4.1"
kotlin-compiler = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable", version.ref = "kotlin" }
kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-gradlePlugin-api = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin-api", version.ref = "kotlin" }
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
mordant = "com.github.ajalt.mordant:mordant:2.1.0"
truth = "com.google.truth:truth:1.1.5"
mordant = "com.github.ajalt.mordant:mordant:2.6.0"
truth = "com.google.truth:truth:1.4.2"

View File

@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=591855b517fc635b9e04de1d05d5e76ada3f89f5fc76f87978d1b245b4f69225
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionSha256Sum=a4b4158601f8636cdeeab09bd76afb640030bb5b144aafe261a5e8af027dc612
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME

View File

@ -1,16 +1,26 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
alias(libs.plugins.kotlin.jvm)
id("dev.msfjarvis.tracelog")
alias(libs.plugins.shadow)
application
}
kotlin.jvmToolchain(11)
traceLog { loggerFunction.set("dev.msfjarvis.tracelog.sample.recordMessage") }
tasks.withType<KotlinCompile>().configureEach {
compilerOptions.freeCompilerArgs.addAll(
"-P",
"plugin:dev.msfjarvis.tracelog:loggerFunction=dev.msfjarvis.tracelog.sample.recordMessage",
"-P",
"plugin:dev.msfjarvis.tracelog:debugAnnotation=dev/msfjarvis/tracelog/runtime/annotations/DebugLog",
)
}
application { mainClass.set("dev.msfjarvis.tracelog.sample.MainKt") }
dependencies {
kotlinCompilerPluginClasspath(projects.compilerPlugin)
implementation(projects.runtime)
implementation(libs.mordant)
}

View File

@ -66,6 +66,7 @@ public fun recordMessage(message: Any?) {
/** An example of an annotated method which will be transformed by the compiler plugin. */
@DebugLog
@Suppress("UNUSED_PARAMETER")
public fun debuggableFunction(p0: String, p1: String = "Bar"): String {
return "Debugging is cool!"
}

View File

@ -1,11 +1,17 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithHostTests
plugins {
alias(libs.plugins.kotlin.multiplatform)
id("dev.msfjarvis.tracelog")
}
plugins { alias(libs.plugins.kotlin.multiplatform) }
traceLog { loggerFunction.set("recordMessage") }
tasks.withType<KotlinCompile<KotlinCommonOptions>>().configureEach {
kotlinOptions.options.freeCompilerArgs.addAll(
"-P",
"plugin:dev.msfjarvis.tracelog:loggerFunction=recordMessage",
"-P",
"plugin:dev.msfjarvis.tracelog:debugAnnotation=dev/msfjarvis/tracelog/runtime/annotations/DebugLog",
)
}
fun KotlinNativeTargetWithHostTests.configureTarget() = binaries {
executable { entryPoint = "main" }
@ -17,6 +23,8 @@ kotlin {
macosX64 { configureTarget() }
dependencies {
kotlinCompilerPluginClasspath(projects.compilerPlugin)
kotlinNativeCompilerPluginClasspath(projects.compilerPlugin)
commonMainImplementation(projects.runtime)
commonMainImplementation(libs.mordant)
}

View File

@ -0,0 +1,62 @@
import com.github.ajalt.mordant.rendering.TextColors.*
import com.github.ajalt.mordant.terminal.Terminal
object LogPrinter {
private val messages = arrayListOf<String>()
private const val MATCH_ARROW = "arrow"
private const val MATCH_IDENTIFIER = "identifier"
private const val MATCH_PARAMS = "params"
private const val MATCH_TIME = "time"
private const val MATCH_RETURN = "retval"
private val ENTER_REGEX =
"(?<$MATCH_ARROW>⇢) (?<$MATCH_IDENTIFIER>[a-zA-Z].*)\\((?<$MATCH_PARAMS>.*)\\)".toRegex()
private val EXIT_REGEX =
"(?<$MATCH_ARROW>⇠) (?<$MATCH_IDENTIFIER>[a-zA-Z].*) \\[(?<$MATCH_TIME>.*)] = (?<$MATCH_RETURN>.*)"
.toRegex()
private fun MatchResult.getMatch(groupName: String): String {
return groups[groupName]!!.value
}
fun submitLog(message: String) {
messages += message
}
fun printLogs() {
val t = Terminal()
messages.forEach { msg ->
var matches = ENTER_REGEX.find(msg)
if (matches != null) {
val params =
matches.getMatch(MATCH_PARAMS).split(", ").joinToString(", ") {
val split = it.split("=")
if (split.size == 1) {
""
} else {
val (name, value) = (split[0] to split[1])
"${brightYellow(name)}=${brightBlue(value)}"
}
}
t.println(
"""
${red(matches.getMatch(MATCH_ARROW))} ${green(matches.getMatch(MATCH_IDENTIFIER))}($params)
"""
.trimIndent()
)
} else {
matches = EXIT_REGEX.matchEntire(msg)
if (matches != null) {
t.println(
"""
${red(matches.getMatch(MATCH_ARROW))} ${green(matches.getMatch(MATCH_IDENTIFIER))} [${blue(matches.getMatch(
MATCH_TIME))}] = ${brightWhite(matches.getMatch(MATCH_RETURN))}
"""
.trimIndent()
)
}
}
}
}
}

View File

@ -1,69 +1,27 @@
import com.github.ajalt.mordant.rendering.TextColors.*
import com.github.ajalt.mordant.terminal.Terminal
import dev.msfjarvis.tracelog.runtime.annotations.DebugLog
private val messages = arrayListOf<String>()
private const val MATCH_ARROW = "arrow"
private const val MATCH_IDENTIFIER = "identifier"
private const val MATCH_PARAMS = "params"
private const val MATCH_TIME = "time"
private const val MATCH_RETURN = "retval"
private val ENTER_REGEX =
"(?<$MATCH_ARROW>⇢) (?<$MATCH_IDENTIFIER>[a-zA-Z].*)\\((?<$MATCH_PARAMS>.*)\\)".toRegex()
private val EXIT_REGEX =
"(?<$MATCH_ARROW>⇠) (?<$MATCH_IDENTIFIER>[a-zA-Z].*) \\[(?<$MATCH_TIME>.*)] = (?<$MATCH_RETURN>.*)"
.toRegex()
private fun MatchResult.getMatch(groupName: String): String {
return groups[groupName]!!.value
}
fun main() {
debuggableFunction("First parameter")
val t = Terminal()
messages.forEach { msg ->
var matches = ENTER_REGEX.find(msg)
if (matches != null) {
val params =
matches
.getMatch(MATCH_PARAMS)
.split(", ")
.map {
val split = it.split("=")
(split[0] to split[1])
}
.joinToString(", ") { (name, value) -> "${brightYellow(name)}=${brightBlue(value)}" }
t.println(
"""
${red(matches.getMatch(MATCH_ARROW))} ${green(matches.getMatch(MATCH_IDENTIFIER))}($params)
"""
.trimIndent()
)
} else {
matches = EXIT_REGEX.matchEntire(msg)
if (matches != null) {
t.println(
"""
${red(matches.getMatch(MATCH_ARROW))} ${green(matches.getMatch(MATCH_IDENTIFIER))} [${blue(matches.getMatch(
MATCH_TIME))}] = ${brightWhite(matches.getMatch(MATCH_RETURN))}
"""
.trimIndent()
)
}
}
}
try {
throwingFunction()
} catch (_: Exception) {}
LogPrinter.printLogs()
}
/** Custom implementation of a logger function for use by the compiler plugin. */
@Suppress("Unused") // Used by the generated bytecode
fun recordMessage(message: Any?) {
messages += message.toString()
LogPrinter.submitLog(message.toString())
}
/** An example of an annotated method which will be transformed by the compiler plugin. */
@DebugLog
@Suppress("UNUSED_PARAMETER")
fun debuggableFunction(p0: String, p1: String = "Bar"): String {
return "Debugging is cool!"
}
@DebugLog
fun throwingFunction() {
throw Exception("This code is throwing!")
}

View File

@ -1,7 +1,7 @@
@file:Suppress("UnstableApiUsage")
pluginManagement {
plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0" }
plugins { id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" }
repositories {
includeBuild("build-logic")
includeBuild("gradle-plugin")
@ -41,6 +41,11 @@ pluginManagement {
"com.github.gmazzo.buildconfig",
"com.github.gmazzo.buildconfig.gradle.plugin"
)
includeModule("com.github.johnrengelman", "shadow")
includeModule(
"com.github.johnrengelman.shadow",
"com.github.johnrengelman.shadow.gradle.plugin"
)
includeModule("com.github.gmazzo.buildconfig", "plugin")
}
}