Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
daspilker committed May 28, 2017
1 parent 07ebcea commit 5b1f269
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

/**
Expand All @@ -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)
}

/**
Expand All @@ -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)
}

/**
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TextSectionContext extends SectionContext {
private static final List<String> VALID_STYLES = ['NONE', 'NOTE', 'INFO', 'WARNING', 'TIP']

String style = 'NONE'
String text = ''
String text

TextSectionContext(JobManagement jobManagement) {
super(jobManagement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ViewListingSectionContext extends SectionContext {
*/
void views(String... viewNames) {
for (String viewName : viewNames) {
name(viewName)
view(viewName)
}
}
}

0 comments on commit 5b1f269

Please sign in to comment.