Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy slash operator (Jenkins job-dsl)

We would like to understand a couple of legacy job-dsl scripts but don't know what "slash operator" means in this context (as it cant be division):

def command = (shells.first() / command)

We have tried to look it up in several Groovy books but only found the trivial solution that it means 'division'.

like image 435
user1724641 Avatar asked Jan 26 '15 16:01

user1724641


1 Answers

It's an XML Node operation, to return a sub-node of a XML node, or create it if it doesn't exist. Probably the command node under the first of your shells nodes here.

Groovy allows operator overloading, so it is the same "division" operator, just redefined somewhat. This is common (but also controversial) in other languages allowing operator overloading, but does allow for richer DSLs.

Having had a quick look at (an old copy of) the JobDSL source, it seems that they're doing it using a class NodeEnhancement, notably this JavaDoc:

/**
Add div and leftShift operators to Node.
div - Will return the first child that matches name, and if it doesn't exists, it creates
...
**/
like image 79
declension Avatar answered Sep 20 '22 23:09

declension