From 5b1f26962c61cfa7430d73a2618a47eafba35e53 Mon Sep 17 00:00:00 2001 From: Daniel Spilker Date: Sun, 28 May 2017 11:48:01 +0200 Subject: [PATCH] refactoring --- .../jobdsl/dsl/views/SectionsContext.groovy | 82 ++++++------------- .../dsl/views/TextSectionContext.groovy | 2 +- .../views/ViewListingSectionContext.groovy | 2 +- 3 files changed, 27 insertions(+), 59 deletions(-) diff --git a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/views/SectionsContext.groovy b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/views/SectionsContext.groovy index 62134e3ee..f999798f1 100644 --- a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/views/SectionsContext.groovy +++ b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/views/SectionsContext.groovy @@ -17,11 +17,8 @@ class SectionsContext extends AbstractContext { /* * Adds a generic section. */ - private void generic(String type, @DslContext(SectionContext) Closure sectionClosure) { - SectionContext context = new SectionContext(jobManagement) - executeInContext(sectionClosure, context) - - sectionNodes << new NodeBuilder()."$type" { + private Node generic(String type, SectionContext context) { + Node node = new NodeBuilder()."$type" { jobNames { comparator(class: 'hudson.util.CaseInsensitiveComparator') for (String job : context.jobsContext.jobNames.sort(true, CASE_INSENSITIVE_ORDER)) { // see GROOVY-6900 @@ -36,6 +33,18 @@ class SectionsContext extends AbstractContext { width(context.width) alignment(context.alignment) } + sectionNodes << node + node + } + + /* + * Adds a generic section. + */ + private Node generic(String type, @DslContext(SectionContext) Closure sectionClosure) { + SectionContext context = new SectionContext(jobManagement) + executeInContext(sectionClosure, context) + + generic(type, context) } /** @@ -54,22 +63,8 @@ class SectionsContext extends AbstractContext { ListViewSectionContext context = new ListViewSectionContext(jobManagement) executeInContext(listViewSectionClosure, context) - sectionNodes << new NodeBuilder().'hudson.plugins.sectioned__view.ListViewSection' { - jobNames { - comparator(class: 'hudson.util.CaseInsensitiveComparator') - for (String job : context.jobsContext.jobNames.sort(true, CASE_INSENSITIVE_ORDER)) { // see GROOVY-6900 - string(job) - } - } - jobFilters(context.jobFiltersContext.filterNodes) - name(context.name) - if (context.jobsContext.regex) { - includeRegex(context.jobsContext.regex) - } - width(context.width) - alignment(context.alignment) - columns(context.columnsContext.columnNodes) - } + Node node = generic('hudson.plugins.sectioned__view.ListViewSection', context) + node.appendNode('columns', context.columnsContext.columnNodes) } /** @@ -90,23 +85,9 @@ class SectionsContext extends AbstractContext { TextSectionContext context = new TextSectionContext(jobManagement) executeInContext(textSectionClosure, context) - sectionNodes << new NodeBuilder().'hudson.plugins.sectioned__view.TextSection' { - jobNames { - comparator(class: 'hudson.util.CaseInsensitiveComparator') - for (String job : context.jobsContext.jobNames.sort(true, CASE_INSENSITIVE_ORDER)) { // see GROOVY-6900 - string(job) - } - } - jobFilters(context.jobFiltersContext.filterNodes) - name(context.name) - if (context.jobsContext.regex) { - includeRegex(context.jobsContext.regex) - } - width(context.width) - alignment(context.alignment) - text(context.text) - style(context.style) - } + Node node = generic('hudson.plugins.sectioned__view.TextSection', context) + node.appendNode('text', context.text ?: '') + node.appendNode('style', context.style) } /** @@ -118,26 +99,13 @@ class SectionsContext extends AbstractContext { ViewListingSectionContext context = new ViewListingSectionContext(jobManagement) executeInContext(viewListingSectionClosure, context) - sectionNodes << new NodeBuilder().'hudson.plugins.sectioned__view.ViewListingSection' { - jobNames { - comparator(class: 'hudson.util.CaseInsensitiveComparator') - for (String job : context.jobsContext.jobNames.sort(true, CASE_INSENSITIVE_ORDER)) { // see GROOVY-6900 - string(job) - } - } - jobFilters(context.jobFiltersContext.filterNodes) - name(context.name) - if (context.jobsContext.regex) { - includeRegex(context.jobsContext.regex) - } - width(context.width) - alignment(context.alignment) - views { - for (String view : context.viewNames.sort(true, CASE_INSENSITIVE_ORDER)) { // see GROOVY-6900 - string(view) - } + Node views = new NodeBuilder().'views' { + for (String view : context.viewNames.sort(true, CASE_INSENSITIVE_ORDER)) { // see GROOVY-6900 + string(view) } - columns(context.columns) } + Node node = generic('hudson.plugins.sectioned__view.ViewListingSection', context) + node.append(views) + node.appendNode('columns', context.columns) } } diff --git a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/views/TextSectionContext.groovy b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/views/TextSectionContext.groovy index 17df0c952..ff8395dda 100644 --- a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/views/TextSectionContext.groovy +++ b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/views/TextSectionContext.groovy @@ -8,7 +8,7 @@ class TextSectionContext extends SectionContext { private static final List VALID_STYLES = ['NONE', 'NOTE', 'INFO', 'WARNING', 'TIP'] String style = 'NONE' - String text = '' + String text TextSectionContext(JobManagement jobManagement) { super(jobManagement) diff --git a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/views/ViewListingSectionContext.groovy b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/views/ViewListingSectionContext.groovy index e5fce07fd..b45bfd214 100644 --- a/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/views/ViewListingSectionContext.groovy +++ b/job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/views/ViewListingSectionContext.groovy @@ -35,7 +35,7 @@ class ViewListingSectionContext extends SectionContext { */ void views(String... viewNames) { for (String viewName : viewNames) { - name(viewName) + view(viewName) } } }