Skip to content

Commit

Permalink
Add plot description (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahcorde authored Mar 9, 2020
1 parent fa4f431 commit e26dfc0
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/main/java/hudson/plugins/plot/MatrixPlotPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ public boolean prebuild(AbstractBuild<?, ?> build, BuildListener listener) {
for (Plot p : plots) {
Plot plot = new Plot(p.title, p.yaxis, p.group, p.numBuilds,
p.csvFileName, p.style, p.useDescr, p.getKeepRecords(),
p.getExclZero(), p.isLogarithmic(), p.yaxisMinimum, p.yaxisMaximum);
p.getExclZero(), p.isLogarithmic(), p.yaxisMinimum, p.yaxisMaximum,
p.description);
plot.series = p.series;
plot.setProject((MatrixConfiguration) build.getProject());
addPlot(plot);
Expand Down
27 changes: 24 additions & 3 deletions src/main/java/hudson/plugins/plot/Plot.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ public class Plot implements Comparable<Plot> {
@SuppressWarnings("visibilitymodifier")
public String title;

/**
* Description of plot. Optional.
*/
@SuppressWarnings("visibilitymodifier")
public String description;

/**
* Y-axis label. Optional.
*/
Expand Down Expand Up @@ -329,7 +335,7 @@ static ChartStyle forName(String name) {
public Plot(String title, String yaxis, String group, String numBuilds,
String csvFileName, String style, boolean useDescr,
boolean keepRecords, boolean exclZero, boolean logarithmic,
String yaxisMinimum, String yaxisMaximum) {
String yaxisMinimum, String yaxisMaximum, String description) {
this.title = title;
this.yaxis = yaxis;
this.group = group;
Expand All @@ -342,6 +348,7 @@ public Plot(String title, String yaxis, String group, String numBuilds,
this.logarithmic = logarithmic;
this.yaxisMinimum = yaxisMinimum;
this.yaxisMaximum = yaxisMaximum;
this.description = description;
}

/**
Expand All @@ -351,7 +358,7 @@ public Plot(String title, String yaxis, String group, String numBuilds,
public Plot(String title, String yaxis, String group, String numBuilds,
String csvFileName, String style, boolean useDescr) {
this(title, yaxis, group, numBuilds, csvFileName, style, useDescr,
false, false, false, null, null);
false, false, false, null, null, null);
}

// needed for serialization
Expand Down Expand Up @@ -420,7 +427,8 @@ public String toString() {
+ getRightBuildNum() + "),HASLEGEND(" + hasLegend()
+ "),ISLOGARITHMIC(" + isLogarithmic() + "),YAXISMINIMUM("
+ yaxisMinimum + "),YAXISMAXIMUM(" + yaxisMaximum
+ "),FILENAME(" + getCsvFileName() + ")";
+ "),FILENAME(" + getCsvFileName() + "),DESCRIPTION("
+ getDescription() + ")";
}

public String getYaxis() {
Expand Down Expand Up @@ -524,6 +532,19 @@ public String getNumBuilds() {
return numBuilds;
}

/**
* Sets the description of the plot from the "description" parameter in the
* given StaplerRequest. If the parameter doesn't exist or isn't an string
* then a default is used.
*/
private void setDescription(StaplerRequest req) {
description = req.getParameter("description");
}

public String getDescription() {
return description;
}

/**
* Sets the right-most build number shown on the plot from the
* "rightbuildnum" parameter in the given StaplerRequest. If the parameter
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/hudson/plugins/plot/PlotBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class PlotBuilder extends Builder implements SimpleBuildStep {
@CheckForNull
private String title;
@CheckForNull
private String description;
@CheckForNull
private String numBuilds;
@CheckForNull
private String yaxis;
Expand Down Expand Up @@ -173,6 +175,11 @@ public final void setYaxisMaximum(@CheckForNull String yaxisMaximum) {
this.yaxisMaximum = Util.fixEmptyAndTrim(yaxisMaximum);
}

@DataBoundSetter
public final void setDescription(@CheckForNull String description) {
this.description = Util.fixEmptyAndTrim(description);
}

public List<CSVSeries> getCsvSeries() {
return csvSeries;
}
Expand Down Expand Up @@ -206,7 +213,7 @@ public void perform(Run<?, ?> build, FilePath workspace, Launcher launcher,
List<Plot> plots = new ArrayList<>();
Plot plot = new Plot(title, yaxis, group, numBuilds, csvFileName, style,
useDescr, keepRecords, exclZero, logarithmic,
yaxisMinimum, yaxisMaximum);
yaxisMinimum, yaxisMaximum, description);

List<Series> series = new ArrayList<>();
if (csvSeries != null) {
Expand Down Expand Up @@ -294,4 +301,3 @@ public boolean configure(StaplerRequest req, JSONObject formData) throws FormExc
}
}
}

6 changes: 6 additions & 0 deletions src/main/java/hudson/plugins/plot/PlotReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ public String formatNumber(String number) {
return formatted;
}

// called from PlotReport/index.jelly
public String getPlotDescription(int i) {
Plot plot = getPlot(i);
return plot.getDescription();
}

// called from PlotReport/index.jelly
public void doGetPlot(StaplerRequest req, StaplerResponse rsp) {
String i = req.getParameter("index");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<f:entry title="${%Plot title}" help="/plugin/plot/help-title.html">
<f:textbox name="title" value="${plot.title}" />
</f:entry>
<f:entry title="${%Plot description}" help="/plugin/plot/help-description.html">
<f:textbox name="description" value="${plot.description}" />
</f:entry>
<f:entry title="${%Number of builds to include}" help="/plugin/plot/help-numbuilds.html">
<input class="positive-number" type="text" name="numBuilds"
style="width:20em" value="${plot.numBuilds}" />
Expand Down Expand Up @@ -55,7 +58,6 @@
<f:entry title="${%Y-axis maximum}" help="/plugin/plot/help-yaxisMaximum.html">
<f:textbox name="yaxisMaximum" value="${plot.yaxisMaximum}" />
</f:entry>

<f:entry title="${%Keep records for deleted builds}" help="/plugin/plot/help-keepRecords.html">
<f:checkbox name="keepRecords" checked="${plot.keepRecords}" />
</f:entry>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<f:textbox name="title" value="${plot.title}"/>
</f:entry>

<f:entry title="${%Plot description}" help="/plugin/plot/help-description.html">
<f:textbox name="description" value="${plot.description}" />
</f:entry>

<f:entry title="${%Number of builds to include}" field="numBuilds" help="/plugin/plot/help-numbuilds.html">
<input class="positive-number" type="text" name="numBuilds"
style="width:20em" value="${plot.numBuilds}"/>
Expand Down Expand Up @@ -65,7 +69,6 @@
<f:entry title="${%Y-axis maximum}" field="yaxisMaximum" help="/plugin/plot/help-yaxisMaximum.html">
<f:textbox name="yaxisMaximum" value="${plot.yaxisMaximum}"/>
</f:entry>

<f:entry title="" description="${%A new data series definition}">
<f:repeatableProperty field="csvSeries" add="Add CSV series"/>
</f:entry>
Expand Down
13 changes: 10 additions & 3 deletions src/main/resources/hudson/plugins/plot/PlotReport/index.jelly
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!--
<!--
/*
* Copyright (c) 2008-2009 Yahoo! Inc. All rights reserved.
* The copyrights to the contents of this file are licensed under the MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:c="chart">

<d:taglib uri="chart">
<d:tag name="chart">
<style>
Expand Down Expand Up @@ -51,6 +51,13 @@
</div>
</j:if>
<img src="getPlot?index=${index}&amp;width=750&amp;height=450" width="750" height="450" lazymap="getPlotMap?index=${index}" />
<div style="width:750px">
<j:if test="${it.getPlotDescription(index) != null}">
<j:if test="${!it.getPlotDescription(index).isEmpty()}">
<b>Description</b>: <j:out value="${it.getPlotDescription(index)}"/>
</j:if>
</j:if>
</div>
</div>
</d:tag>
<d:tag name="individualChart">
Expand All @@ -74,7 +81,7 @@
</j:forEach>
</select>
</div>

<j:forEach var="plot" items="${it.plots}" varStatus="loopStat2">
<c:individualChart id="${plot.csvFileName}" index="${loopStat2.index}" />
</j:forEach>
Expand Down
3 changes: 3 additions & 0 deletions src/main/webapp/help-description.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
Optional. Specifies the plot description.
</div>
4 changes: 2 additions & 2 deletions src/test/java/hudson/plugins/plot/PlotTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private MatrixProject matrixJobArchivingBuilds(int count) throws Exception {
private void plotBuilds(AbstractProject<?, ?> p, String count, boolean keepRecords) {
final PlotPublisher publisher = new PlotPublisher();
final Plot plot = new Plot("Title", "Number", "default", count, null,
"line", false, keepRecords, false, false, null, null);
"line", false, keepRecords, false, false, null, null, null);
p.getPublishersList().add(publisher);
publisher.addPlot(plot);
plot.series = Arrays.<Series>asList(new PropertiesSeries("src.properties", null));
Expand All @@ -196,7 +196,7 @@ private void plotBuilds(AbstractProject<?, ?> p, String count, boolean keepRecor
private void plotMatrixBuilds(AbstractProject<?, ?> p, String count, boolean keepRecords) {
final MatrixPlotPublisher publisher = new MatrixPlotPublisher();
final Plot plot = new Plot("Title", "Number", "default", count, null,
"line", false, keepRecords, false, false, null, null);
"line", false, keepRecords, false, false, null, null, null);
p.getPublishersList().add(publisher);
publisher.setPlots(Arrays.asList(plot));
plot.series = Arrays.<Series>asList(new PropertiesSeries("src.properties", null));
Expand Down

0 comments on commit e26dfc0

Please sign in to comment.