Add hook to customize script compiler

15 visualizzazioni
Passa al primo messaggio da leggere

Rui Fernando Hayashi

da leggere,
19 nov 2015, 14:20:1619/11/15
a job-dsl-plugin
Hello

First of all, congrats for the awesome plugin :)

I think it would be useful if jobdsl had a hook so it could be possible to customize the script compiler. Specially when you're providing a library of reusable jobs, I see two main use cases:

1. Ability to auto add imports, so something like:

import static mypackage.Jobs.*

jobA(this)
jobB(this)


would turn into this:

jobA(this)
jobB(this)


2. Ability to subclass JobParent so you could add methods to it and specially get rid of having to pass "this" to the library methods. In the last example, the code would be:

jobA()
jobB()


I think that would also open up the possibility of creating custom dsl's that could be used for developers that are not familiar with jobdsl. I know that it's just a case of adding some imports and passing the JobParent instance around, but I think it looks a lot more natural without them.

I made a little experiment and implemented a proof of concept of my ideas:

https://github.com/rfhayashi/job-dsl-plugin/commit/4bdc10bac028c3643684c467d01581bcfb7c2895

I wrote two test cases that show how it would be used:

https://github.com/rfhayashi/job-dsl-plugin/commit/4bdc10bac028c3643684c467d01581bcfb7c2895#diff-a9e95cee45810853c0c425ddd9bb16f9R345

Basically, the idea is to add a Compiler Customizer Script field that allows you to specify a groovy script. That script will receive a variable "config" that is a reference to the CompilerConfiguration used by DslScriptLoader (https://github.com/rfhayashi/job-dsl-plugin/commit/4bdc10bac028c3643684c467d01581bcfb7c2895#diff-c6b6f5578012a20de5f9bfb67773d32fR240), so it's just a matter of tweaking it to your own needs (ex: https://github.com/rfhayashi/job-dsl-plugin/commit/4bdc10bac028c3643684c467d01581bcfb7c2895#diff-360ce885a32c7207116c2f333d67ae77R1).

What are your thoughts? Do you think it is a good idea? If so, do you think it is a good implementation or can anyone suggest a different approach?

Cheers

Rui
Rispondi a tutti
Rispondi all'autore
Inoltra
0 nuovi messaggi