Skip to content

Commit e1368a3

Browse files
committed
Merge branch 'plots_options'
Conflicts: docs/Home.md
2 parents 91911e2 + 3081fc3 commit e1368a3

File tree

6 files changed

+119
-14
lines changed

6 files changed

+119
-14
lines changed

docs/Home.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Have a look at the [Jenkins Job DSL Gradle example](https://github.com/sheehan/j
2121
* Added support for [Pre-SCM Build Step Plugin](https://wiki.jenkins-ci.org/display/JENKINS/pre-scm-buildstep)
2222
* Added support for [Sonar Plugin](http://docs.sonarqube.org/display/SONAR/Jenkins+Plugin)
2323
* Added support for [Debian Package Builder Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Debian+Package+Builder+Plugin)
24+
* Added support for [Plot Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Plot+Plugin)
2425
* Added `recurse` option for list views
2526
* Added `ignorePostCommitHooks` option for SCM trigger
2627
* Added `commentFilePath` option for [GitHub Pull Request Builder Plugin](https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin)
@@ -31,7 +32,6 @@ Have a look at the [Jenkins Job DSL Gradle example](https://github.com/sheehan/j
3132
* Enhanced support for the [Multijob Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Multijob+Plugin)
3233
* Enhanced support for the [NodeJS Plugin](https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin)
3334
* The enum argument of `localRepository` for the Maven job and context has changed, see [[Migration]]
34-
* Added partial support for [Plot Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Plot+Plugin)
3535
* Support for the older versions of the [Multijob Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Multijob+Plugin) is deprecated, see [[Migration]]
3636
* 1.30 (March 08 2015)
3737
* Added support for [Custom Tools Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Custom+Tools+Plugin)

docs/Job-reference.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3931,7 +3931,13 @@ job {
39313931
publishers {
39323932
plotBuildData {
39333933
plot(String group, String dataStore) {
3934-
style(String style) // defaults to 'line'
3934+
title(String title)
3935+
numberOfBuilds(int numberOfBuilds)
3936+
yAxis(String yAxis)
3937+
style(String style) // defaults to 'line'
3938+
useDescriptions(boolean useDescriptions = true) // defaults to false
3939+
excludeZero(boolean excludeZero = true) // defaults to false
3940+
keepRecords(boolean keepRecords = true) // defaults to false
39353941
propertiesFile(String fileName) {
39363942
label(String label)
39373943
}
@@ -3974,6 +3980,24 @@ job {
39743980
}
39753981
}
39763982
}
3983+
3984+
job {
3985+
publishers {
3986+
plotBuildData {
3987+
plot('Exciting plots', 'excitment.csv') {
3988+
title('X vs Y')
3989+
yAxis('Y')
3990+
numberOfBuilds(42)
3991+
useDescriptions()
3992+
keepRecords()
3993+
excludeZero()
3994+
propertiesFile('my_data.properties') {
3995+
label('Builds')
3996+
}
3997+
}
3998+
}
3999+
}
4000+
}
39774001
```
39784002
39794003
(since 1.31)

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/publisher/PlotContext.groovy

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,48 @@ class PlotContext implements Context {
1414
final String group
1515
final String dataStore
1616
final List<PlotSeriesContext> dataSeriesList = []
17+
String title
18+
String yAxis
1719
String style = 'line'
20+
Integer numberOfBuilds
21+
boolean useDescriptions
22+
boolean keepRecords
23+
boolean excludeZero
1824

1925
PlotContext(String group, String dataStore) {
2026
this.group = group
2127
this.dataStore = dataStore
2228
}
2329

30+
void title(String title) {
31+
this.title = title
32+
}
33+
34+
void yAxis(String yAxis) {
35+
this.yAxis = yAxis
36+
}
37+
2438
void style(String style) {
2539
checkArgument(STYLE.contains(style), "style must be one of ${STYLE.join(', ')}")
2640
this.style = style
2741
}
2842

43+
void numberOfBuilds(int numberOfBuilds) {
44+
this.numberOfBuilds = numberOfBuilds
45+
}
46+
47+
void useDescriptions(boolean useDescriptions = true) {
48+
this.useDescriptions = useDescriptions
49+
}
50+
51+
void keepRecords(boolean keepRecords = true) {
52+
this.keepRecords = keepRecords
53+
}
54+
55+
void excludeZero(boolean excludeZero = true) {
56+
this.excludeZero = excludeZero
57+
}
58+
2959
void propertiesFile(String fileName, Closure plotSeriesClosure = null) {
3060
checkArgument(!Strings.isNullOrEmpty(fileName), 'fileName must not be null or empty')
3161

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/publisher/PlotsContext.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import com.google.common.base.Preconditions
44
import com.google.common.base.Strings
55
import javaposse.jobdsl.dsl.ContextHelper
66
import javaposse.jobdsl.dsl.Context
7+
import javaposse.jobdsl.dsl.DslContext
78

89
class PlotsContext implements Context {
910
final List<PlotContext> plots = []
1011

11-
void plot(String group, String dataStore, Closure plotClosure) {
12+
void plot(String group, String dataStore, @DslContext(PlotContext) Closure plotClosure) {
1213
Preconditions.checkArgument(!Strings.isNullOrEmpty(group), 'group must not be null or empty')
1314
Preconditions.checkArgument(!Strings.isNullOrEmpty(dataStore), 'dataStore must not be null or empty')
1415

job-dsl-core/src/main/groovy/javaposse/jobdsl/dsl/helpers/publisher/PublisherContext.groovy

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,20 +357,23 @@ class PublisherContext implements Context {
357357
* <useDescr>false</useDescr>
358358
* <keepRecords>false</keepRecords>
359359
* <exclZero>false</exclZero>
360+
* <logarithmic>false</logarithmic>
360361
* </hudson.plugins.plot.Plot>
361362
* </plots>
362363
* </hudson.plugins.plot.PlotPublisher>
363364
*/
364-
void plotBuildData(Closure plotsClosure) {
365+
void plotBuildData(@DslContext(PlotsContext) Closure plotsClosure) {
366+
jobManagement.requireMinimumPluginVersion('plot', '1.9')
367+
365368
PlotsContext plotsContext = new PlotsContext()
366369
ContextHelper.executeInContext(plotsClosure, plotsContext)
367370

368371
publisherNodes << NodeBuilder.newInstance().'hudson.plugins.plot.PlotPublisher' {
369372
plots {
370373
plotsContext.plots.each { PlotContext plot ->
371374
'hudson.plugins.plot.Plot' {
372-
title()
373-
yaxis()
375+
title(plot.title ?: '')
376+
yaxis(plot.yAxis ?: '')
374377
series {
375378
plot.dataSeriesList.each { PlotSeriesContext data ->
376379
'hudson.plugins.plot.PropertiesSeries' {
@@ -381,13 +384,14 @@ class PublisherContext implements Context {
381384
}
382385
}
383386
group(plot.group)
384-
numBuilds()
387+
numBuilds(plot.numberOfBuilds ?: '')
385388
csvFileName(plot.dataStore)
386389
csvLastModification(0)
387390
style(plot.style)
388-
usrDescr(false)
389-
keepRecords(false)
390-
exclZero(false)
391+
useDescr(plot.useDescriptions)
392+
keepRecords(plot.keepRecords)
393+
exclZero(plot.excludeZero)
394+
logarithmic(false)
391395
}
392396
}
393397
}

job-dsl-core/src/test/groovy/javaposse/jobdsl/dsl/helpers/publisher/PublisherContextSpec.groovy

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3094,17 +3094,18 @@ class PublisherContextSpec extends Specification {
30943094
name() == 'hudson.plugins.plot.PlotPublisher'
30953095
children().size() == 1
30963096
with(plots.'hudson.plugins.plot.Plot'[0]) {
3097-
children().size() == 11
3097+
children().size() == 12
30983098
title[0].value().empty
30993099
yaxis[0].value().empty
31003100
group[0].value() == 'my group'
31013101
numBuilds[0].value().empty
31023102
csvFileName[0].value() == 'some.csv'
31033103
csvLastModification[0].value() == 0
31043104
style[0].value() == 'line'
3105-
usrDescr[0].value() == false
3105+
useDescr[0].value() == false
31063106
keepRecords[0].value() == false
31073107
exclZero[0].value() == false
3108+
logarithmic[0].value() == false
31083109
with(series[0].'hudson.plugins.plot.PropertiesSeries'[0]) {
31093110
children().size() == 3
31103111
file[0].value() == 'data.prop'
@@ -3113,6 +3114,49 @@ class PublisherContextSpec extends Specification {
31133114
}
31143115
}
31153116
}
3117+
_ * jobManagement.requireMinimumPluginVersion('plot', '1.9')
3118+
}
3119+
3120+
def 'call plotPlugin with all args'() {
3121+
when:
3122+
context.plotBuildData {
3123+
plot('my group', 'some.csv') {
3124+
title('plot title')
3125+
yAxis('yaxis title')
3126+
numberOfBuilds(42)
3127+
useDescriptions()
3128+
keepRecords()
3129+
excludeZero()
3130+
propertiesFile('data.prop')
3131+
}
3132+
}
3133+
3134+
then:
3135+
with(context.publisherNodes[0]) {
3136+
name() == 'hudson.plugins.plot.PlotPublisher'
3137+
children().size() == 1
3138+
with(plots.'hudson.plugins.plot.Plot'[0]) {
3139+
children().size() == 12
3140+
title[0].value() == 'plot title'
3141+
yaxis[0].value() == 'yaxis title'
3142+
group[0].value() == 'my group'
3143+
numBuilds[0].value() == 42
3144+
csvFileName[0].value() == 'some.csv'
3145+
csvLastModification[0].value() == 0
3146+
style[0].value() == 'line'
3147+
useDescr[0].value() == true
3148+
keepRecords[0].value() == true
3149+
exclZero[0].value() == true
3150+
logarithmic[0].value() == false
3151+
with(series[0].'hudson.plugins.plot.PropertiesSeries'[0]) {
3152+
children().size() == 3
3153+
file[0].value() == 'data.prop'
3154+
label[0].value() == ''
3155+
fileType[0].value() == 'properties'
3156+
}
3157+
}
3158+
}
3159+
_ * jobManagement.requireMinimumPluginVersion('plot', '1.9')
31163160
}
31173161

31183162
def 'call plotPlugin with all chart styles'() {
@@ -3131,17 +3175,18 @@ class PublisherContextSpec extends Specification {
31313175
name() == 'hudson.plugins.plot.PlotPublisher'
31323176
children().size() == 1
31333177
with(plots.'hudson.plugins.plot.Plot'[0]) {
3134-
children().size() == 11
3178+
children().size() == 12
31353179
title[0].value().empty
31363180
yaxis[0].value().empty
31373181
group[0].value() == 'my group'
31383182
numBuilds[0].value().empty
31393183
csvFileName[0].value() == 'some.csv'
31403184
csvLastModification[0].value() == 0
31413185
style[0].value() == chart
3142-
usrDescr[0].value() == false
3186+
useDescr[0].value() == false
31433187
keepRecords[0].value() == false
31443188
exclZero[0].value() == false
3189+
logarithmic[0].value() == false
31453190
with(series[0].'hudson.plugins.plot.PropertiesSeries'[0]) {
31463191
children().size() == 3
31473192
file[0].value() == 'data.prop'
@@ -3150,6 +3195,7 @@ class PublisherContextSpec extends Specification {
31503195
}
31513196
}
31523197
}
3198+
_ * jobManagement.requireMinimumPluginVersion('plot', '1.9')
31533199

31543200
where:
31553201
chart << ['area', 'bar', 'bar3d', 'line', 'line3d', 'stackedArea', 'stackedbar', 'stackedbar3d', 'waterfall']

0 commit comments

Comments
 (0)