Skip to content

Commit f157df0

Browse files
committed
Merge branch 'plot_xml'
2 parents 60e887f + 3ef1af9 commit f157df0

File tree

6 files changed

+152
-5
lines changed

6 files changed

+152
-5
lines changed

docs/Job-reference.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3943,6 +3943,11 @@ job {
39433943
propertiesFile(String fileName) {
39443944
label(String label)
39453945
}
3946+
xmlFile(String fileName) {
3947+
nodeType(String nodeType) // defaults to 'NODESET'
3948+
url(String url)
3949+
xpath(String xpath)
3950+
}
39463951
}
39473952
}
39483953
}
@@ -3959,6 +3964,8 @@ the workspace root. To avoid conflicts this location needs to be set manually re
39593964
The `style` option can be one of `'area'`, `'bar'`, `'bar3d'`, `'line'` (default), `'line3d'`, `'stackedArea'`,
39603965
`'stackedbar'`, `'stackedbar3d'` or `'waterfall'`.
39613966
3967+
The `nodeType` option can be one of `'NODESET'`, `'NODE'`, `'STRING'`, `'BOOLEAN'`, `'NUMBER'`.
3968+
39623969
```groovy
39633970
job {
39643971
publishers {

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package javaposse.jobdsl.dsl.helpers.publisher
33
import com.google.common.base.Strings
44
import javaposse.jobdsl.dsl.ContextHelper
55
import javaposse.jobdsl.dsl.Context
6+
import javaposse.jobdsl.dsl.DslContext
67

78
import static com.google.common.base.Preconditions.checkArgument
89

@@ -61,10 +62,19 @@ class PlotContext implements Context {
6162
this.logarithmic = logarithmic
6263
}
6364

64-
void propertiesFile(String fileName, Closure plotSeriesClosure = null) {
65+
void propertiesFile(String fileName, @DslContext(PlotSeriesContext) Closure plotSeriesClosure = null) {
6566
checkArgument(!Strings.isNullOrEmpty(fileName), 'fileName must not be null or empty')
6667

67-
PlotSeriesContext plotSeriesContext = new PlotSeriesContext(fileName)
68+
PlotSeriesContext plotSeriesContext = new PlotSeriesContext(fileName, 'properties', 'PropertiesSeries')
69+
ContextHelper.executeInContext(plotSeriesClosure, plotSeriesContext)
70+
71+
dataSeriesList << plotSeriesContext
72+
}
73+
74+
void xmlFile(String fileName, @DslContext(PlotXMLSeriesContext) Closure plotSeriesClosure = null) {
75+
checkArgument(!Strings.isNullOrEmpty(fileName), 'fileName must not be null or empty')
76+
77+
PlotSeriesContext plotSeriesContext = new PlotXMLSeriesContext(fileName)
6878
ContextHelper.executeInContext(plotSeriesClosure, plotSeriesContext)
6979

7080
dataSeriesList << plotSeriesContext

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import javaposse.jobdsl.dsl.Context
44

55
class PlotSeriesContext implements Context {
66
final String fileName
7+
final String fileType
8+
final String seriesType
79
String label
810

9-
PlotSeriesContext(String fileName) {
11+
PlotSeriesContext(String fileName, String fileType, String seriesType) {
1012
this.fileName = fileName
13+
this.fileType = fileType
14+
this.seriesType = seriesType
1115
}
1216

1317
void label(String label) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package javaposse.jobdsl.dsl.helpers.publisher
2+
3+
import static com.google.common.base.Preconditions.checkArgument
4+
5+
class PlotXMLSeriesContext extends PlotSeriesContext {
6+
private static final List<String> NODE_TYPES = [
7+
'NODESET', 'NODE', 'STRING', 'BOOLEAN', 'NUMBER'
8+
]
9+
10+
String nodeType = 'NODESET'
11+
String url
12+
String xpath
13+
14+
PlotXMLSeriesContext(String fileName) {
15+
super(fileName, 'xml', 'XMLSeries')
16+
}
17+
18+
void nodeType(String nodeType) {
19+
checkArgument(NODE_TYPES.contains(nodeType), "nodeType must be one of ${NODE_TYPES.join(', ')}")
20+
this.nodeType = nodeType
21+
}
22+
23+
void url(String url) {
24+
this.url = url
25+
}
26+
27+
void xpath(String xpath) {
28+
this.xpath = xpath
29+
}
30+
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,14 @@ class PublisherContext implements Context {
348348
* <label>test</label>
349349
* <fileType>properties</fileType>
350350
* </hudson.plugins.plot.PropertiesSeries>
351+
* <hudson.plugins.plot.XMLSeries>
352+
* <file>XML</file>
353+
* <label></label>
354+
* <fileType>xml</fileType>
355+
* <xpathString></xpathString>
356+
* <url></url>
357+
* <nodeTypeString>NODESET</nodeTypeString>
358+
* </hudson.plugins.plot.XMLSeries>
351359
* </series>
352360
* <group>test</group>
353361
* <numBuilds/>
@@ -376,10 +384,15 @@ class PublisherContext implements Context {
376384
yaxis(plot.yAxis ?: '')
377385
series {
378386
plot.dataSeriesList.each { PlotSeriesContext data ->
379-
'hudson.plugins.plot.PropertiesSeries' {
387+
"hudson.plugins.plot.${data.seriesType}" {
380388
file(data.fileName)
381389
label(data.label ?: '')
382-
fileType('properties')
390+
fileType(data.fileType)
391+
if (data instanceof PlotXMLSeriesContext) {
392+
xpathString(data.xpath ?: '')
393+
url(data.url ?: '')
394+
nodeTypeString(data.nodeType)
395+
}
383396
}
384397
}
385398
}

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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,6 +3202,89 @@ class PublisherContextSpec extends Specification {
32023202
chart << ['area', 'bar', 'bar3d', 'line', 'line3d', 'stackedArea', 'stackedbar', 'stackedbar3d', 'waterfall']
32033203
}
32043204

3205+
def 'call plotPlugin with a xml series'() {
3206+
when:
3207+
context.plotBuildData {
3208+
plot('my group', 'some.csv') {
3209+
xmlFile('data.prop')
3210+
}
3211+
}
3212+
3213+
then:
3214+
with(context.publisherNodes[0]) {
3215+
name() == 'hudson.plugins.plot.PlotPublisher'
3216+
children().size() == 1
3217+
with(plots.'hudson.plugins.plot.Plot'[0]) {
3218+
children().size() == 12
3219+
title[0].value().empty
3220+
yaxis[0].value().empty
3221+
group[0].value() == 'my group'
3222+
numBuilds[0].value().empty
3223+
csvFileName[0].value() == 'some.csv'
3224+
csvLastModification[0].value() == 0
3225+
style[0].value() == 'line'
3226+
useDescr[0].value() == false
3227+
keepRecords[0].value() == false
3228+
exclZero[0].value() == false
3229+
logarithmic[0].value() == false
3230+
with(series[0].'hudson.plugins.plot.XMLSeries'[0]) {
3231+
children().size() == 6
3232+
file[0].value() == 'data.prop'
3233+
label[0].value() == ''
3234+
fileType[0].value() == 'xml'
3235+
nodeTypeString[0].value() == 'NODESET'
3236+
url[0].value() == ''
3237+
xpathString[0].value() == ''
3238+
}
3239+
}
3240+
}
3241+
_ * jobManagement.requireMinimumPluginVersion('plot', '1.9')
3242+
}
3243+
3244+
def 'call plotPlugin with full xml series'() {
3245+
when:
3246+
context.plotBuildData {
3247+
plot('my group', 'some.csv') {
3248+
xmlFile('data.prop') {
3249+
label('some label')
3250+
nodeType('NODE')
3251+
url('http://somewhere')
3252+
xpath('an xpath string')
3253+
}
3254+
}
3255+
}
3256+
3257+
then:
3258+
with(context.publisherNodes[0]) {
3259+
name() == 'hudson.plugins.plot.PlotPublisher'
3260+
children().size() == 1
3261+
with(plots.'hudson.plugins.plot.Plot'[0]) {
3262+
children().size() == 12
3263+
title[0].value().empty
3264+
yaxis[0].value().empty
3265+
group[0].value() == 'my group'
3266+
numBuilds[0].value().empty
3267+
csvFileName[0].value() == 'some.csv'
3268+
csvLastModification[0].value() == 0
3269+
style[0].value() == 'line'
3270+
useDescr[0].value() == false
3271+
keepRecords[0].value() == false
3272+
exclZero[0].value() == false
3273+
logarithmic[0].value() == false
3274+
with(series[0].'hudson.plugins.plot.XMLSeries'[0]) {
3275+
children().size() == 6
3276+
file[0].value() == 'data.prop'
3277+
label[0].value() == 'some label'
3278+
fileType[0].value() == 'xml'
3279+
nodeTypeString[0].value() == 'NODE'
3280+
url[0].value() == 'http://somewhere'
3281+
xpathString[0].value() == 'an xpath string'
3282+
}
3283+
}
3284+
}
3285+
_ * jobManagement.requireMinimumPluginVersion('plot', '1.9')
3286+
}
3287+
32053288
def 'call plotPlugin without group'() {
32063289
when:
32073290
context.plotBuildData {

0 commit comments

Comments
 (0)