Skip to content

Commit 40352ec

Browse files
committed
Changed BufTasks into ProtoTasks
1 parent da15eb0 commit 40352ec

File tree

21 files changed

+559
-1038
lines changed

21 files changed

+559
-1038
lines changed

gradle-plugin/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ kotlin {
1919
explicitApi()
2020

2121
jvmToolchain(17)
22+
23+
compilerOptions.optIn.add("kotlinx.rpc.internal.InternalRpcApi")
2224
}
2325

2426
tasks.withType<KotlinCompile>().configureEach {

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

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44

55
package kotlinx.rpc.buf
66

7-
import kotlinx.rpc.buf.tasks.BufAllTasks
8-
import kotlinx.rpc.buf.tasks.BufAllTasksImpl
97
import kotlinx.rpc.buf.tasks.BufExecTask
10-
import kotlinx.rpc.buf.tasks.BufGenerateTask
11-
import kotlinx.rpc.buf.tasks.BufTasks
12-
import kotlinx.rpc.buf.tasks.BufTasksImpl
8+
import kotlinx.rpc.protoc.ProtoTasks
139
import kotlinx.rpc.protoc.ProtocPlugin
10+
import kotlinx.rpc.protoc.protoTasks
1411
import org.gradle.api.Action
1512
import org.gradle.api.Project
1613
import org.gradle.api.model.ObjectFactory
@@ -104,13 +101,6 @@ public open class BufExtension @Inject internal constructor(objects: ObjectFacto
104101
* Allows registering custom Buf tasks that can operate on the generated workspace.
105102
*/
106103
public open class BufTasksExtension @Inject internal constructor(internal val project: Project) {
107-
/**
108-
* Returns a collection of all `buf` tasks registered in the project.
109-
*/
110-
public fun all(): BufAllTasks {
111-
return BufAllTasksImpl(project, project.tasks.withType(BufExecTask::class.java))
112-
}
113-
114104
/**
115105
* Registers a custom Buf task that operates on the generated workspace.
116106
*
@@ -123,11 +113,11 @@ public open class BufTasksExtension @Inject internal constructor(internal val pr
123113
kClass: KClass<T>,
124114
name: String,
125115
configure: Action<T> = Action {},
126-
): BufTasks<T> {
116+
): ProtoTasks<T> {
127117
@Suppress("UNCHECKED_CAST")
128118
customTasks.add(Definition(name, kClass, configure))
129119

130-
return all().matchingType(kClass)
120+
return project.protoTasks.matchingType(kClass)
131121
}
132122

133123
/**
@@ -141,7 +131,7 @@ public open class BufTasksExtension @Inject internal constructor(internal val pr
141131
public inline fun <reified T : BufExecTask> registerWorkspaceTask(
142132
name: String,
143133
configure: Action<T> = Action {},
144-
): BufTasks<T> {
134+
): ProtoTasks<T> {
145135
return registerWorkspaceTask(T::class, name, configure)
146136
}
147137

@@ -161,13 +151,6 @@ public open class BufTasksExtension @Inject internal constructor(internal val pr
161151
* @see [BUF_GEN_YAML]
162152
*/
163153
public open class BufGenerateExtension @Inject internal constructor(internal val project: Project) {
164-
/**
165-
* Returns a collection of all `buf generate` tasks registered in the project.
166-
*/
167-
public fun allTasks(): BufTasks<BufGenerateTask> {
168-
return BufTasksImpl(project, project.tasks.withType(BufGenerateTask::class.java), BufGenerateTask::class)
169-
}
170-
171154
/**
172155
* `--include-imports` option.
173156
*

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

Lines changed: 6 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ package kotlinx.rpc.buf.tasks
77
import kotlinx.rpc.buf.BUF_EXECUTABLE_CONFIGURATION
88
import kotlinx.rpc.buf.BufExtension
99
import kotlinx.rpc.buf.execBuf
10-
import kotlinx.rpc.protoc.PROTO_GROUP
1110
import kotlinx.rpc.rpcExtension
12-
import org.gradle.api.DefaultTask
1311
import org.gradle.api.Project
1412
import org.gradle.api.provider.ListProperty
1513
import org.gradle.api.provider.Property
@@ -26,25 +24,20 @@ import kotlin.reflect.KClass
2624
import kotlinx.rpc.buf.BUF_GEN_YAML
2725
import kotlinx.rpc.buf.BUF_YAML
2826
import kotlinx.rpc.buf.BufTasksExtension
27+
import kotlinx.rpc.protoc.DefaultProtoTask
28+
import kotlinx.rpc.protoc.ProtoTask
2929
import org.gradle.api.logging.LogLevel
30-
import org.gradle.api.provider.SetProperty
3130
import org.gradle.api.tasks.Classpath
3231
import org.gradle.api.tasks.InputFiles
33-
import org.gradle.api.tasks.Internal
3432
import org.gradle.api.tasks.SkipWhenEmpty
3533
import javax.inject.Inject
3634

3735
/**
3836
* Abstract base class for `buf` tasks.
3937
*/
4038
public abstract class BufExecTask @Inject constructor(
41-
@Internal
42-
public val properties: Provider<Properties>,
43-
) : DefaultTask() {
44-
init {
45-
group = PROTO_GROUP
46-
}
47-
39+
properties: ProtoTask.Properties,
40+
) : DefaultProtoTask(properties) {
4841
// unsued, but required for Gradle to properly recognise inputs
4942
@get:InputFiles
5043
@get:SkipWhenEmpty
@@ -54,77 +47,12 @@ public abstract class BufExecTask @Inject constructor(
5447
@get:InputFiles
5548
internal abstract val importProtoFiles: ListProperty<File>
5649

57-
// list of buf task dependencies of the same type
58-
@get:Internal
59-
internal abstract val bufTaskDependencies: SetProperty<String>
60-
6150
@get:InputFile
6251
internal abstract val bufExecutable: Property<File>
6352

6453
@get:Input
6554
internal abstract val debug: Property<Boolean>
6655

67-
/**
68-
* Properties of the buf task.
69-
*
70-
* Can be used with [BufTasks] to filter tasks.
71-
*/
72-
public open class Properties internal constructor(
73-
/**
74-
* Whether the task is for a test source set.
75-
*/
76-
public val isTest: Boolean,
77-
/**
78-
* Name of the [kotlinx.rpc.protoc.ProtoSourceSet] this task is associated with.
79-
*/
80-
public val sourceSetName: String,
81-
)
82-
83-
/**
84-
* Properties of the buf task for android source sets.
85-
*
86-
* Can be used with [BufTasks] to filter tasks.
87-
*/
88-
public class AndroidProperties internal constructor(
89-
isTest: Boolean,
90-
sourceSetName: String,
91-
92-
/**
93-
* Name of the android flavors this task is associated with.
94-
*
95-
* Can be empty for 'com.android.kotlin.multiplatform.library' source sets.
96-
*
97-
* @see com.android.build.api.variant.Variant.productFlavors
98-
*/
99-
public val flavors: List<String>,
100-
101-
/**
102-
* Name of the android build type this task is associated with.
103-
*
104-
* @see com.android.build.api.variant.Variant.buildType
105-
*/
106-
public val buildType: String?,
107-
108-
/**
109-
* Name of the android variant this task is associated with.
110-
*
111-
* Can be `null` for 'com.android.kotlin.multiplatform.library' source sets.
112-
*
113-
* @see com.android.build.api.variant.Variant.name
114-
*/
115-
public val variant: String?,
116-
117-
/**
118-
* Whether the task is for instrumentation tests.
119-
*/
120-
public val isInstrumentedTest: Boolean,
121-
122-
/**
123-
* Whether the task is for unit tests.
124-
*/
125-
public val isUnitTest: Boolean,
126-
) : Properties(isTest, sourceSetName)
127-
12856
/**
12957
* The `buf` command to execute.
13058
*
@@ -185,7 +113,7 @@ public abstract class BufExecTask @Inject constructor(
185113
public inline fun <reified T : BufExecTask> Project.registerBufExecTask(
186114
name: String,
187115
workingDir: Provider<File>,
188-
properties: Provider<BufExecTask.Properties>,
116+
properties: ProtoTask.Properties,
189117
noinline configuration: T.() -> Unit,
190118
): TaskProvider<T> = registerBufExecTask(T::class, name, workingDir, properties, configuration)
191119

@@ -194,7 +122,7 @@ internal fun <T : BufExecTask> Project.registerBufExecTask(
194122
clazz: KClass<T>,
195123
name: String,
196124
workingDir: Provider<File>,
197-
properties: Provider<BufExecTask.Properties>,
125+
properties: ProtoTask.Properties,
198126
configuration: T.() -> Unit = {},
199127
): TaskProvider<T> = tasks.register(name, clazz, properties).apply {
200128
configure {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import org.gradle.api.tasks.TaskProvider
1717
import java.io.File
1818
import kotlinx.rpc.buf.BufGenerateExtension
1919
import kotlinx.rpc.protoc.DefaultProtoSourceSet
20-
import kotlinx.rpc.protoc.bufExecProperties
20+
import kotlinx.rpc.protoc.ProtoTask
21+
import kotlinx.rpc.protoc.protoTaskProperties
2122
import org.gradle.api.file.SourceDirectorySet
2223
import org.gradle.api.provider.Provider
2324
import org.gradle.api.tasks.InputFiles
@@ -31,7 +32,7 @@ import javax.inject.Inject
3132
* @see <a href="https://buf.build/docs/reference/cli/buf/generate/">buf generate</a>
3233
*/
3334
public abstract class BufGenerateTask @Inject internal constructor(
34-
properties: Provider<Properties>,
35+
properties: ProtoTask.Properties,
3536
) : BufExecTask(properties) {
3637
// used to properly calculate output directories
3738
@get:Input
@@ -141,13 +142,12 @@ internal fun Project.registerBufGenerateTask(
141142
workingDir: File,
142143
outputDirectory: File,
143144
includedPlugins: Provider<Set<ProtocPlugin>>,
145+
properties: ProtoTask.Properties,
144146
configure: BufGenerateTask.() -> Unit = {},
145147
): TaskProvider<BufGenerateTask> {
146148
val capitalName = protoSourceSet.name.replaceFirstChar { it.uppercase() }
147149
val bufGenerateTaskName = "${BufGenerateTask.NAME_PREFIX}$capitalName"
148150

149-
val properties = protoSourceSet.bufExecProperties()
150-
151151
return registerBufExecTask<BufGenerateTask>(bufGenerateTaskName, provider { workingDir }, properties) {
152152
group = PROTO_GROUP
153153
description = "Generates code from .proto files using 'buf generate'"

0 commit comments

Comments
 (0)