Skip to content

Commit 433a2d8

Browse files
uhafnertimja
andauthored
Upgrade trends and detail views to Bootstrap 5 (#272)
Co-authored-by: Tim Jacomb <[email protected]> Co-authored-by: Tim Jacomb <[email protected]>
1 parent 86b06fd commit 433a2d8

File tree

13 files changed

+216
-158
lines changed

13 files changed

+216
-158
lines changed

pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<dependency>
4848
<groupId>io.jenkins.plugins</groupId>
4949
<artifactId>echarts-api</artifactId>
50+
<version>5.3.2-1</version>
5051
</dependency>
5152
<dependency>
5253
<groupId>io.jenkins.plugins</groupId>
@@ -74,7 +75,8 @@
7475
</dependency>
7576
<dependency>
7677
<groupId>io.jenkins.plugins</groupId>
77-
<artifactId>bootstrap4-api</artifactId>
78+
<artifactId>bootstrap5-api</artifactId>
79+
<version>5.1.3-6</version>
7880
</dependency>
7981
<dependency>
8082
<groupId>org.jenkins-ci.plugins.workflow</groupId>

src/main/java/hudson/tasks/junit/History.java

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,24 @@
2323
*/
2424
package hudson.tasks.junit;
2525

26+
import java.util.List;
27+
import java.util.Objects;
28+
import java.util.stream.Collectors;
29+
2630
import edu.hm.hafner.echarts.ChartModelConfiguration;
2731
import edu.hm.hafner.echarts.JacksonFacade;
2832
import edu.hm.hafner.echarts.LinesChartModel;
33+
34+
import org.kohsuke.accmod.Restricted;
35+
import org.kohsuke.accmod.restrictions.NoExternalUse;
36+
import org.kohsuke.stapler.bind.JavaScriptMethod;
2937
import hudson.tasks.test.TestObject;
3038
import hudson.tasks.test.TestObjectIterable;
3139
import hudson.tasks.test.TestResultDurationChart;
3240
import hudson.tasks.test.TestResultTrendChart;
3341
import hudson.util.RunList;
34-
import io.jenkins.plugins.junit.storage.TestResultImpl;
35-
import org.kohsuke.accmod.Restricted;
36-
import org.kohsuke.accmod.restrictions.NoExternalUse;
37-
import org.kohsuke.stapler.bind.JavaScriptMethod;
3842

39-
import java.util.List;
40-
import java.util.Objects;
41-
import java.util.stream.Collectors;
43+
import io.jenkins.plugins.junit.storage.TestResultImpl;
4244

4345
/**
4446
* History of {@link hudson.tasks.test.TestObject} over time.
@@ -48,6 +50,7 @@
4850
@Restricted(NoExternalUse.class)
4951
public class History {
5052
private static final JacksonFacade JACKSON_FACADE = new JacksonFacade();
53+
private static final String EMPTY_CONFIGURATION = "{}";
5154
private final TestObject testObject;
5255

5356
public History(TestObject testObject) {
@@ -73,33 +76,37 @@ public boolean historyAvailable() {
7376

7477
@JavaScriptMethod
7578
@SuppressWarnings("unused") // Called by jelly view
76-
public String getTestResultTrend() {
77-
return JACKSON_FACADE.toJson(createTestResultTrend());
79+
public String getTestResultTrend(String configuration) {
80+
return JACKSON_FACADE.toJson(createTestResultTrend(ChartModelConfiguration.fromJson(configuration)));
7881
}
7982

80-
private LinesChartModel createTestResultTrend() {
83+
private LinesChartModel createTestResultTrend(ChartModelConfiguration chartModelConfiguration) {
8184
TestResultImpl pluggableStorage = getPluggableStorage();
8285
if (pluggableStorage != null) {
8386
return new TestResultTrendChart().create(pluggableStorage.getTrendTestResultSummary());
8487
}
8588

86-
return new TestResultTrendChart().createFromTestObject(createBuildHistory(testObject), new ChartModelConfiguration());
89+
return new TestResultTrendChart().createFromTestObject(createBuildHistory(testObject), chartModelConfiguration);
8790
}
8891

8992
@JavaScriptMethod
9093
@SuppressWarnings("unused") // Called by jelly view
91-
public String getTestDurationTrend() {
92-
return JACKSON_FACADE.toJson(createTestDurationResultTrend());
94+
public String getTestDurationTrend(String configuration) {
95+
return JACKSON_FACADE.toJson(createTestDurationResultTrend(ChartModelConfiguration.fromJson(configuration)));
9396
}
9497

95-
private LinesChartModel createTestDurationResultTrend() {
98+
private LinesChartModel createTestDurationResultTrend(ChartModelConfiguration chartModelConfiguration) {
9699
TestResultImpl pluggableStorage = getPluggableStorage();
97100

98101
if (pluggableStorage != null) {
99102
return new TestResultDurationChart().create(pluggableStorage.getTestDurationResultSummary());
100103
}
101104

102-
return new TestResultDurationChart().create(createBuildHistory(testObject), new ChartModelConfiguration());
105+
return new TestResultDurationChart().create(createBuildHistory(testObject), chartModelConfiguration);
106+
}
107+
108+
private TestObjectIterable createBuildHistory(final TestObject testObject) {
109+
return new TestObjectIterable(testObject);
103110
}
104111

105112
private TestResultImpl getPluggableStorage() {
@@ -171,10 +178,6 @@ private List<HistoryTestResultSummary> getHistoryFromFileStorage() {
171178
.collect(Collectors.toList());
172179
}
173180

174-
private TestObjectIterable createBuildHistory(TestObject testObject) {
175-
return new TestObjectIterable(testObject);
176-
}
177-
178181
@SuppressWarnings("unused") // Called by jelly view
179182
public static int asInt(String s, int defaultValue) {
180183
if (s == null) return defaultValue;

src/main/java/hudson/tasks/test/TestResultDurationChart.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
import static hudson.tasks.test.TestDurationTrendSeriesBuilder.SECONDS;
1212

1313
public class TestResultDurationChart {
14-
14+
1515
public LinesChartModel create(List<TestDurationResultSummary> results) {
1616
LinesDataSet dataset = new LinesDataSet();
1717
results.forEach(result -> dataset.add(result.getDisplayName(), result.toMap(), result.getBuildNumber()));
18-
18+
1919
return getLinesChartModel(dataset);
2020
}
2121

@@ -28,15 +28,13 @@ public LinesChartModel create(final Iterable results,
2828
}
2929

3030
private LinesChartModel getLinesChartModel(LinesDataSet dataSet) {
31-
LinesChartModel model = new LinesChartModel();
32-
model.setDomainAxisLabels(dataSet.getDomainAxisLabels());
33-
model.setBuildNumbers(dataSet.getBuildNumbers());
31+
LinesChartModel model = new LinesChartModel(dataSet);
3432

3533
LineSeries duration = new LineSeries(SECONDS, Palette.GREEN.getNormal(),
3634
LineSeries.StackedMode.STACKED, LineSeries.FilledMode.FILLED);
3735
duration.addAll(dataSet.getSeries(SECONDS));
3836
model.addSeries(duration);
39-
37+
4038
return model;
4139
}
4240
}

src/main/java/hudson/tasks/test/TestResultProjectAction.java

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/*
22
* The MIT License
3-
*
3+
*
44
* Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
5-
*
5+
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
88
* in the Software without restriction, including without limitation the rights
99
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1010
* copies of the Software, and to permit persons to whom the Software is
1111
* furnished to do so, subject to the following conditions:
12-
*
12+
*
1313
* The above copyright notice and this permission notice shall be included in
1414
* all copies or substantial portions of the Software.
15-
*
15+
*
1616
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1717
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1818
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -23,29 +23,32 @@
2323
*/
2424
package hudson.tasks.test;
2525

26+
import java.io.IOException;
27+
import java.util.List;
28+
import javax.servlet.ServletException;
29+
import javax.servlet.http.Cookie;
30+
import javax.servlet.http.HttpServletResponse;
31+
2632
import edu.hm.hafner.echarts.ChartModelConfiguration;
2733
import edu.hm.hafner.echarts.JacksonFacade;
2834
import edu.hm.hafner.echarts.LinesChartModel;
2935
import edu.umd.cs.findbugs.annotations.CheckForNull;
36+
37+
import org.kohsuke.stapler.Ancestor;
38+
import org.kohsuke.stapler.StaplerRequest;
39+
import org.kohsuke.stapler.StaplerResponse;
40+
import org.kohsuke.stapler.bind.JavaScriptMethod;
3041
import hudson.model.AbstractProject;
3142
import hudson.model.Action;
3243
import hudson.model.Job;
3344
import hudson.model.Run;
3445
import hudson.tasks.junit.JUnitResultArchiver;
46+
47+
import io.jenkins.plugins.echarts.AsyncConfigurableTrendChart;
48+
import io.jenkins.plugins.echarts.AsyncTrendChart;
3549
import io.jenkins.plugins.junit.storage.FileJunitTestResultStorage;
36-
import io.jenkins.plugins.junit.storage.TestResultImpl;
3750
import io.jenkins.plugins.junit.storage.JunitTestResultStorage;
38-
import io.jenkins.plugins.echarts.AsyncTrendChart;
39-
import org.kohsuke.stapler.Ancestor;
40-
import org.kohsuke.stapler.StaplerRequest;
41-
import org.kohsuke.stapler.StaplerResponse;
42-
43-
import javax.servlet.ServletException;
44-
import javax.servlet.http.Cookie;
45-
import javax.servlet.http.HttpServletResponse;
46-
import java.io.IOException;
47-
import java.util.List;
48-
import org.kohsuke.stapler.bind.JavaScriptMethod;
51+
import io.jenkins.plugins.junit.storage.TestResultImpl;
4952

5053
/**
5154
* Project action object from test reporter, such as {@link JUnitResultArchiver},
@@ -56,7 +59,7 @@
5659
*
5760
* @author Kohsuke Kawaguchi
5861
*/
59-
public class TestResultProjectAction implements Action, AsyncTrendChart {
62+
public class TestResultProjectAction implements Action, AsyncTrendChart, AsyncConfigurableTrendChart {
6063
/**
6164
* Project that owns this action.
6265
* @since 1.2-beta-1
@@ -69,13 +72,13 @@ public class TestResultProjectAction implements Action, AsyncTrendChart {
6972
/**
7073
* @since 1.2-beta-1
7174
*/
72-
public TestResultProjectAction(Job<?,?> job) {
75+
public TestResultProjectAction(final Job<?,?> job) {
7376
this.job = job;
7477
project = job instanceof AbstractProject ? (AbstractProject) job : null;
7578
}
7679

7780
@Deprecated
78-
public TestResultProjectAction(AbstractProject<?,?> project) {
81+
public TestResultProjectAction(final AbstractProject<?,?> project) {
7982
this((Job) project);
8083
}
8184

@@ -114,7 +117,12 @@ public AbstractTestResultAction getLastTestResultAction() {
114117
return null;
115118
}
116119

120+
@Deprecated
117121
protected LinesChartModel createChartModel() {
122+
return createChartModel(new ChartModelConfiguration());
123+
}
124+
125+
private LinesChartModel createChartModel(final ChartModelConfiguration configuration) {
118126
Run<?, ?> lastCompletedBuild = job.getLastCompletedBuild();
119127

120128
JunitTestResultStorage storage = JunitTestResultStorage.find();
@@ -127,11 +135,11 @@ protected LinesChartModel createChartModel() {
127135
if (buildHistory == null) {
128136
return new LinesChartModel();
129137
}
130-
return new TestResultTrendChart().create(buildHistory, new ChartModelConfiguration());
138+
return new TestResultTrendChart().create(buildHistory, configuration);
131139
}
132140

133141
@CheckForNull
134-
private TestResultActionIterable createBuildHistory(Run<?, ?> lastCompletedBuild) {
142+
private TestResultActionIterable createBuildHistory(final Run<?, ?> lastCompletedBuild) {
135143
// some plugins that depend on junit seem to attach the action even though there's no run
136144
// e.g. xUnit and cucumber
137145
if (lastCompletedBuild == null) {
@@ -153,11 +161,11 @@ private TestResultActionIterable createBuildHistory(Run<?, ?> lastCompletedBuild
153161

154162
/**
155163
* Display the test result trend.
156-
*
164+
*
157165
* @deprecated Replaced by echarts in TODO
158166
*/
159167
@Deprecated
160-
public void doTrend( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
168+
public void doTrend( final StaplerRequest req, final StaplerResponse rsp ) throws IOException, ServletException {
161169
AbstractTestResultAction a = getLastTestResultAction();
162170
if(a!=null)
163171
a.doGraph(req,rsp);
@@ -171,7 +179,7 @@ public void doTrend( StaplerRequest req, StaplerResponse rsp ) throws IOExceptio
171179
* @deprecated Replaced by echarts in TODO
172180
*/
173181
@Deprecated
174-
public void doTrendMap( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
182+
public void doTrendMap( final StaplerRequest req, final StaplerResponse rsp ) throws IOException, ServletException {
175183
AbstractTestResultAction a = getLastTestResultAction();
176184
if(a!=null)
177185
a.doGraphMap(req,rsp);
@@ -182,7 +190,7 @@ public void doTrendMap( StaplerRequest req, StaplerResponse rsp ) throws IOExcep
182190
/**
183191
* Changes the test result report display mode.
184192
*/
185-
public void doFlipTrend( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
193+
public void doFlipTrend( final StaplerRequest req, final StaplerResponse rsp ) throws IOException, ServletException {
186194
boolean failureOnly = false;
187195

188196
// check the current preference value
@@ -200,7 +208,7 @@ public void doFlipTrend( StaplerRequest req, StaplerResponse rsp ) throws IOExce
200208
// set the updated value
201209
Cookie cookie = new Cookie(FAILURE_ONLY_COOKIE,String.valueOf(failureOnly));
202210
List<Ancestor> anc = req.getAncestors();
203-
Ancestor a = (Ancestor) anc.get(anc.size()-2);
211+
Ancestor a = anc.get(anc.size()-2);
204212
cookie.setPath(a.getUrl()); // just for this project
205213
cookie.setMaxAge(60*60*24*365); // 1 year
206214
rsp.addCookie(cookie);
@@ -211,12 +219,17 @@ public void doFlipTrend( StaplerRequest req, StaplerResponse rsp ) throws IOExce
211219

212220
private static final String FAILURE_ONLY_COOKIE = "TestResultAction_failureOnly";
213221

214-
@JavaScriptMethod
215-
@Override
222+
@Override @Deprecated
216223
public String getBuildTrendModel() {
217224
return new JacksonFacade().toJson(createChartModel());
218225
}
219226

227+
@JavaScriptMethod
228+
@Override
229+
public String getConfigurableBuildTrendModel(final String configuration) {
230+
return new JacksonFacade().toJson(createChartModel(ChartModelConfiguration.fromJson(configuration)));
231+
}
232+
220233
@Override
221234
public boolean isTrendVisible() {
222235
return true;

src/main/java/hudson/tasks/test/TestResultTrendChart.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
package hudson.tasks.test;
22

3+
import java.util.List;
4+
35
import edu.hm.hafner.echarts.ChartModelConfiguration;
46
import edu.hm.hafner.echarts.LineSeries;
57
import edu.hm.hafner.echarts.LinesChartModel;
68
import edu.hm.hafner.echarts.LinesDataSet;
79
import edu.hm.hafner.echarts.Palette;
810
import edu.umd.cs.findbugs.annotations.NonNull;
11+
912
import hudson.tasks.junit.TrendTestResultSummary;
10-
import java.util.List;
1113

12-
import static hudson.tasks.test.TestResultTrendSeriesBuilder.FAILED_KEY;
13-
import static hudson.tasks.test.TestResultTrendSeriesBuilder.PASSED_KEY;
14-
import static hudson.tasks.test.TestResultTrendSeriesBuilder.SKIPPED_KEY;
14+
import static hudson.tasks.test.TestResultTrendSeriesBuilder.*;
1515

1616
public class TestResultTrendChart {
17-
18-
public LinesChartModel create(List<TrendTestResultSummary> results) {
17+
18+
public LinesChartModel create(final List<TrendTestResultSummary> results) {
1919
LinesDataSet dataset = new LinesDataSet();
2020
results.forEach(result -> dataset.add(result.getDisplayName(), result.toMap(), result.getBuildNumber()));
21-
21+
2222
return getLinesChartModel(dataset);
2323
}
2424

@@ -29,7 +29,7 @@ public LinesChartModel create(@NonNull final Iterable results,
2929

3030
return getLinesChartModel(dataSet);
3131
}
32-
32+
3333
public LinesChartModel createFromTestObject(final Iterable results,
3434
final ChartModelConfiguration configuration) {
3535
TestObjectTrendSeriesBuilder builder = new TestObjectTrendSeriesBuilder();
@@ -38,11 +38,8 @@ public LinesChartModel createFromTestObject(final Iterable results,
3838
return getLinesChartModel(dataSet);
3939
}
4040

41-
private LinesChartModel getLinesChartModel(LinesDataSet dataSet) {
42-
LinesChartModel model = new LinesChartModel();
43-
model.setDomainAxisLabels(dataSet.getDomainAxisLabels());
44-
model.setBuildNumbers(dataSet.getBuildNumbers());
45-
41+
private LinesChartModel getLinesChartModel(final LinesDataSet dataSet) {
42+
LinesChartModel model = new LinesChartModel(dataSet);
4643
LineSeries failed = new LineSeries("Failed", Palette.RED.getNormal(),
4744
LineSeries.StackedMode.STACKED, LineSeries.FilledMode.FILLED);
4845
failed.addAll(dataSet.getSeries(FAILED_KEY));

0 commit comments

Comments
 (0)