Skip to content

Commit 0cc011e

Browse files
committed
cleanup
1 parent 8d88f75 commit 0cc011e

File tree

5 files changed

+94
-61
lines changed

5 files changed

+94
-61
lines changed

docs/Home.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Have a look at the [Jenkins Job DSL Gradle example](https://github.com/sheehan/j
1818
## Release Notes
1919
* 1.31 (unreleased)
2020
* Added support for [Pre-SCM Build Step Plugin](https://wiki.jenkins-ci.org/display/JENKINS/pre-scm-buildstep)
21+
* Added support for [Xvfb Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Xvfb+Plugin)
2122
* The enum argument of `localRepository` for the Maven job and context has changed, see [[Migration]]
2223
* 1.30 (March 08 2015)
2324
* Added support for [Custom Tools Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Custom+Tools+Plugin)

docs/Job-reference.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ freeStyleJob(String name) { // since 1.30
117117
timeout(Closure timeoutClosure = null)
118118
timestamps()
119119
toolenv(String... tools)
120-
xvfb(String installation)
120+
xvfb(String installation, Closure xvfbClosure = null) // since 1.31
121121
xvnc(boolean takeScreenshot) // deprecated
122122
xvnc(Closure xvncClosure = null) // since 1.26
123123
}
@@ -1673,23 +1673,32 @@ job('example') {
16731673
```groovy
16741674
job {
16751675
wrappers {
1676-
xvfb('xvfb') {
1677-
screen '1024x768x24' // defaults to 1024x768x24
1678-
debug(boolean debug = true) // defaults to false
1679-
timeout(int timeout) // defaults to 0
1680-
displayNameOffset(int displayNameOffset) // defaults to 1
1676+
xvfb(String xvfbInstallation) {
1677+
screen(String screen) // defaults to 1024x768x24
1678+
debug(boolean debug = true) // defaults to false
1679+
timeout(int timeout) // defaults to 0
1680+
displayNameOffset(int displayNameOffset) // defaults to 1
16811681
shutdownWithBuild(boolean shutdownWithBuild = true) // defaults to false
1682-
autoDisplayName(boolean autoDisplayName = true) // defaults to false
1683-
assignedLabels 'xvfb'
1684-
parallelBuild(boolean parallelBuild = true) // defaults to false
1682+
autoDisplayName(boolean autoDisplayName = true) // defaults to false
1683+
assignedLabels(String labels)
1684+
parallelBuild(boolean parallelBuild = true) // defaults to false
16851685
}
16861686
}
16871687
}
16881688
```
16891689

1690-
Lets you control Xvfb virtual frame buffer X11 server with each build. It starts Xvfb before the build starts, and stops
1691-
it with the build. This is very useful if your build requires X11 access, for instance runs tests that require GUI.
1692-
Requires the [Xvfb Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Xvfb+Plugin).
1690+
Controls the Xvfb virtual frame buffer X11 server. Requires the
1691+
[Xvfb Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Xvfb+Plugin).
1692+
1693+
```groovy
1694+
job {
1695+
wrappers {
1696+
xvfb('default') {
1697+
screen('1920x1080x24')
1698+
}
1699+
}
1700+
}
1701+
```
16931702

16941703
### Xvnc
16951704

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/wrapper/WrapperContext.groovy

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package javaposse.jobdsl.dsl.helpers.wrapper
22

33
import com.google.common.base.Preconditions
4-
4+
import com.google.common.base.Strings
55
import hudson.util.VersionNumber
66
import javaposse.jobdsl.dsl.Context
77
import javaposse.jobdsl.dsl.ContextHelper
@@ -310,41 +310,35 @@ class WrapperContext implements Context {
310310
}
311311

312312
/**
313-
* <pre>
314-
* {@code
315-
* <project>
316-
* <buildWrappers>
317-
* <org.jenkinsci.plugins.xvfb.XvfbBuildWrapper>
318-
* <installationName>xvfb</installationName>
319-
* <screen>1024x768x24</screen>
320-
* <debug>false</debug>
321-
* <timeout>0</timeout>
322-
* <displayNameOffset>1</displayNameOffset>
323-
* <shutdownWithBuild>false</shutdownWithBuild>
324-
* <autoDisplayName>false</autoDisplayName>
325-
* <assignedLabels>xvfb</assignedLabels>
326-
* <parallelBuild>false</parallelBuild>
327-
* </org.jenkinsci.plugins.xvfb.XvfbBuildWrapper>
328-
* </buildWrappers>
329-
* </project>
330-
* }
331-
*
332-
* Runs build under XVFB.
333-
* @param name of the Xvfb tool installation that Jenkins administrator set up
313+
* <org.jenkinsci.plugins.xvfb.XvfbBuildWrapper>
314+
* <installationName>xvfb</installationName>
315+
* <screen>1024x768x24</screen>
316+
* <debug>false</debug>
317+
* <timeout>0</timeout>
318+
* <displayNameOffset>1</displayNameOffset>
319+
* <shutdownWithBuild>false</shutdownWithBuild>
320+
* <autoDisplayName>false</autoDisplayName>
321+
* <assignedLabels>xvfb</assignedLabels>
322+
* <parallelBuild>false</parallelBuild>
323+
* </org.jenkinsci.plugins.xvfb.XvfbBuildWrapper>
334324
*/
335325
void xvfb(String installation, @DslContext(XvfbContext) Closure closure = null) {
336-
XvfbContext context = new XvfbContext(installation)
326+
Preconditions.checkArgument(!Strings.isNullOrEmpty(installation), 'installation must not be null or empty')
327+
328+
XvfbContext context = new XvfbContext()
337329
ContextHelper.executeInContext(closure, context)
338330

339331
wrapperNodes << new NodeBuilder().'org.jenkinsci.plugins.xvfb.XvfbBuildWrapper' {
340-
installationName(context.installationName)
332+
installationName(installation)
341333
screen(context.screen)
342334
debug(context.debug)
343335
timeout(context.timeout)
344336
displayNameOffset(context.displayNameOffset)
345337
shutdownWithBuild(context.shutdownWithBuild)
346338
autoDisplayName(context.autoDisplayName)
347-
assignedLabels(context.assignedLabels)
339+
if (context.assignedLabels) {
340+
assignedLabels(context.assignedLabels)
341+
}
348342
parallelBuild(context.parallelBuild)
349343
}
350344
}

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/wrapper/XvfbContext.groovy

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package javaposse.jobdsl.dsl.helpers.wrapper
33
import javaposse.jobdsl.dsl.Context
44

55
class XvfbContext implements Context {
6-
String installationName
76
String screen = '1024x768x24'
87
boolean debug = false
98
int timeout = 0
@@ -13,14 +12,6 @@ class XvfbContext implements Context {
1312
String assignedLabels
1413
boolean parallelBuild = false
1514

16-
XvfbContext(String installationName) {
17-
this.installationName = installationName
18-
}
19-
20-
void installationName(String installationName) {
21-
this.installationName = installationName
22-
}
23-
2415
void screen(String screen) {
2516
this.screen = screen
2617
}
@@ -41,7 +32,7 @@ class XvfbContext implements Context {
4132
this.shutdownWithBuild = shutdownWithBuild
4233
}
4334

44-
void autoDisplayName(boolean autoDisplayName = false) {
35+
void autoDisplayName(boolean autoDisplayName = true) {
4536
this.autoDisplayName = autoDisplayName
4637
}
4738

job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/wrapper/WrapperContextSpec.groovy

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -413,25 +413,63 @@ class WrapperContextSpec extends Specification {
413413
wrapper.takeScreenshot[0].value() == false
414414
}
415415

416-
def 'xvfb' () {
416+
def 'xvfb with minimal options'() {
417+
when:
418+
context.xvfb('default')
419+
420+
then:
421+
with(context.wrapperNodes[0]) {
422+
name() == 'org.jenkinsci.plugins.xvfb.XvfbBuildWrapper'
423+
children().size() == 8
424+
installationName[0].value() == 'default'
425+
screen[0].value() == '1024x768x24'
426+
debug[0].value() == false
427+
timeout[0].value() == 0
428+
displayNameOffset[0].value() == 1
429+
shutdownWithBuild[0].value() == false
430+
autoDisplayName[0].value() == false
431+
parallelBuild[0].value() == false
432+
}
433+
}
434+
435+
def 'xvfb with all options'() {
417436
when:
418437
context.xvfb('default') {
419-
assignedLabels 'xvfb'
438+
screen('1920x1080x32')
439+
debug()
440+
timeout(500)
441+
displayNameOffset(24)
442+
shutdownWithBuild()
443+
autoDisplayName()
444+
assignedLabels('test')
445+
parallelBuild()
420446
}
421447

422448
then:
423-
context.wrapperNodes[0].name() == 'org.jenkinsci.plugins.xvfb.XvfbBuildWrapper'
424-
def wrapper = context.wrapperNodes[0]
425-
wrapper.children().size() == 9
426-
wrapper.installationName[0].value() == 'default'
427-
wrapper.screen[0].value() == '1024x768x24'
428-
wrapper.debug[0].value() == false
429-
wrapper.timeout[0].value() == 0
430-
wrapper.displayNameOffset[0].value() == 1
431-
wrapper.shutdownWithBuild[0].value() == false
432-
wrapper.autoDisplayName[0].value() == false
433-
wrapper.assignedLabels[0].value() == 'xvfb'
434-
wrapper.parallelBuild[0].value() == false
449+
with(context.wrapperNodes[0]) {
450+
name() == 'org.jenkinsci.plugins.xvfb.XvfbBuildWrapper'
451+
children().size() == 9
452+
installationName[0].value() == 'default'
453+
screen[0].value() == '1920x1080x32'
454+
debug[0].value() == true
455+
timeout[0].value() == 500
456+
displayNameOffset[0].value() == 24
457+
shutdownWithBuild[0].value() == true
458+
autoDisplayName[0].value() == true
459+
assignedLabels[0].value() == 'test'
460+
parallelBuild[0].value() == true
461+
}
462+
}
463+
464+
def 'xvfb without installation'() {
465+
when:
466+
context.xvfb(installation)
467+
468+
then:
469+
thrown(IllegalArgumentException)
470+
471+
where:
472+
installation << [null, '']
435473
}
436474

437475
def 'toolenv' () {

0 commit comments

Comments
 (0)