1
1
package io .jenkins .plugins .analysis .core .model ;
2
2
3
- import java .io .IOException ;
4
- import java .util .Optional ;
5
-
6
3
import edu .hm .hafner .echarts .BuildResult ;
7
4
import edu .hm .hafner .echarts .ChartModelConfiguration ;
8
5
import edu .hm .hafner .echarts .JacksonFacade ;
9
6
import edu .umd .cs .findbugs .annotations .CheckForNull ;
10
7
8
+ import java .io .IOException ;
9
+ import java .util .Optional ;
10
+
11
11
import org .kohsuke .stapler .StaplerRequest2 ;
12
12
import org .kohsuke .stapler .StaplerResponse2 ;
13
13
import org .kohsuke .stapler .bind .JavaScriptMethod ;
@@ -38,6 +38,7 @@ public class JobAction implements Action, AsyncConfigurableTrendChart {
38
38
private final StaticAnalysisLabelProvider labelProvider ;
39
39
private final int numberOfTools ;
40
40
private final TrendChartType trendChartType ;
41
+ private final String urlName ;
41
42
42
43
/**
43
44
* Creates a new instance of {@link JobAction}.
@@ -48,9 +49,12 @@ public class JobAction implements Action, AsyncConfigurableTrendChart {
48
49
* the label provider
49
50
* @param numberOfTools
50
51
* the number of tools that have results to show
52
+ * @deprecated
53
+ * Use {@link #JobAction(Job, StaticAnalysisLabelProvider, int, TrendChartType, String)} instead.
51
54
*/
55
+ @ Deprecated
52
56
public JobAction (final Job <?, ?> owner , final StaticAnalysisLabelProvider labelProvider , final int numberOfTools ) {
53
- this (owner , labelProvider , numberOfTools , TrendChartType .TOOLS_ONLY );
57
+ this (owner , labelProvider , numberOfTools , TrendChartType .TOOLS_ONLY , labelProvider . getId () );
54
58
}
55
59
56
60
/**
@@ -64,9 +68,32 @@ public JobAction(final Job<?, ?> owner, final StaticAnalysisLabelProvider labelP
64
68
* the number of tools that have results to show
65
69
* @param trendChartType
66
70
* determines if the trend chart will be shown
71
+ * @deprecated
72
+ * Use {@link #JobAction(Job, StaticAnalysisLabelProvider, int, TrendChartType, String)} instead.
67
73
*/
74
+ @ Deprecated
68
75
public JobAction (final Job <?, ?> owner , final StaticAnalysisLabelProvider labelProvider , final int numberOfTools ,
69
76
final TrendChartType trendChartType ) {
77
+ this (owner , labelProvider , numberOfTools , trendChartType , labelProvider .getId ());
78
+ }
79
+
80
+ /**
81
+ * Creates a new instance of {@link JobAction}.
82
+ *
83
+ * @param owner
84
+ * the job that owns this action
85
+ * @param labelProvider
86
+ * the label provider
87
+ * @param numberOfTools
88
+ * the number of tools that have results to show
89
+ * @param trendChartType
90
+ * determines if the trend chart will be shown
91
+ * @param urlName
92
+ * the custom URL name of this action
93
+ */
94
+ public JobAction (final Job <?, ?> owner , final StaticAnalysisLabelProvider labelProvider , final int numberOfTools ,
95
+ final TrendChartType trendChartType , final String urlName ) {
96
+ this .urlName = urlName ;
70
97
this .owner = owner ;
71
98
this .labelProvider = labelProvider ;
72
99
this .numberOfTools = numberOfTools ;
@@ -79,7 +106,7 @@ public JobAction(final Job<?, ?> owner, final StaticAnalysisLabelProvider labelP
79
106
* @return the ID
80
107
*/
81
108
public String getId () {
82
- return labelProvider . getId () ;
109
+ return urlName ;
83
110
}
84
111
85
112
@ Override
@@ -116,7 +143,7 @@ public History createBuildHistory() {
116
143
return new NullAnalysisHistory ();
117
144
}
118
145
else {
119
- return new AnalysisHistory (lastCompletedBuild , new ByIdResultSelector (labelProvider . getId ()));
146
+ return new AnalysisHistory (lastCompletedBuild , new ByIdResultSelector (getId ()));
120
147
}
121
148
}
122
149
@@ -129,14 +156,12 @@ public History createBuildHistory() {
129
156
@ Override
130
157
@ CheckForNull
131
158
public String getIconFileName () {
132
- return createBuildHistory ().getBaselineResult ()
133
- .map (result -> labelProvider .getSmallIconUrl ())
134
- .orElse (null );
159
+ return labelProvider .getSmallIconUrl ();
135
160
}
136
161
137
162
@ Override
138
163
public String getUrlName () {
139
- return labelProvider . getId () ;
164
+ return urlName ;
140
165
}
141
166
142
167
/**
@@ -155,7 +180,7 @@ public void doIndex(final StaplerRequest2 request, final StaplerResponse2 respon
155
180
Optional <ResultAction > action = getLatestAction ();
156
181
if (action .isPresent ()) {
157
182
response .sendRedirect2 (String .format ("../%d/%s" , action .get ().getOwner ().getNumber (),
158
- labelProvider . getId ()));
183
+ getId ()));
159
184
}
160
185
}
161
186
0 commit comments