Hi everyone!
Some days ago Kohsuke released a new plugin which can be used by DSL plugins to generate DSL syntax from metadata provided by Descriptors[2]. I started to explore how Job DSL can use that plugin to complement the existing Job DSL ContextExtensionPoint and opened a pull request [3] to show the progress.
I'm very happy with the intermediate results. Let's take some of the currently open pull requests [4][5][6][7][8] as an example. The following DSL will work by just applying my changes and it does neither require specific support for those plugins in the DSL nor any changes in the plugins themselves.
job('example') {
steps {
phingBuilder {
name('Phing 1.8')
useModuleRoot(false)
properties('KEY=VALUE')
targets('test')
options('--debug')
buildFile('dir1/build.xml')
}
exporterBuilder()
unity3dBuilder {
unstableReturnCodes('2,3')
argLine('-batchmode')
}
msBuildBuilder {
msBuildName('MSBuild 1.8')
msBuildFile('dir1/build.proj')
cmdLineArgs('check')
buildVariablesAsProperties(true)
continueOnBuildFailure(true)
unstableIfWarnings(true)
}
}
publishers {
logParserPublisher {
projectRulePath('unitybuilder.parser')
useProjectRule(true)
unstableOnWarning(true)
failBuildOnError(true)
}
}
}
The DSL syntax can be derived from the config XML. Field/property names can be taken from the XML directly and class names are shortened by using the uncapitalized class name only. The following config XML corresponds to the phingBuilder DSL above:
<project>
<builders>
<hudson.plugins.phing.PhingBuilder>
<buildFile>dir1/build.xml</buildFile>
<name>Phing 1.8</name>
<targets>test</targets>
<properties>KEY=VALUE</properties>
<useModuleRoot>false</useModuleRoot>
<options>--debug</options>
</hudson.plugins.phing.PhingBuilder>
</builders>
</project>
The syntax resembles the built-in DSL methods except for the step and publisher names where we would for example use phing instead of phingBuilder. But that can be solved by adding the new @Symbol annotation to the plugin, which is only a minimal change to the plugin. See [1] for details. As an example I added some symbols to the Gerrit Trigger plugin to get nicer method names for the trigger events, see [9].