Skip to content

Commit

Permalink
Update kotlinpoet to 2.0.0 (#6)
Browse files Browse the repository at this point in the history
* Update kotlinpoet to 2.0.0

* No idea why this broke now
  • Loading branch information
benjamin-bader authored Nov 24, 2024
1 parent a7340e9 commit 6a88582
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 45 deletions.
1 change: 0 additions & 1 deletion .github/workflows/pre-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
with:
path: |
~/.konan/
.build-cache/
key: cache-gradle-${{ matrix.os }}-${{ matrix.jvm-version }}-${{ hashFiles('settings.gradle') }}-${{ hashFiles('**/build.gradle') }}
restore-keys: |
cache-gradle-${{ matrix.os }}-${{ matrix.jvm-version }}-${{ hashFiles('settings.gradle') }}
Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@ org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m

# Build cache is helpful
org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.configuration-cache.parallel=true

org.gradle.parallel=true

kotlin.mpp.enableCInteropCommonization=true
3 changes: 1 addition & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ atomicfu-common = { module = "org.jetbrains.kotlinx:atomicfu", version.ref = "at
clikt = "com.github.ajalt.clikt:clikt:3.1.0"
dokka = "org.jetbrains.dokka:dokka-gradle-plugin:1.9.0"
guava = "com.google.guava:guava:33.3.1-jre"
javaPoet = "com.squareup:javapoet:1.13.0"
kotlin-bom = { module = "org.jetbrains.kotlin:kotlin-bom", version.ref = "kotlin" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" }
kotlin-stdlibCommon = { module = "org.jetbrains.kotlin:kotlin-stdlib-common", version.ref = "kotlin" }
kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
kotlinx-coroutinesTest = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
kotlinPoet = "com.squareup:kotlinpoet:1.12.0"
kotlinPoet = "com.squareup:kotlinpoet:2.0.0"
ktor-network = { module = "io.ktor:ktor-network", version.ref = "ktor" }
ktor-networkTls = { module = "io.ktor:ktor-network-tls", version.ref = "ktor" }
mavenPublishPlugin = "com.vanniktech:gradle-maven-publish-plugin:0.25.3"
Expand Down
27 changes: 7 additions & 20 deletions thrifty-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,22 @@ gradlePlugin {
}
}

def versionTask = tasks.register("generateVersionProps") { t ->
def versionTask = tasks.register("generateVersionProps", WriteProperties) {
def generatedResourcesDir = project.layout.buildDirectory.dir(["generated", "sources", "thrifty", "src", "main", "resources"].join(File.separator))
def outputFile = generatedResourcesDir.map {it -> it.file("thrifty-version.properties") }
destinationFile = generatedResourcesDir.map {dir -> dir.file("thrifty-version.properties") }

t.inputs.property("thrifty-version", VERSION_NAME)
t.inputs.property("kotlin-version", libs.versions.kotlin.get())
t.outputs.dir(generatedResourcesDir).withPropertyName("outputDir")
property("THRIFTY_VERSION", VERSION_NAME)
property("KOTLIN_VERSION", libs.versions.kotlin.get())
}

doFirst {
outputFile.get().getAsFile().with {
it.delete()
it << "THRIFTY_VERSION=${VERSION_NAME}\n"
it << "KOTLIN_VERSION=${libs.versions.kotlin.get()}\n"
}
}
processResources {
from versionTask
}

clean {
delete versionTask
}

sourceSets {
main {
resources {
srcDirs += versionTask
}
}
}

dependencies {
compileOnly gradleApi()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ class KotlinCodeGenerator(
}

return FunSpec.builder("toString")
.returns(String::class)
.addModifiers(KModifier.OVERRIDE)
.addCode(block)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,9 @@ class KotlinCodeGeneratorTest {

val parcelize = ClassName("kotlinx.android.parcel", "Parcelize")

struct.annotationSpecs.any { it.typeName == parcelize } shouldBe true
anEnum.annotationSpecs.any { it.typeName == parcelize } shouldBe true
svc.annotationSpecs.any { it.typeName == parcelize } shouldBe false
struct.annotations.any { it.typeName == parcelize } shouldBe true
anEnum.annotations.any { it.typeName == parcelize } shouldBe true
svc.annotations.any { it.typeName == parcelize } shouldBe false
}

@Test
Expand Down Expand Up @@ -415,12 +415,12 @@ class KotlinCodeGeneratorTest {
|public class SvcClient(
| protocol: Protocol,
| dispatcher: CoroutineDispatcher = Dispatchers.IO,
|) : AsyncClientBase(protocol, dispatcher), Svc {
| public override suspend fun doSomething(foo: Int): Int {
|) : AsyncClientBase(protocol, dispatcher),
| Svc {
| override suspend fun doSomething(foo: Int): Int {
| val call = DoSomethingCall(foo)
| return executeMethodCall(call)
| }
|
""".trimMargin())
}

Expand Down Expand Up @@ -539,25 +539,25 @@ class KotlinCodeGeneratorTest {
| public data class Foo(
| public val `value`: Int,
| ) : Union() {
| public override fun toString(): String = "Union(Foo=${'$'}value)"
| override fun toString(): String = "Union(Foo=${'$'}value)"
| }
|
| public data class Bar(
| public val `value`: Long,
| ) : Union() {
| public override fun toString(): String = "Union(Bar=${'$'}value)"
| override fun toString(): String = "Union(Bar=${'$'}value)"
| }
|
| public data class Baz(
| public val `value`: String,
| ) : Union() {
| public override fun toString(): String = "Union(Baz=${'$'}value)"
| override fun toString(): String = "Union(Baz=${'$'}value)"
| }
|
| public data class NotFoo(
| public val `value`: Int,
| ) : Union() {
| public override fun toString(): String = "Union(NotFoo=${'$'}value)"
| override fun toString(): String = "Union(NotFoo=${'$'}value)"
| }
|
""".trimMargin())
Expand Down Expand Up @@ -605,7 +605,7 @@ class KotlinCodeGeneratorTest {
file.shouldCompile()

file.single().toString() should contain("""
| public override suspend fun read(protocol: Protocol): Union {
| override suspend fun read(protocol: Protocol): Union {
| protocol.readStructBegin()
| var result : Union? = null
| while (true) {
Expand Down Expand Up @@ -714,14 +714,14 @@ class KotlinCodeGeneratorTest {

file.single().toString() should contain("""
|public sealed class UnionStruct : Struct {
| public override suspend fun write(protocol: Protocol): Unit {
| override suspend fun write(protocol: Protocol) {
| ADAPTER.write(protocol, this)
| }
|
| public data class Struct(
| public val `value`: Bonk,
| ) : UnionStruct() {
| public override fun toString(): String = "UnionStruct(Struct=${'$'}value)"
| override fun toString(): String = "UnionStruct(Struct=${'$'}value)"
| }
""".trimMargin())
}
Expand Down Expand Up @@ -764,9 +764,7 @@ class KotlinCodeGeneratorTest {
1 -> {
if (fieldMeta.typeId == TType.I32) {
val field_ = protocol.readI32().let {
TestEnum.findByValue(it) ?: throw
ThriftException(ThriftException.Kind.PROTOCOL_ERROR,
"Unexpected value for enum type TestEnum: ${'$'}it")
TestEnum.findByValue(it) ?: throw ThriftException(ThriftException.Kind.PROTOCOL_ERROR, "Unexpected value for enum type TestEnum: ${'$'}it")
}
_local_field = field_
} else {
Expand Down Expand Up @@ -808,9 +806,7 @@ class KotlinCodeGeneratorTest {
2 -> {
if (fieldMeta.typeId == TType.I32) {
val field2 = protocol.readI32().let {
TestEnum.findByValue(it) ?: throw
ThriftException(ThriftException.Kind.PROTOCOL_ERROR,
"Unexpected value for enum type TestEnum: ${'$'}it")
TestEnum.findByValue(it) ?: throw ThriftException(ThriftException.Kind.PROTOCOL_ERROR, "Unexpected value for enum type TestEnum: ${'$'}it")
}
_local_field2 = field2
} else {
Expand Down Expand Up @@ -854,9 +850,7 @@ class KotlinCodeGeneratorTest {
2 -> {
if (fieldMeta.typeId == TType.I32) {
val field2 = protocol.readI32().let {
TestEnum.findByValue(it) ?: throw
ThriftException(ThriftException.Kind.PROTOCOL_ERROR,
"Unexpected value for enum type TestEnum: ${'$'}it")
TestEnum.findByValue(it) ?: throw ThriftException(ThriftException.Kind.PROTOCOL_ERROR, "Unexpected value for enum type TestEnum: ${'$'}it")
}
_local_field2 = field2
} else {
Expand Down

0 comments on commit 6a88582

Please sign in to comment.