Skip to content

Commit 310a78b

Browse files
authored
Restore compatiblity with junit-sql-storage (#630)
1 parent 72cf99b commit 310a78b

File tree

6 files changed

+150
-156
lines changed

6 files changed

+150
-156
lines changed

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

Lines changed: 126 additions & 140 deletions
Large diffs are not rendered by default.

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import hudson.Util;
44
import hudson.model.Run;
5+
import hudson.tasks.test.AbstractTestResultAction;
6+
import hudson.tasks.test.TestResult;
57

68
public class HistoryTestResultSummary {
79

@@ -11,21 +13,19 @@ public class HistoryTestResultSummary {
1113
private final int skipCount;
1214
private final int passCount;
1315
private final String description;
14-
private final hudson.tasks.test.TestResult resultInRun;
1516

16-
public HistoryTestResultSummary(Run<?, ?> run, hudson.tasks.test.TestResult resultInRun,
17+
public HistoryTestResultSummary(Run<?, ?> run,
1718
float duration, int failCount, int skipCount, int passCount) {
18-
this(run, resultInRun, duration, failCount, skipCount, passCount, null);
19+
this(run, duration, failCount, skipCount, passCount, null);
1920
}
2021

21-
public HistoryTestResultSummary(Run<?, ?> run, hudson.tasks.test.TestResult resultInRun, float duration, int failCount, int skipCount, int passCount, String description) {
22+
public HistoryTestResultSummary(Run<?, ?> run, float duration, int failCount, int skipCount, int passCount, String description) {
2223
this.run = run;
2324
this.duration = duration;
2425
this.failCount = failCount;
2526
this.skipCount = skipCount;
2627
this.passCount = passCount;
2728
this.description = description;
28-
this.resultInRun = resultInRun;
2929
}
3030

3131
public String getDescription() {
@@ -36,6 +36,10 @@ public String getDescription() {
3636
return run;
3737
}
3838

39+
public float getDuration() {
40+
return duration;
41+
}
42+
3943
public String getDurationString() {
4044
return Util.getTimeSpanString((long) (duration * 1000));
4145
}
@@ -65,10 +69,9 @@ public String getFullDisplayName() {
6569
}
6670

6771
public String getUrl() {
68-
return resultInRun.getUrl();
69-
}
72+
AbstractTestResultAction<?> action = run.getAction(AbstractTestResultAction.class);
7073

71-
public hudson.tasks.test.TestResult getResultInRun() {
72-
return resultInRun;
74+
// TODO pass id to end of url
75+
return getRun().getUrl() + action.getUrlName() + "/";
7376
}
7477
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,10 +693,11 @@ public int getFailCount() {
693693
if (impl != null) {
694694
return impl.getFailCount();
695695
}
696-
if(failedTests==null)
696+
if(failedTests==null) {
697697
return 0;
698-
else
699-
return failedTests.size();
698+
} else {
699+
return failedTests.size();
700+
}
700701
}
701702

702703
@Exported(visibility=999)

src/main/resources/hudson/tasks/junit/History/history.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ function onBuildIntervalChange(selectObj) {
3131
interval = dataEl.getAttribute("data-interval")
3232
let trendChartJsonStr = dataEl.innerHTML
3333
trendChartJson = JSON.parse(trendChartJsonStr)
34-
appRootUrl = dataEl.getAttribute("data-appRootUrl")
34+
const rootUrl = document.head.dataset.rooturl
35+
if (!rootUrl.endsWith("/")) {
36+
appRootUrl = `${rootUrl}/`
37+
} else {
38+
appRootUrl = rootUrl
39+
}
3540
testObjectUrl = dataEl.getAttribute("data-testObjectUrl")
3641

3742
trendChartJsonStr = null
@@ -390,7 +395,7 @@ function onBuildIntervalChange(selectObj) {
390395
renderTrendChart(trendChartId, trendChartJson, trendConfigurationDialogId,
391396
function (buildDisplayName) {
392397
if (trendChartJson.buildMap[buildDisplayName]) {
393-
window.open(rootUrl + trendChartJson.buildMap[buildDisplayName].url);
398+
window.open(appRootUrl + trendChartJson.buildMap[buildDisplayName].url);
394399
}
395400
});
396401
renderDistributionChart('test-distribution-chart', trendChartJson, trendConfigurationDialogId, null);

src/main/resources/hudson/tasks/junit/History/index.jelly

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ THE SOFTWARE.
4444
data-end="${end}"
4545
data-count="${count}"
4646
data-interval="${interval}"
47-
data-appRootUrl="${app.rootUrl}"
4847
data-testObjectUrl="${it.testObject.url}"
4948
type="application/json"
5049
>${historySummary.trendChartJson}</script>

src/test/java/io/jenkins/plugins/junit/storage/TestResultStorageJunitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ public List<HistoryTestResultSummary> getHistorySummary(int offset) {
476476
Job<?, ?> theJob = Jenkins.get().getItemByFullName(getJobName(), Job.class);
477477
if (theJob != null) {
478478
Run<?, ?> run = theJob.getBuildByNumber(buildNumber);
479-
historyTestResultSummaries.add(new HistoryTestResultSummary(run, null, duration, failed, skipped, passed));
479+
historyTestResultSummaries.add(new HistoryTestResultSummary(run, duration, failed, skipped, passed));
480480
}
481481
}
482482
return historyTestResultSummaries;

0 commit comments

Comments
 (0)