Skip to content

Commit 4d7911e

Browse files
authored
protoc-plugin: Refactoring of intermediate model (#418)
1 parent 56372ad commit 4d7911e

File tree

61 files changed

+1065
-2132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1065
-2132
lines changed

gradle-plugin/src/main/kotlin/kotlinx/rpc/buf/BufExtensions.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
package kotlinx.rpc.buf
66

77
import kotlinx.rpc.buf.tasks.BufExecTask
8+
import kotlinx.rpc.proto.ProtocPlugin
89
import org.gradle.api.Action
910
import org.gradle.api.Project
10-
import org.gradle.api.provider.Property
11-
import org.gradle.kotlin.dsl.property
12-
import java.io.File
13-
import javax.inject.Inject
14-
import kotlin.time.Duration
15-
import kotlinx.rpc.proto.ProtocPlugin
1611
import org.gradle.api.model.ObjectFactory
1712
import org.gradle.api.provider.ListProperty
13+
import org.gradle.api.provider.Property
1814
import org.gradle.api.provider.Provider
1915
import org.gradle.kotlin.dsl.listProperty
16+
import org.gradle.kotlin.dsl.property
17+
import java.io.File
18+
import javax.inject.Inject
2019
import kotlin.reflect.KClass
20+
import kotlin.time.Duration
2121

2222
/**
2323
* Options for the Buf tasks.
@@ -100,14 +100,14 @@ public open class BufExtension @Inject constructor(objects: ObjectFactory) {
100100
* Allows registering custom Buf tasks that can operate on the generated workspace.
101101
*/
102102
public open class BufTasksExtension @Inject constructor(internal val project: Project) {
103-
// TODO change to commonMain/commonTest in docs when it's supported KRPC-180
103+
104104
/**
105105
* Registers a custom Buf task that operates on the generated workspace.
106106
*
107107
* Name conventions:
108108
* `lint` input for [name] will result in tasks
109109
* named 'bufLintMain' and 'bufLintTest' for Kotlin/JVM projects
110-
* and 'bufLintJvmMain' and 'bufLintJvmTest' for Kotlin/Multiplatform projects.
110+
* and 'bufLintCommonMain' and 'bufLintCommonTest' for Kotlin/Multiplatform projects.
111111
*
112112
* Note the by default 'test' task doesn't depend on 'main' task.
113113
*/
@@ -127,14 +127,14 @@ public open class BufTasksExtension @Inject constructor(internal val project: Pr
127127
return provider
128128
}
129129

130-
// TODO change to commonMain/commonTest in docs when it's supported KRPC-180
130+
131131
/**
132132
* Registers a custom Buf task that operates on the generated workspace.
133133
*
134134
* Name conventions:
135135
* `lint` input for [name] will result in tasks
136136
* named 'bufLintMain' and 'bufLintTest' for Kotlin/JVM projects
137-
* and 'bufLintJvmMain' and 'bufLintJvmTest' for Kotlin/Multiplatform projects.
137+
* and 'bufLintCommonMain' and 'bufLintCommonTest' for Kotlin/Multiplatform projects.
138138
*
139139
* Note the by default 'test' task doesn't depend on 'main' task.
140140
*/

gradle-plugin/src/main/kotlin/kotlinx/rpc/grpc/DefaultGrpcExtension.kt

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,14 @@
44

55
package kotlinx.rpc.grpc
66

7-
import kotlinx.rpc.GRPC_KOTLIN_VERSION
8-
import kotlinx.rpc.GRPC_VERSION
9-
import kotlinx.rpc.PROTOBUF_VERSION
107
import kotlinx.rpc.buf.BufExtension
118
import kotlinx.rpc.buf.configureBufExecutable
129
import kotlinx.rpc.buf.tasks.registerBufExecTask
1310
import kotlinx.rpc.buf.tasks.registerBufGenerateTask
1411
import kotlinx.rpc.buf.tasks.registerGenerateBufGenYamlTask
1512
import kotlinx.rpc.buf.tasks.registerGenerateBufYamlTask
1613
import kotlinx.rpc.proto.*
17-
import kotlinx.rpc.proto.ProtocPlugin.Companion.GRPC_JAVA
18-
import kotlinx.rpc.proto.ProtocPlugin.Companion.GRPC_KOTLIN
1914
import kotlinx.rpc.proto.ProtocPlugin.Companion.KOTLIN_MULTIPLATFORM
20-
import kotlinx.rpc.proto.ProtocPlugin.Companion.PROTOBUF_JAVA
2115
import kotlinx.rpc.util.ensureDirectoryExists
2216
import org.gradle.api.Action
2317
import org.gradle.api.GradleException
@@ -61,9 +55,6 @@ internal open class DefaultGrpcExtension @Inject constructor(
6155
createDefaultProtocPlugins()
6256

6357
project.protoSourceSets.forEach { protoSourceSet ->
64-
protoSourceSet.protocPlugin(protocPlugins.protobufJava)
65-
protoSourceSet.protocPlugin(protocPlugins.grpcJava)
66-
protoSourceSet.protocPlugin(protocPlugins.grpcKotlin)
6758
protoSourceSet.protocPlugin(protocPlugins.kotlinMultiplatform)
6859
}
6960

@@ -294,30 +285,6 @@ internal open class DefaultGrpcExtension @Inject constructor(
294285
// ignore for bufGenerate task caching
295286
project.normalization.runtimeClasspath.ignore("**/protoc-gen-kotlin-multiplatform.log")
296287
project.normalization.runtimeClasspath.ignore("**/.keep")
297-
298-
protocPlugins.create(GRPC_JAVA) {
299-
isJava.set(true)
300-
301-
remote {
302-
locator.set("buf.build/grpc/java:v$GRPC_VERSION")
303-
}
304-
}
305-
306-
protocPlugins.create(GRPC_KOTLIN) {
307-
remote {
308-
locator.set("buf.build/grpc/kotlin:v$GRPC_KOTLIN_VERSION")
309-
}
310-
}
311-
312-
protocPlugins.create(PROTOBUF_JAVA) {
313-
isJava.set(true)
314-
315-
remote {
316-
// for some reason they omit the first digit in this version:
317-
// https://buf.build/protocolbuffers/java?version=v31.1
318-
locator.set("buf.build/protocolbuffers/java:v${PROTOBUF_VERSION.substringAfter(".")}")
319-
}
320-
}
321288
}
322289

323290
private fun DefaultProtoSourceSet.correspondingMainSourceSetOrNull(): DefaultProtoSourceSet? {

gradle-plugin/src/main/kotlin/kotlinx/rpc/proto/DefaultProtoSourceSet.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,11 @@ internal fun Project.createProtoExtensions() {
9696
}
9797

9898
project.withKotlinKmpExtension {
99-
findOrCreateAndConfigure("jvmMain", null)
100-
findOrCreateAndConfigure("jvmTest", null)
10199
findOrCreateAndConfigure("commonMain", null)
102100
findOrCreateAndConfigure("commonTest", null)
103101

104102
sourceSets.configureEach {
105-
if (name == "jvmMain" || name == "jvmTest" || name == "commonMain" || name == "commonTest") {
103+
if (name == "commonMain" || name == "commonTest") {
106104
findOrCreateAndConfigure(name, this)
107105
}
108106
}

gradle-plugin/src/main/kotlin/kotlinx/rpc/proto/ProtocPlugin.kt

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
package kotlinx.rpc.proto
66

7-
import kotlinx.rpc.proto.ProtocPlugin.Companion.GRPC_JAVA
8-
import kotlinx.rpc.proto.ProtocPlugin.Companion.GRPC_KOTLIN
97
import kotlinx.rpc.proto.ProtocPlugin.Companion.KOTLIN_MULTIPLATFORM
10-
import kotlinx.rpc.proto.ProtocPlugin.Companion.PROTOBUF_JAVA
118
import kotlinx.rpc.util.OS
129
import org.gradle.api.Action
1310
import org.gradle.api.NamedDomainObjectContainer
@@ -34,45 +31,6 @@ public fun NamedDomainObjectContainer<ProtocPlugin>.kotlinMultiplatform(action:
3431
kotlinMultiplatform.configure(action)
3532
}
3633

37-
/**
38-
* Access to the `protobuf-java` protoc plugin.
39-
*/
40-
public val NamedDomainObjectContainer<ProtocPlugin>.protobufJava: NamedDomainObjectProvider<ProtocPlugin>
41-
get() = named(PROTOBUF_JAVA)
42-
43-
/**
44-
* Configures the `protobuf-java` protoc plugin.
45-
*/
46-
public fun NamedDomainObjectContainer<ProtocPlugin>.protobufJava(action: Action<ProtocPlugin>) {
47-
protobufJava.configure(action)
48-
}
49-
50-
/**
51-
* Access to the `grpc-java` protoc plugin.
52-
*/
53-
public val NamedDomainObjectContainer<ProtocPlugin>.grpcJava: NamedDomainObjectProvider<ProtocPlugin>
54-
get() = named(GRPC_JAVA)
55-
56-
/**
57-
* Configures the grpc-java protoc plugin.
58-
*/
59-
public fun NamedDomainObjectContainer<ProtocPlugin>.grpcJava(action: Action<ProtocPlugin>) {
60-
grpcJava.configure(action)
61-
}
62-
63-
/**
64-
* Access to the `grpc-kotlin` protoc plugin.
65-
*/
66-
public val NamedDomainObjectContainer<ProtocPlugin>.grpcKotlin: NamedDomainObjectProvider<ProtocPlugin>
67-
get() = named(GRPC_KOTLIN)
68-
69-
/**
70-
* Configures the `grpc-kotlin` protoc plugin.
71-
*/
72-
public fun NamedDomainObjectContainer<ProtocPlugin>.grpcKotlin(action: Action<ProtocPlugin>) {
73-
grpcKotlin.configure(action)
74-
}
75-
7634
/**
7735
* Access to a specific protoc plugin.
7836
*/
@@ -193,27 +151,6 @@ public open class ProtocPlugin(
193151
* @see [kotlinMultiplatform]
194152
*/
195153
public const val KOTLIN_MULTIPLATFORM: String = "kotlin-multiplatform"
196-
197-
/**
198-
* The name of the `protobuf-java` protoc plugin.
199-
*
200-
* @see [protobufJava]
201-
*/
202-
public const val PROTOBUF_JAVA: String = "java"
203-
204-
/**
205-
* The name of the `grpc-java` protoc plugin.
206-
*
207-
* @see [grpcJava]
208-
*/
209-
public const val GRPC_JAVA: String = "grpc-java"
210-
211-
/**
212-
* The name of the `grpc-kotlin` protoc plugin.
213-
*
214-
* @see [grpcKotlin]
215-
*/
216-
public const val GRPC_KOTLIN: String = "grpc-kotlin"
217154
}
218155

219156
/**

gradle-plugin/src/test/kotlin/kotlinx/rpc/GrpcJvmProjectTest.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,6 @@ class GrpcJvmProjectTest : GrpcBaseTest() {
135135
version: v2
136136
clean: true
137137
plugins:
138-
- remote: buf.build/protocolbuffers/java:v${TEST_PROTOBUF_VERSION.substringAfter(".")}
139-
out: java
140-
- remote: buf.build/grpc/java:v$TEST_GRPC_VERSION
141-
out: grpc-java
142-
- remote: buf.build/grpc/kotlin:v$TEST_GRPC_KOTLIN_VERSION
143-
out: grpc-kotlin
144138
- local: [protoc-gen-kotlin-multiplatform]
145139
out: kotlin-multiplatform
146140
opt:
@@ -174,7 +168,8 @@ inputs:
174168
}
175169

176170
@Suppress("detekt.MaxLineLength")
177-
private val cliFlagsRegex = "- Buf Arguments: \\[.*?, generate, --output, .*?, --include-imports, --include-wkt, --error-format, json, --config, some\\.buf\\.yaml, --log-format, json, --timeout, 60s]".toRegex()
171+
private val cliFlagsRegex =
172+
"- Buf Arguments: \\[.*?, generate, --output, .*?, --include-imports, --include-wkt, --error-format, json, --config, some\\.buf\\.yaml, --log-format, json, --timeout, 60s]".toRegex()
178173

179174
@Test
180175
fun `Custom Buf CLI Flags`() = runGrpcTest {

gradle-plugin/src/test/kotlin/kotlinx/rpc/base/GrpcBaseTest.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,7 @@ import org.gradle.testkit.runner.TaskOutcome
99
import org.intellij.lang.annotations.Language
1010
import org.junit.jupiter.api.TestInstance
1111
import java.nio.file.Path
12-
import kotlin.io.path.ExperimentalPathApi
13-
import kotlin.io.path.absolutePathString
14-
import kotlin.io.path.deleteRecursively
15-
import kotlin.io.path.exists
16-
import kotlin.io.path.extension
17-
import kotlin.io.path.isRegularFile
18-
import kotlin.io.path.pathString
19-
import kotlin.io.path.readLines
20-
import kotlin.io.path.relativeTo
21-
import kotlin.io.path.walk
22-
import kotlin.lazy
12+
import kotlin.io.path.*
2313
import kotlin.test.assertEquals
2414
import kotlin.test.fail
2515

@@ -229,7 +219,7 @@ abstract class GrpcBaseTest : BaseTest() {
229219
}
230220

231221
companion object {
232-
private const val KMP_SOURCE_SET = "jvm"
222+
private const val KMP_SOURCE_SET = "common"
233223
private val KMP_SOURCE_SET_CAPITAL = KMP_SOURCE_SET.replaceFirstChar(Char::uppercaseChar)
234224
private const val KOTLIN_MULTIPLATFORM_DIR = "kotlin-multiplatform"
235225
const val RPC_INTERNAL = "_rpc_internal"

0 commit comments

Comments
 (0)