Skip to content

Commit 3c3c6f0

Browse files
KRPC-598: Use RegularFileProperty/DirectoryProperty for buf task outputs (#714)
Co-authored-by: Alexander Sysoev <Alexander.Sysoev@jetbrains.com>
1 parent af345e2 commit 3c3c6f0

4 files changed

Lines changed: 16 additions & 13 deletions

File tree

gradle-plugin/api/gradle-plugin.api

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,19 @@ public abstract class kotlinx/rpc/buf/tasks/BufGenerateTask : kotlinx/rpc/buf/ta
120120
public abstract fun getExecutableFiles ()Lorg/gradle/api/provider/ListProperty;
121121
public abstract fun getIncludeImports ()Lorg/gradle/api/provider/Property;
122122
public abstract fun getIncludeWkt ()Lorg/gradle/api/provider/Property;
123-
public abstract fun getOutputDirectory ()Lorg/gradle/api/provider/Property;
123+
public abstract fun getOutputDirectory ()Lorg/gradle/api/file/DirectoryProperty;
124124
public final fun getOutputSourceDirectories ()Lorg/gradle/api/provider/Provider;
125125
public abstract fun getPluginNames ()Lorg/gradle/api/provider/ListProperty;
126126
}
127127

128128
public abstract class kotlinx/rpc/buf/tasks/GenerateBufGenYaml : kotlinx/rpc/protoc/DefaultProtoTask {
129129
public static final field NAME_PREFIX Ljava/lang/String;
130-
public abstract fun getBufGenFile ()Lorg/gradle/api/provider/Property;
130+
public abstract fun getBufGenFile ()Lorg/gradle/api/file/RegularFileProperty;
131131
}
132132

133133
public abstract class kotlinx/rpc/buf/tasks/GenerateBufYaml : kotlinx/rpc/protoc/DefaultProtoTask {
134134
public static final field NAME_PREFIX Ljava/lang/String;
135-
public abstract fun getBufFile ()Lorg/gradle/api/provider/Property;
135+
public abstract fun getBufFile ()Lorg/gradle/api/file/RegularFileProperty;
136136
}
137137

138138
public final class kotlinx/rpc/protoc/ConstsKt {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package kotlinx.rpc.buf.tasks
77
import kotlinx.rpc.protoc.PROTO_GROUP
88
import kotlinx.rpc.protoc.ProtocPlugin
99
import org.gradle.api.Project
10+
import org.gradle.api.file.DirectoryProperty
1011
import org.gradle.api.provider.ListProperty
1112
import org.gradle.api.provider.Property
1213
import org.gradle.api.tasks.Input
@@ -99,7 +100,7 @@ public abstract class BufGenerateTask @Inject internal constructor(
99100
* not the directory for sources. For that see [outputSourceDirectories].
100101
*/
101102
@get:OutputDirectory
102-
public abstract val outputDirectory: Property<File>
103+
public abstract val outputDirectory: DirectoryProperty
103104

104105
/**
105106
* Generated source directories by plugin name.
@@ -113,7 +114,7 @@ public abstract class BufGenerateTask @Inject internal constructor(
113114
*/
114115
@get:Internal
115116
public val outputSourceDirectories: Provider<List<File>> = pluginNames.map { plugins ->
116-
val out = outputDirectory.get()
117+
val out = outputDirectory.get().asFile
117118
plugins.map { out.resolve(it) }
118119
}
119120

@@ -122,7 +123,7 @@ public abstract class BufGenerateTask @Inject internal constructor(
122123

123124
val args = project.provider {
124125
buildList {
125-
add("--output"); add(outputDirectory.get().absolutePath)
126+
add("--output"); add(outputDirectory.get().asFile.absolutePath)
126127

127128
if (includeImports.getOrElse(false) || includeWkt.getOrElse(false)) {
128129
add("--include-imports")
@@ -169,7 +170,7 @@ internal fun Project.registerBufGenerateTask(
169170
includeWkt.convention(generate.includeWkt)
170171
errorFormat.convention(generate.errorFormat)
171172

172-
this.outputDirectory.convention(outputDirectory)
173+
this.outputDirectory.convention(project.layout.dir(project.provider { outputDirectory }))
173174

174175
pluginNames.convention(includedPlugins.map { it.map { plugin -> plugin.name } })
175176

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import kotlinx.rpc.protoc.ProtoTask
1111
import kotlinx.rpc.protoc.ProtocPlugin
1212
import kotlinx.rpc.util.ensureRegularFileExists
1313
import org.gradle.api.Project
14+
import org.gradle.api.file.RegularFileProperty
1415
import org.gradle.api.provider.ListProperty
1516
import org.gradle.api.provider.Property
1617
import org.gradle.api.provider.Provider
@@ -66,11 +67,11 @@ public abstract class GenerateBufGenYaml @Inject internal constructor(
6667
* The `buf.gen.yaml` file to generate/update.
6768
*/
6869
@get:OutputFile
69-
public abstract val bufGenFile: Property<File>
70+
public abstract val bufGenFile: RegularFileProperty
7071

7172
@TaskAction
7273
internal fun generate() {
73-
val file = bufGenFile.get()
74+
val file = bufGenFile.get().asFile
7475
// Parent dir may be missing when the configuration cache hits and `ensureRegularFileExists`
7576
// in the caller is skipped; creating it defensively lets `bufferedWriter()` succeed.
7677
file.parentFile.mkdirs()
@@ -184,7 +185,7 @@ internal fun Project.registerGenerateBufGenYamlTask(
184185
.resolve(BUF_GEN_YAML)
185186
.ensureRegularFileExists()
186187

187-
bufGenFile.convention(bufGenYamlFile)
188+
bufGenFile.convention(project.layout.file(project.provider { bufGenYamlFile }))
188189

189190
configure()
190191
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import kotlinx.rpc.protoc.DefaultProtoTask
99
import kotlinx.rpc.protoc.ProtoTask
1010
import kotlinx.rpc.util.ensureRegularFileExists
1111
import org.gradle.api.Project
12+
import org.gradle.api.file.RegularFileProperty
1213
import org.gradle.api.provider.Property
1314
import org.gradle.api.provider.Provider
1415
import org.gradle.api.tasks.CacheableTask
@@ -62,11 +63,11 @@ public abstract class GenerateBufYaml @Inject internal constructor(
6263
* The `buf.yaml` file to generate/update.
6364
*/
6465
@get:OutputFile
65-
public abstract val bufFile: Property<File>
66+
public abstract val bufFile: RegularFileProperty
6667

6768
@TaskAction
6869
internal fun generate() {
69-
val file = bufFile.get()
70+
val file = bufFile.get().asFile
7071
// Parent dir may be missing when the configuration cache hits and `ensureRegularFileExists`
7172
// in the caller is skipped; creating it defensively lets `bufferedWriter()` succeed.
7273
file.parentFile.mkdirs()
@@ -123,7 +124,7 @@ internal fun Project.registerGenerateBufYamlTask(
123124
.resolve(BUF_YAML)
124125
.ensureRegularFileExists()
125126

126-
bufFile.convention(bufYamlFile)
127+
bufFile.convention(project.layout.file(project.provider { bufYamlFile }))
127128

128129
configure()
129130
}

0 commit comments

Comments
 (0)