Skip to content

Commit bc324d1

Browse files
authored
Merge pull request #217 from jenkinsci/JENKINS-57312-column-types
[JENKINS-57312] Add a type configuration to columns and tokens
2 parents 7b61cd0 + 4c36230 commit bc324d1

29 files changed

Lines changed: 987 additions & 336 deletions

clean.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
JENKINS_HOME=../docker/volumes/jenkins-home
44

5-
mvn clean install || { echo "Build failed"; exit 1; }
5+
mvn clean install -Djenkins.test.timeout=1000 || { echo "Build failed"; exit 1; }
66

77
echo "Installing plugin in $JENKINS_HOME"
88
rm -rf $JENKINS_HOME/plugins/warnings-ng*

doc/Documentation.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ main build page. From there you can also dive into the details:
6161
* [Source code blames (for Git projects)](#source-code-blames-for-git-projects)
6262
* [Repository forensics (for Git projects)](#repository-forensics-for-git-projects)
6363
* [Source code view](#source-code-view)
64+
* [Issues Totals Column](#issues-totals-column)
6465
* [Dashboard view support](#dashboard-view-support)
6566
* [Configuration as code support](#configuration-as-code-support)
6667
* [Remote API](#remote-api)
@@ -577,17 +578,34 @@ This library provides syntax highlighting for the most popular languages and ren
577578

578579
![source view](images/source-view.png)
579580

581+
### Issues Totals Column
582+
583+
You can show the total number of issues of a job in separate columns of the Jenkins jobs table. By default, the Jenkins
584+
main list view will show a new column that counts the total number of issues of all tools. You can add additional columns
585+
that can configure
586+
- the column name
587+
- the actual tools that should be taken into account
588+
- the type of the totals to show (overall warnings, new warnings, specific severity, etc.).
589+
590+
![issues column](images/column.png)
591+
580592
### Dashboard view support
581593

582-
Support for Jenkins [dashboard view](https://wiki.jenkins.io/display/JENKINS/Dashboard+View) is quite limited up to now.
583-
Currently, only one portlet is available, that shows the number of issues for a job (separated by each tool). Moreover,
584-
the visualization is quite ugly, since it is more complex to use modern JS libraries on pages that are not under control
585-
of the warnings plugin.
586-
587-
The remaining portlets from the old static analysis collector plugin will be added step by step.
594+
Support for Jenkins [dashboard view](https://wiki.jenkins.io/display/JENKINS/Dashboard+View) is also available.
595+
Currently, the following portlets are available:
596+
597+
#### Issues per tool and job table
588598

599+
An issues table shows the total number of issues for a job (separated by each tool).
600+
589601
![issues portlet](images/issues-portlet.png)
590602

603+
#### Issues trend
604+
605+
A trend chart can be added as portlet that shows an aggregation of the total number of issues of all jobs.
606+
607+
![chart portlet](images/chart-portlet.png)
608+
591609
### Configuration as code support
592610

593611
The Warnings Next Generation plugin is compatible with the

doc/images/chart-portlet.png

50.4 KB
Loading

doc/images/column.png

27.7 KB
Loading

src/main/java/io/jenkins/plugins/analysis/core/columns/IssuesTotalColumn.java

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import hudson.Extension;
2020
import hudson.model.Job;
2121
import hudson.model.Run;
22+
import hudson.util.ListBoxModel;
2223
import hudson.views.ListViewColumn;
2324
import hudson.views.ListViewColumnDescriptor;
2425

@@ -27,6 +28,7 @@
2728
import io.jenkins.plugins.analysis.core.model.ResultAction;
2829
import io.jenkins.plugins.analysis.core.model.StaticAnalysisLabelProvider;
2930
import io.jenkins.plugins.analysis.core.model.ToolSelection;
31+
import io.jenkins.plugins.analysis.core.util.IssuesStatistics.StatisticProperties;
3032

3133
import static io.jenkins.plugins.analysis.core.model.ToolSelection.*;
3234

@@ -44,6 +46,7 @@ public class IssuesTotalColumn extends ListViewColumn {
4446
private String name = "# Issues";
4547

4648
private LabelProviderFactory labelProviderFactory = new LabelProviderFactory();
49+
private StatisticProperties type = StatisticProperties.TOTAL;
4750

4851
/** Creates a new instance of {@link ToolSelection}. */
4952
@DataBoundConstructor
@@ -52,7 +55,18 @@ public IssuesTotalColumn() {
5255
// empty constructor required for stapler
5356
}
5457

55-
@SuppressWarnings({"unused", "PMD.BooleanGetMethodName"}) // called by Stapler
58+
/**
59+
* Called after de-serialization to retain backward compatibility..
60+
*
61+
* @return this
62+
*/
63+
protected Object readResolve() {
64+
type = StatisticProperties.TOTAL;
65+
66+
return this;
67+
}
68+
69+
@SuppressWarnings({"unused", "PMD.BooleanGetMethodName", "WeakerAccess"}) // called by Stapler
5670
public boolean getSelectTools() {
5771
return selectTools;
5872
}
@@ -74,6 +88,19 @@ public List<ToolSelection> getTools() {
7488
return tools;
7589
}
7690

91+
/**
92+
* Returns the tools that should be taken into account when summing up the totals of a job.
93+
*
94+
* @param tools
95+
* the tools to select
96+
*
97+
* @see #setSelectTools(boolean)
98+
*/
99+
@DataBoundSetter
100+
public void setTools(final List<ToolSelection> tools) {
101+
this.tools = tools;
102+
}
103+
77104
public String getName() {
78105
return name;
79106
}
@@ -89,17 +116,19 @@ public void setName(final String name) {
89116
this.name = name;
90117
}
91118

119+
public StatisticProperties getType() {
120+
return type;
121+
}
122+
92123
/**
93-
* Returns the tools that should be taken into account when summing up the totals of a job.
94-
*
95-
* @param tools
96-
* the tools to select
124+
* Defines which value should be shown in the column.
97125
*
98-
* @see #setSelectTools(boolean)
126+
* @param type
127+
* the type of the values to show
99128
*/
100129
@DataBoundSetter
101-
public void setTools(final List<ToolSelection> tools) {
102-
this.tools = tools;
130+
public void setType(final StatisticProperties type) {
131+
this.type = type;
103132
}
104133

105134
@VisibleForTesting
@@ -129,7 +158,8 @@ public OptionalInt getTotal(final Job<?, ?> job) {
129158
return lastCompletedBuild.getActions(ResultAction.class).stream()
130159
.filter(createToolFilter(selectTools, tools))
131160
.map(ResultAction::getResult)
132-
.mapToInt(AnalysisResult::getTotalSize)
161+
.map(AnalysisResult::getTotals)
162+
.mapToInt(totals -> type.getSizeGetter().apply(totals))
133163
.reduce(Integer::sum);
134164
}
135165

@@ -200,6 +230,21 @@ public static class IssuesTablePortletDescriptor extends ListViewColumnDescripto
200230
public String getDisplayName() {
201231
return Messages.IssuesTotalColumn_Name();
202232
}
233+
234+
/**
235+
* Return the model for the select widget.
236+
*
237+
* @return the quality gate types
238+
*/
239+
public ListBoxModel doFillTypeItems() {
240+
ListBoxModel model = new ListBoxModel();
241+
242+
for (StatisticProperties qualityGateType : StatisticProperties.values()) {
243+
model.add(qualityGateType.getDisplayName(), qualityGateType.name());
244+
}
245+
246+
return model;
247+
}
203248
}
204249

205250
/**

0 commit comments

Comments
 (0)