-
-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathPlotBuilder.java
More file actions
382 lines (318 loc) · 10.2 KB
/
PlotBuilder.java
File metadata and controls
382 lines (318 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
package hudson.plugins.plot;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Util;
import hudson.model.AbstractProject;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.util.FormValidation;
import jakarta.servlet.ServletException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import jenkins.tasks.SimpleBuildStep;
import net.sf.json.JSONObject;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest2;
/**
* Plot {@link Builder} class for pipeline.
* <p>
* When the user configures the project and enables this builder,
* {@link DescriptorImpl#newInstance(StaplerRequest2, JSONObject)} is invoked
* and a new {@link PlotBuilder} is created.
* The created instance is persisted to the project configuration XML by using XStream,
* so this allows you to use instance fields (like {@link #group}) to remember the configuration.
* <p>
* When a build is performed, the {@link #perform} method will be invoked.
*/
public class PlotBuilder extends Builder implements SimpleBuildStep {
// Required fields
private final String group;
private final String style;
// Optional fields
@CheckForNull
private String title;
@CheckForNull
private String description;
@CheckForNull
private String numBuilds;
@CheckForNull
private String yaxis;
@CheckForNull
private String yaxisMinimum;
@CheckForNull
private String yaxisMaximum;
private boolean useDescr;
private boolean exclZero;
private boolean logarithmic;
private boolean keepRecords;
@CheckForNull
private String chartWidth;
@CheckForNull
private String chartHeight;
private boolean skipZeroValues;
private boolean useDecimalFormat;
// Generated?
@SuppressWarnings("visibilitymodifier")
public String csvFileName;
/**
* List of data series.
*/
@SuppressWarnings("visibilitymodifier")
public List<CSVSeries> csvSeries;
@SuppressWarnings("visibilitymodifier")
public List<PropertiesSeries> propertiesSeries;
@SuppressWarnings("visibilitymodifier")
public List<XMLSeries> xmlSeries;
// Fields in config.jelly must match the parameter names in the "DataBoundConstructor"
// Similarly, any optional @DataBoundSetter properties must match
@DataBoundConstructor
public PlotBuilder(String group, String style, String csvFileName) {
this.group = group;
this.style = style;
this.csvFileName = csvFileName;
}
public String getGroup() {
return group;
}
public String getStyle() {
return style;
}
@CheckForNull
public String getTitle() {
return title;
}
@DataBoundSetter
public final void setTitle(@CheckForNull String title) {
this.title = Util.fixEmptyAndTrim(title);
}
@CheckForNull
public String getNumBuilds() {
return numBuilds;
}
@DataBoundSetter
public final void setNumBuilds(@CheckForNull String numBuilds) {
this.numBuilds = Util.fixEmptyAndTrim(numBuilds);
}
@CheckForNull
public String getYaxis() {
return yaxis;
}
@DataBoundSetter
public final void setYaxis(@CheckForNull String yaxis) {
this.yaxis = Util.fixEmptyAndTrim(yaxis);
}
public boolean getUseDescr() {
return useDescr;
}
@DataBoundSetter
public void setUseDescr(boolean useDescr) {
this.useDescr = useDescr;
}
public boolean getExclZero() {
return exclZero;
}
@DataBoundSetter
public void setExclZero(boolean exclZero) {
this.exclZero = exclZero;
}
public boolean getLogarithmic() {
return logarithmic;
}
@DataBoundSetter
public void setLogarithmic(boolean logarithmic) {
this.logarithmic = logarithmic;
}
public boolean getKeepRecords() {
return keepRecords;
}
@DataBoundSetter
public void setKeepRecords(boolean keepRecords) {
this.keepRecords = keepRecords;
}
@CheckForNull
public String getYaxisMinimum() {
return yaxisMinimum;
}
@DataBoundSetter
public final void setYaxisMinimum(@CheckForNull String yaxisMinimum) {
this.yaxisMinimum = Util.fixEmptyAndTrim(yaxisMinimum);
}
@CheckForNull
public String getYaxisMaximum() {
return yaxisMaximum;
}
@DataBoundSetter
public final void setYaxisMaximum(@CheckForNull String yaxisMaximum) {
this.yaxisMaximum = Util.fixEmptyAndTrim(yaxisMaximum);
}
@CheckForNull
public String getDescription() {
return description;
}
@DataBoundSetter
public final void setDescription(@CheckForNull String description) {
this.description = Util.fixEmptyAndTrim(description);
}
@CheckForNull
public String getChartWidth() {
return chartWidth;
}
@DataBoundSetter
public final void setChartWidth(@CheckForNull String chartWidth) {
this.chartWidth = Util.fixEmptyAndTrim(chartWidth);
}
@CheckForNull
public String getChartHeight() {
return chartHeight;
}
@DataBoundSetter
public final void setChartHeight(@CheckForNull String chartHeight) {
this.chartHeight = Util.fixEmptyAndTrim(chartHeight);
}
public boolean getSkipZeroValues() {
return skipZeroValues;
}
@DataBoundSetter
public void setSkipZeroValues(boolean skipZeroValues) {
this.skipZeroValues = skipZeroValues;
}
public boolean getUseDecimalFormat() {
return useDecimalFormat;
}
@DataBoundSetter
public void setUseDecimalFormat(boolean useDecimalFormat) {
this.useDecimalFormat = useDecimalFormat;
}
public List<CSVSeries> getCsvSeries() {
return csvSeries;
}
@DataBoundSetter
public void setCsvSeries(List<CSVSeries> csvSeries) {
this.csvSeries = csvSeries;
}
public List<PropertiesSeries> getPropertiesSeries() {
return propertiesSeries;
}
@DataBoundSetter
public void setPropertiesSeries(List<PropertiesSeries> propertiesSeries) {
this.propertiesSeries = propertiesSeries;
}
public List<XMLSeries> getXmlSeries() {
return xmlSeries;
}
@DataBoundSetter
public void setXmlSeries(List<XMLSeries> xmlSeries) {
this.xmlSeries = xmlSeries;
}
@Override
public void perform(
@NonNull Run<?, ?> build,
@NonNull FilePath workspace,
@NonNull Launcher launcher,
@NonNull TaskListener listener) {
List<Plot> plots = new ArrayList<>();
Plot plot = new Plot(
title,
yaxis,
group,
numBuilds,
csvFileName,
style,
useDescr,
keepRecords,
exclZero,
logarithmic,
yaxisMinimum,
yaxisMaximum,
description,
chartWidth,
chartHeight,
skipZeroValues,
useDecimalFormat);
List<Series> series = new ArrayList<>();
if (csvSeries != null) {
series.addAll(csvSeries);
}
if (xmlSeries != null) {
series.addAll(xmlSeries);
}
if (propertiesSeries != null) {
series.addAll(propertiesSeries);
}
plot.series = series;
plot.addBuild(build, listener.getLogger(), workspace);
plots.add(plot);
PlotBuildAction buildAction = build.getAction(PlotBuildAction.class);
if (buildAction == null) {
build.addAction(new PlotBuildAction(build, plots));
} else {
buildAction.addPlots(plots);
}
}
// Overridden for better type safety.
// If your plugin doesn't really define any property on Descriptor, you don't have to do this.
@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
}
/**
* Descriptor for {@link PlotBuilder}. Used as a singleton.
* The class is marked as public so that it can be accessed from views.
*/
@Extension // This indicates to Jenkins that this is an implementation of an extension point.
@Symbol("plot")
public static final class DescriptorImpl extends BuildStepDescriptor<Builder> {
/*
* To persist global configuration information,
* simply store it in a field and call save().
*
* <p>
* If you don't want fields to be persisted, use <tt>transient</tt>.
*/
/**
* In order to load the persisted global configuration, you have to
* call load() in the constructor.
*/
public DescriptorImpl() {
load();
}
public String getCsvFileName() {
return "plot-" + UUID.randomUUID() + ".csv";
}
public FormValidation doCheckName(@QueryParameter String value) throws IOException, ServletException {
if (value == null || value.isEmpty()) {
return FormValidation.error("Please set a group");
}
if (value.length() < 4) {
return FormValidation.warning("Isn't the group too short?");
}
return FormValidation.ok();
}
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
// Indicates that this builder can be used with all kinds of project types
return true;
}
/**
* This human readable group is used in the configuration screen.
*/
@NonNull
public String getDisplayName() {
return Messages.Plot_Publisher_DisplayName();
}
@Override
public boolean configure(StaplerRequest2 req, JSONObject formData) throws FormException {
save();
return super.configure(req, formData);
}
}
}