jenkinsci/job-dsl-plugin — pull request #107 by daspilker (2013-11-01 08:59:15+00:00)
Title: Views

This pull request adds support for creating and updating Jenkins (list) views.

```groovy
view(type: ListView) { // type is optional, ListView is the default
name(String name)
description(String description)
filterBuildQueue(boolean filterBuildQueue)
filterExecutors(boolean filterExecutors)
statusFilter(StatusFilter filter)
jobs {
name(String jobName) // names are accumulated, duplicates will be eliminated
names(String... jobNames)
regex(String regex)
}
columns {
status()
weather()
name()
lastSuccess()
lastFailure()
lastDuration()
buildButton()
}
configure(Closure withXmlClosure)
}
```

I renamed several classes since they are no longer dealing with jobs exclusively:
* JobParent → DslScript
* JobNameNotProvidedException → NameNotProvidedException
* ConfigurationMissingException → ConfigurationMissingException

Scripts depending on these class names will break, but I hope that only a few people are using them.

I used a different approach to deal with different view types. While the job types we currently support have many methods in common, views only share a few methods. Instead of having a single View class which is extended by helpers, I thought it will be more feasible to have subclass of View for each concrete view. The view method in DslScript chooses the concrete View subclass from a mapping of ViewTypes to View classes. The views package contains the View subclasses, currently only ListView.

ListView has a statusFilter method which has an enum argument. To avoid additional star imports for the DslScript which are likely to cause name collisions in the future, I used propertyMissing in ListView to expose the enum values to the view closure.

For the jobs and columns closures, I set the resolve strategy to DELEGATE_FIRST so that these methods can define their own name methods. When not setting the resolve strategy, the name method of the enclosing view closure will be called, which is not desired.

I updated the dependency to Spock to be able to use newer mocking and spying feature, which also required runtime dependencies to cglib and objenesis.