diff --git a/docs/Home.md b/docs/Home.md index fdd075e65..61c606982 100644 --- a/docs/Home.md +++ b/docs/Home.md @@ -37,6 +37,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins ([#882](https://github.com/jenkinsci/job-dsl-plugin/pull/882)) * Enhanced support for the [Groovy Postbuild Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin) ([#884](https://github.com/jenkinsci/job-dsl-plugin/pull/884)) + * Allow extensions for job view filters + ([#896](https://github.com/jenkinsci/job-dsl-plugin/pull/896)) * Updated [Structs Plugin](https://github.com/jenkinsci/structs-plugin) dependency to version 1.2 * Improved support for [[Automatically Generated DSL]]: print deprecation warnings and show deprecated methods in API viewer diff --git a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/views/JobFiltersContext.groovy b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/views/JobFiltersContext.groovy index 944dae2dc..888fa55d9 100644 --- a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/views/JobFiltersContext.groovy +++ b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/views/JobFiltersContext.groovy @@ -1,6 +1,7 @@ package javaposse.jobdsl.dsl.views -import javaposse.jobdsl.dsl.AbstractContext +import javaposse.jobdsl.dsl.AbstractExtensibleContext +import javaposse.jobdsl.dsl.ContextType import javaposse.jobdsl.dsl.DslContext import javaposse.jobdsl.dsl.JobManagement import javaposse.jobdsl.dsl.RequiresPlugin @@ -13,11 +14,17 @@ import javaposse.jobdsl.dsl.views.jobfilter.UnclassifiedJobsFilter import static javaposse.jobdsl.dsl.ContextHelper.executeInContext -class JobFiltersContext extends AbstractContext { +@ContextType('hudson.views.ViewJobFilter') +class JobFiltersContext extends AbstractExtensibleContext { List filterNodes = [] protected JobFiltersContext(JobManagement jobManagement) { - super(jobManagement) + super(jobManagement, null) + } + + @Override + protected void addExtensionNode(Node node) { + filterNodes << node } /** diff --git a/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/views/ListViewSpec.groovy b/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/views/ListViewSpec.groovy index 1e5a647be..f935b1d4d 100644 --- a/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/views/ListViewSpec.groovy +++ b/job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/views/ListViewSpec.groovy @@ -577,6 +577,24 @@ class ListViewSpec extends Specification { 1 * jobManagement.requireMinimumPluginVersion('release', '2.5.3') } + def 'job filter extension'() { + setup: + jobManagement.callExtension('extension', null, JobFiltersContext) >> new Node(null, 'foo') + + when: + view.jobFilters { + extension() + } + + then: + def filters = view.node.jobFilters[0].value() + filters.size() == 1 + with(filters[0]) { + name() == 'foo' + children().size() == 0 + } + } + def 'recurse folders'() { when: view.recurse()