Add external reader support in pkl-gradle#1067
Conversation
498201d to
fc0567e
Compare
fc0567e to
a18074d
Compare
|
@HT154 can we add some test coverage for this? I think this would involve moving Hint: the Groovy syntax for maps is externalModuleReaders = ["foo": new org.pkl.gradle.ExternalReader("bar")] |
e6b911e to
f6d3224
Compare
| @Nested | ||
| @Optional | ||
| public abstract MapProperty<String, ExternalReader> getExternalModuleReaders(); | ||
|
|
||
| @Nested | ||
| @Optional | ||
| public abstract MapProperty<String, ExternalReader> getExternalResourceReaders(); |
There was a problem hiding this comment.
These should be marked as @Input properties, not @Nested. The @Nested annotation in Gradle is used to make Gradle process values of a map property as beans. All @Nested properties are treated as @Input, so it will work as is, but semantically values of this map are just data carriers without any annotations which do not require further processing, so I think that @Input would be more appropriate here.
There was a problem hiding this comment.
Thanks @netvl! Do you know of any documentation that covers these subtleties? I wasn't able to find anything when I searched.
There was a problem hiding this comment.
This is all described in Gradle docs, but it may be hard to find, especially since Gradle docs constantly evolve. Most of it comes with experience with writing plugins and sifting through tons of github tickets in the Gradle repo :)
On this particular thing, I believe, the description is here: https://docs.gradle.org/current/userguide/incremental_build.html#sec:task_input_output_annotations
818061b to
5b2a4c8
Compare
5b2a4c8 to
a1565c2
Compare
|
It looks like this hangs right now for reasons I'm not understanding. It's intermittent on *nix systems and seemingly consistent on Windows (but I don't have a system to test that locally). Will likely need a hand debugging this. |
a1565c2 to
cbff681
Compare
cbff681 to
30972cc
Compare
This PR adds support for configuring external module and resource readers in the Gradle plugin, for all tasks which may need it.
Currently, no external readers are passed to the CliBaseOptions instance which is constructed by every task. Therefore, the only way external readers can be used with Gradle is via PklProject definitions, which sometimes may be limiting. After this change, it will be possible to configure external readers for any tasks, including those which operate on individual modules and not the entire projects.
I'm using NamedDomainObjectContainer to store reader definitions. The name of each reader's definition is passed through into the CLI classes as the map key. Therefore, you can define an external reader like this:
```kotlin
val myPklTask by pkl.operationKind.creating {
val foo by externalModuleReaders.creating {
executable = "external-executable"
arguments = listOf("--bar", "baz")
}
}
```
and then use `foo` as the URI schema in the Pkl code:
```pkl
import "foo:a/b/c"
```
Properties of each external reader spec are defined as proper properties and are propagated as input dependencies to the task, so the caching and task dependency resolution behaves as expected.
I completely forgot that apple#1067 exists and reimplemented this from scratch. But my approach to the interface is slightly different and more in line with Gradle recommendations, IMO, and I really need this functionality so I intend to see this through. As in that PR, there are no tests which validate the actual invocation of the external command because creating one requires writing a command which does msgpack, which I'm unsure of how to do properly within this project.
This PR adds support for configuring external module and resource readers in the Gradle plugin, for all tasks which may need it.
Currently, no external readers are passed to the CliBaseOptions instance which is constructed by every task. Therefore, the only way external readers can be used with Gradle is via PklProject definitions, which sometimes may be limiting. After this change, it will be possible to configure external readers for any tasks, including those which operate on individual modules and not the entire projects.
I'm using NamedDomainObjectContainer to store reader definitions. The name of each reader's definition is passed through into the CLI classes as the map key. Therefore, you can define an external reader like this:
```kotlin
val myPklTask by pkl.operationKind.creating {
val foo by externalModuleReaders.creating {
executable = "external-executable"
arguments = listOf("--bar", "baz")
}
}
```
and then use `foo` as the URI schema in the Pkl code:
```pkl
import "foo:a/b/c"
```
Properties of each external reader spec are defined as proper properties and are propagated as input dependencies to the task, so the caching and task dependency resolution behaves as expected.
I completely forgot that apple#1067 exists and reimplemented this from scratch. But my approach to the interface is slightly different and more in line with Gradle recommendations, IMO, and I really need this functionality so I intend to see this through. As in that PR, there are no tests which validate the actual invocation of the external command because creating one requires writing a command which does msgpack, which I'm unsure of how to do properly within this project.
This PR adds support for configuring external module and resource readers in the Gradle plugin, for all tasks which may need it.
Currently, no external readers are passed to the CliBaseOptions instance which is constructed by every task. Therefore, the only way external readers can be used with Gradle is via PklProject definitions, which sometimes may be limiting. After this change, it will be possible to configure external readers for any tasks, including those which operate on individual modules and not the entire projects.
I'm using NamedDomainObjectContainer to store reader definitions. The name of each reader's definition is passed through into the CLI classes as the map key. Therefore, you can define an external reader like this:
```kotlin
val myPklTask by pkl.operationKind.creating {
val foo by externalModuleReaders.creating {
executable = "external-executable"
arguments = listOf("--bar", "baz")
}
}
```
and then use `foo` as the URI schema in the Pkl code:
```pkl
import "foo:a/b/c"
```
Properties of each external reader spec are defined as proper properties and are propagated as input dependencies to the task, so the caching and task dependency resolution behaves as expected.
I completely forgot that apple#1067 exists and reimplemented this from scratch. But my approach to the interface is slightly different and more in line with Gradle recommendations, IMO, and I really need this functionality so I intend to see this through. As in that PR, there are no tests which validate the actual invocation of the external command because creating one requires writing a command which does msgpack, which I'm unsure of how to do properly within this project.
This PR adds support for configuring external module and resource readers in the Gradle plugin, for all tasks which may need it.
Currently, no external readers are passed to the CliBaseOptions instance which is constructed by every task. Therefore, the only way external readers can be used with Gradle is via PklProject definitions, which sometimes may be limiting. After this change, it will be possible to configure external readers for any tasks, including those which operate on individual modules and not the entire projects.
I'm using NamedDomainObjectContainer to store reader definitions. The name of each reader's definition is passed through into the CLI classes as the map key. Therefore, you can define an external reader like this:
```kotlin
val myPklTask by pkl.operationKind.creating {
val foo by externalModuleReaders.creating {
executable = "external-executable"
arguments = listOf("--bar", "baz")
}
}
```
and then use `foo` as the URI schema in the Pkl code:
```pkl
import "foo:a/b/c"
```
Properties of each external reader spec are defined as proper properties and are propagated as input dependencies to the task, so the caching and task dependency resolution behaves as expected.
I completely forgot that apple#1067 exists and reimplemented this from scratch. But my approach to the interface is slightly different and more in line with Gradle recommendations, IMO, and I really need this functionality so I intend to see this through. As in that PR, there are no tests which validate the actual invocation of the external command because creating one requires writing a command which does msgpack, which I'm unsure of how to do properly within this project.
This PR adds support for configuring external module and resource readers in the Gradle plugin, for all tasks which may need it.
Currently, no external readers are passed to the CliBaseOptions instance which is constructed by every task. Therefore, the only way external readers can be used with Gradle is via PklProject definitions, which sometimes may be limiting. After this change, it will be possible to configure external readers for any tasks, including those which operate on individual modules and not the entire projects.
I'm using NamedDomainObjectContainer to store reader definitions. The name of each reader's definition is passed through into the CLI classes as the map key. Therefore, you can define an external reader like this:
```kotlin
val myPklTask by pkl.operationKind.creating {
val foo by externalModuleReaders.creating {
executable = "external-executable"
arguments = listOf("--bar", "baz")
}
}
```
and then use `foo` as the URI schema in the Pkl code:
```pkl
import "foo:a/b/c"
```
Properties of each external reader spec are defined as proper properties and are propagated as input dependencies to the task, so the caching and task dependency resolution behaves as expected.
I completely forgot that apple#1067 exists and reimplemented this from scratch. But my approach to the interface is slightly different and more in line with Gradle recommendations, IMO, and I really need this functionality so I intend to see this through. As in that PR, there are no tests which validate the actual invocation of the external command because creating one requires writing a command which does msgpack, which I'm unsure of how to do properly within this project.
This PR adds support for configuring external module and resource readers in the Gradle plugin, for all tasks which may need it.
Currently, no external readers are passed to the CliBaseOptions instance which is constructed by every task. Therefore, the only way external readers can be used with Gradle is via PklProject definitions, which sometimes may be limiting. After this change, it will be possible to configure external readers for any tasks, including those which operate on individual modules and not the entire projects.
I'm using NamedDomainObjectContainer to store reader definitions. The name of each reader's definition is passed through into the CLI classes as the map key. Therefore, you can define an external reader like this:
```kotlin
val myPklTask by pkl.operationKind.creating {
val foo by externalModuleReaders.creating {
executable = "external-executable"
arguments = listOf("--bar", "baz")
}
}
```
and then use `foo` as the URI schema in the Pkl code:
```pkl
import "foo:a/b/c"
```
Properties of each external reader spec are defined as proper properties and are propagated as input dependencies to the task, so the caching and task dependency resolution behaves as expected.
I completely forgot that apple#1067 exists and reimplemented this from scratch. But my approach to the interface is slightly different and more in line with Gradle recommendations, IMO, and I really need this functionality so I intend to see this through. As in that PR, there are no tests which validate the actual invocation of the external command because creating one requires writing a command which does msgpack, which I'm unsure of how to do properly within this project.
Test on [windows] please