Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sectioned view #1037

Merged
merged 5 commits into from
Jun 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Browse the Jenkins issue tracker to see any [open issues](https://issues.jenkins
([#1028](https://github.com/jenkinsci/job-dsl-plugin/pull/1028))
* Enhanced support for the [Gradle Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Gradle+Plugin)
([JENKINS-44217](https://issues.jenkins-ci.org/browse/JENKINS-44217))
* Enhanced support for [Sectioned View Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Sectioned+View+Plugin)
([#1037](https://github.com/jenkinsci/job-dsl-plugin/pull/1037))
* Support for older versions of the
[HTML Publisher Plugin](https://wiki.jenkins-ci.org/display/JENKINS/HTML+Publisher+Plugin) is deprecated, see
[Migration](Migration#migrating-to-164)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sectionedView('example') {
sections {
jobGraphs {
name('project-A')
width('HALF')
alignment('LEFT')
jobs {
regex('project-A-.*')
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sectionedView('example') {
sections {
testResult {
name('project-A')
width('HALF')
alignment('LEFT')
jobs {
regex('project-A-.*')
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sectionedView('example') {
sections {
text {
name('project-A')
width('HALF')
alignment('LEFT')
style('TIP')
text('Helpful tip')
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sectionedView('example') {
sections {
viewListing {
name('project-A')
width('HALF')
alignment('LEFT')
columns(2)
view('view-a')
view('view-b')
}
}
}
Original file line number Diff line number Diff line change
@@ -1,66 +1,17 @@
package javaposse.jobdsl.dsl.views

import javaposse.jobdsl.dsl.AbstractContext
import javaposse.jobdsl.dsl.DslContext
import javaposse.jobdsl.dsl.JobManagement

import static javaposse.jobdsl.dsl.ContextHelper.executeInContext
import static javaposse.jobdsl.dsl.Preconditions.checkArgument

class ListViewSectionContext extends AbstractContext {
private static final List<String> VALID_WIDTHS = ['FULL', 'HALF', 'THIRD', 'TWO_THIRDS']
private static final List<String> VALID_ALIGNMENTS = ['CENTER', 'LEFT', 'RIGHT']

String name
String width = 'FULL'
String alignment = 'CENTER'
JobsContext jobsContext = new JobsContext()
JobFiltersContext jobFiltersContext = new JobFiltersContext(jobManagement)
class ListViewSectionContext extends SectionContext {
ColumnsContext columnsContext = new ColumnsContext(jobManagement)

ListViewSectionContext(JobManagement jobManagement) {
super(jobManagement)
}

/**
* Sets the name of the section.
*/
void name(String name) {
this.name = name
}

/**
* Sets the with of the section. Either {@code 'FULL'}, {@code 'HALF'}, {@code 'THIRD'} or {@code 'TWO_THIRDS'}.
*/
void width(String width) {
checkArgument(VALID_WIDTHS.contains(width), "width must be one of ${VALID_WIDTHS.join(', ')}")
this.width = width
}

/**
* Sets the alignment of the section. Either {@code 'CENTER'}, {@code 'LEFT'} or {@code 'RIGHT'}.
*/
void alignment(String alignment) {
checkArgument(VALID_ALIGNMENTS.contains(alignment), "alignment must be one of ${VALID_ALIGNMENTS.join(', ')}")
this.alignment = alignment
}

/**
* Adds jobs to the section.
*/
void jobs(@DslContext(JobsContext) Closure jobsClosure) {
executeInContext(jobsClosure, jobsContext)
}

/**
* Adds or removes jobs from the view by specifying filters.
*
* @since 1.29
*/
void jobFilters(@DslContext(JobFiltersContext) Closure jobFiltersClosure) {
executeInContext(jobFiltersClosure, jobFiltersContext)
}

/**
* Adds columns to the views. The view will have no columns by default.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package javaposse.jobdsl.dsl.views

import javaposse.jobdsl.dsl.AbstractContext
import javaposse.jobdsl.dsl.DslContext
import javaposse.jobdsl.dsl.JobManagement

import static javaposse.jobdsl.dsl.ContextHelper.executeInContext
import static javaposse.jobdsl.dsl.Preconditions.checkArgument

class SectionContext extends AbstractContext {
private static final List<String> VALID_WIDTHS = ['FULL', 'HALF', 'THIRD', 'TWO_THIRDS']
private static final List<String> VALID_ALIGNMENTS = ['CENTER', 'LEFT', 'RIGHT']

String name
String width = 'FULL'
String alignment = 'CENTER'
JobsContext jobsContext = new JobsContext()
JobFiltersContext jobFiltersContext = new JobFiltersContext(jobManagement)

SectionContext(JobManagement jobManagement) {
super(jobManagement)
}

/**
* Sets the name of the section.
*/
void name(String name) {
this.name = name
}

/**
* Sets the with of the section. Either {@code 'FULL'}, {@code 'HALF'}, {@code 'THIRD'} or {@code 'TWO_THIRDS'}.
*/
void width(String width) {
checkArgument(VALID_WIDTHS.contains(width), "width must be one of ${VALID_WIDTHS.join(', ')}")
this.width = width
}

/**
* Sets the alignment of the section. Either {@code 'CENTER'}, {@code 'LEFT'} or {@code 'RIGHT'}.
*/
void alignment(String alignment) {
checkArgument(VALID_ALIGNMENTS.contains(alignment), "alignment must be one of ${VALID_ALIGNMENTS.join(', ')}")
this.alignment = alignment
}

/**
* Adds jobs to the section.
*/
void jobs(@DslContext(JobsContext) Closure jobsClosure) {
executeInContext(jobsClosure, jobsContext)
}

/**
* Adds or removes jobs from the view by specifying filters.
*
* @since 1.29
*/
void jobFilters(@DslContext(JobFiltersContext) Closure jobFiltersClosure) {
executeInContext(jobFiltersClosure, jobFiltersContext)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ class SectionsContext extends AbstractContext {
super(jobManagement)
}

/**
* Adds a list view section.
/*
* Adds a generic section.
*/
void listView(@DslContext(ListViewSectionContext) Closure listViewSectionClosure) {
ListViewSectionContext context = new ListViewSectionContext(jobManagement)
executeInContext(listViewSectionClosure, context)

sectionNodes << new NodeBuilder().'hudson.plugins.sectioned__view.ListViewSection' {
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 @@ -35,7 +32,80 @@ class SectionsContext extends AbstractContext {
}
width(context.width)
alignment(context.alignment)
columns(context.columnsContext.columnNodes)
}
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)
}

/**
* Adds a job graphs section.
*
* @since 1.64
*/
void jobGraphs(@DslContext(SectionContext) Closure sectionClosure) {
generic('hudson.plugins.sectioned__view.JobGraphsSection', sectionClosure)
}

/**
* Adds a list view section.
*/
void listView(@DslContext(ListViewSectionContext) Closure listViewSectionClosure) {
ListViewSectionContext context = new ListViewSectionContext(jobManagement)
executeInContext(listViewSectionClosure, context)

Node node = generic('hudson.plugins.sectioned__view.ListViewSection', context)
node.appendNode('columns', context.columnsContext.columnNodes)
}

/**
* Adds a test result section.
*
* @since 1.64
*/
void testResult(@DslContext(SectionContext) Closure sectionClosure) {
generic('hudson.plugins.sectioned__view.TestResultViewSection', sectionClosure)
}

/**
* Adds a text view section.
*
* @since 1.64
*/
void text(@DslContext(TextSectionContext) Closure textSectionClosure) {
TextSectionContext context = new TextSectionContext(jobManagement)
executeInContext(textSectionClosure, context)

Node node = generic('hudson.plugins.sectioned__view.TextSection', context)
node.appendNode('text', context.text ?: '')
node.appendNode('style', context.style)
}

/**
* Adds a view listing section.
*
* @since 1.64
*/
void viewListing(@DslContext(ViewListingSectionContext) Closure viewListingSectionClosure) {
ViewListingSectionContext context = new ViewListingSectionContext(jobManagement)
executeInContext(viewListingSectionClosure, context)

Node views = new NodeBuilder().'views' {
for (String view : context.viewNames.sort(true, CASE_INSENSITIVE_ORDER)) { // see GROOVY-6900
string(view)
}
}
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
@@ -0,0 +1,32 @@
package javaposse.jobdsl.dsl.views

import javaposse.jobdsl.dsl.JobManagement

import static javaposse.jobdsl.dsl.Preconditions.checkArgument

class TextSectionContext extends SectionContext {
private static final List<String> VALID_STYLES = ['NONE', 'NOTE', 'INFO', 'WARNING', 'TIP']

String style = 'NONE'
String text

TextSectionContext(JobManagement jobManagement) {
super(jobManagement)
}

/**
* Sets the style of the section. Either {@code 'NONE'}, {@code 'NOTE'}, {@code 'INFO'}, {@code WARNING'}, or
* {@code 'TIP'}.
*/
void style(String style) {
checkArgument(VALID_STYLES.contains(style), "style must be one of ${VALID_STYLES.join(', ')}")
this.style = style
}

/**
* Sets the text of the section.
*/
void text(String text) {
this.text = text
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package javaposse.jobdsl.dsl.views

import javaposse.jobdsl.dsl.JobManagement

import static javaposse.jobdsl.dsl.Preconditions.checkArgument
import static javaposse.jobdsl.dsl.Preconditions.checkNotNull

class ViewListingSectionContext extends SectionContext {
int columns = 1
Set<String> viewNames = []

ViewListingSectionContext(JobManagement jobManagement) {
super(jobManagement)
}

/**
* Sets the number of columns of the section.
*/
void columns(int columns) {
checkArgument(columns > 0, 'columns must be positive integer')
this.columns = columns
}

/**
* Adds views to the section. Can be called multiple times to added more views.
*/
void view(String viewName) {
checkNotNull(viewName, 'viewName must not be null')

this.viewNames.add(viewName)
}

/**
* Adds views to the section. Can be called multiple times to added more views.
*/
void views(String... viewNames) {
for (String viewName : viewNames) {
view(viewName)
}
}
}
Loading