groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Bayer <andrew.ba...@gmail.com>
Subject Lazy evaluation of properties in a closure?
Date Fri, 23 Sep 2016 16:28:22 GMT
So I've got a DSL that has a section that looks like
https://gist.github.com/abayer/a0bfbb531457e79aabc8d6c25d992e62, which ends
up translating (via
https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/master/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ClosureModelTranslator.groovy
and then
https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/master/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/PropertiesToMapTranslator.groovy)
into a Map, and later on I actually do things with the contents of that Map
in a different context entirely. Fun, right?

So the literal syntax works fine, but non-literals get evaluated when I
call the closure to translate it into a Map. I don't want that - it causes
problems due to not being called in the context that actually has the
"getFruit()" and "getCandy()" methods (and due to the Jenkins Pipeline
Groovy CPS magic for continuation passing style and script security that
make things even weirder). I'd really, really love to be able to lazily
evaluate the property values here while still having dynamic properties,
since I don't know what the names of all the environment variables people
may need will be.

Anyone have any suggestions or ideas? I've looked at the @Lazy field
annotation, which would be perfect if I could use it with dynamic
properties, but I can't see a way to actually do that...

Thanks!

A.

Mime
View raw message