1919import hudson .Extension ;
2020import hudson .model .Job ;
2121import hudson .model .Run ;
22+ import hudson .util .ListBoxModel ;
2223import hudson .views .ListViewColumn ;
2324import hudson .views .ListViewColumnDescriptor ;
2425
2728import io .jenkins .plugins .analysis .core .model .ResultAction ;
2829import io .jenkins .plugins .analysis .core .model .StaticAnalysisLabelProvider ;
2930import io .jenkins .plugins .analysis .core .model .ToolSelection ;
31+ import io .jenkins .plugins .analysis .core .util .IssuesStatistics .StatisticProperties ;
3032
3133import 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