Slackbot
02/09/2024, 6:26 PMMartin
02/09/2024, 6:26 PMFile but that feels a bit off tootony
02/09/2024, 6:50 PMproviders.fileContents but gradle seemed to lose track of the task dependency. This was with gradle 7.6 so maybe there was a bug? but it seemed somewhat reasonable to me...Martin
02/09/2024, 6:54 PMFileContents fileContents(RegularFile file);
FileContents fileContents(Provider<RegularFile> file);
so it's only for files? Or do you mean implement FileContents directly? Without going through providers ?tony
02/09/2024, 7:14 PMproject.providers.fileContents(task.flatMap { it.output })Martin
02/09/2024, 7:55 PMProvider<RegularFile> into a Provider<String> or Provider<ByteArray> right?
But what I want is more a property type theat's neither Property<RegularFile> nor Property<String> . Ideally something like:
// Serializable to serialize to CC
interface MyInput: Serializable {
fun writeContentsTo(outputStream: OutputStream) {
// Write the actual byte contents
// If MyInput is backed by a file, reads the file
// If MyInput is backed by a String, reads the chars array
}
}
open class MyTask: DefaultTask() {
val myProp: Property<MyInput>
}Martin
02/09/2024, 7:57 PMtony
02/09/2024, 7:59 PMMartin
02/09/2024, 8:00 PMMartin
02/09/2024, 8:03 PMtask.register("myTask", MyTask::class.java) {
myProp.set(task.flatMap { it.output.map { FileInput(it.asFile) } }
}
or string input:
task.register("myTask", MyTask::class.java) {
myProp.set(InMemoryInput("someInput"))
}
And if the input is "File" backed, only the file path is saved to CC. And if it's "Memory" backed then serialize everythingMartin
02/09/2024, 8:03 PMtony
02/09/2024, 8:05 PMMartin
02/09/2024, 8:05 PMMartin
02/09/2024, 8:06 PMtony
02/09/2024, 8:07 PMMartin
02/09/2024, 8:07 PMtony
02/09/2024, 8:08 PMProvider.filter() to check if a file exists and if not, use something else, but then CC still has to read the whole file I think (based on a conversation I saw in another channel)Vampire
02/09/2024, 10:38 PMif the input is "File" backed, only the file path is saved to CC. And if it's "Memory" backed then serialize everythingMaybe make the property be
Property<String> and have some setters. If a file is set, set it to the file:/// uri, if a string is set, set it to the `String`and require it does not start with file:, or set it to string:<the given string>. Then at execution time you can use the string or read the file.Martin
02/09/2024, 10:45 PMMartin
02/09/2024, 10:45 PMMartin
02/09/2024, 10:46 PMMartin
02/09/2024, 10:48 PMString or FileVampire
02/09/2024, 10:52 PMfingerprintingof what? For up-to-date / build cache? You probably need additionally an input file property then for that?
Vampire
02/09/2024, 10:53 PMVampire
02/09/2024, 10:55 PM@Nested property type and then two subclasses, one with a file property, one with a string property?Vampire
02/09/2024, 10:55 PMMartin
02/09/2024, 10:56 PMthen two subclasses, one with a file property, one with a string property?This is exactly what I had in mind but easier said than done 😅
Vampire
02/09/2024, 11:15 PMinterface TheInput {
fun retrieveInput(): String
}
abstract class FileInput : TheInput {
@get:InputFile
abstract val file: RegularFileProperty
override fun retrieveInput() = file.get().asFile.readText()
}
abstract class StringInput : TheInput {
@get:Input
abstract val string: Property<String>
override fun retrieveInput() = string.get()
}
abstract class Foo : DefaultTask() {
@get:Nested
abstract val input: Property<TheInput>
init {
outputs.upToDateWhen { true }
}
@TaskAction
fun foo() = println(input.get().retrieveInput())
}
val foo by tasks.registering(Foo::class) {
input = objects.newInstance<StringInput>().apply {
string = "foo"
}
}
val bar by tasks.registering(Foo::class) {
input = objects.newInstance<FileInput>().apply {
file = file("bar.txt")
}
}
Of course for the objects.newInstance stuff some convenience method or setter or whatever can be used instead.
The tasks are up-to-date if the input string and the content of the input file do not change and out of date if for example the file content changed.
And the CC is always reused, whether the file content changes or not.Martin
02/09/2024, 11:19 PMMartin
02/09/2024, 11:20 PMVampire
02/09/2024, 11:42 PM