Skip to content

Commit 7a1bb80

Browse files
authored
Merge pull request #271 from eclipse-rcptt/merge/master/release/2.8
Merge release/2.8 into master
2 parents c2cbcf8 + 34d8085 commit 7a1bb80

19 files changed

Lines changed: 356 additions & 202 deletions

File tree

launching/org.eclipse.rcptt.reporting.html/src/org/eclipse/rcptt/reporting/html/HtmlReportRenderer.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2019 Xored Software Inc and others.
2+
* Copyright (c) 2009 Xored Software Inc and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -18,6 +18,7 @@
1818
import static org.eclipse.rcptt.reporting.html.internal.Plugin.UTILS;
1919

2020
import java.io.IOException;
21+
import java.io.InputStream;
2122
import java.io.OutputStream;
2223
import java.io.OutputStreamWriter;
2324
import java.io.PrintWriter;
@@ -54,8 +55,8 @@ public class HtmlReportRenderer implements IReportRenderer {
5455
}
5556

5657
static String loadAsString(String path) {
57-
try {
58-
byte[] content = FileUtil.getStreamContent(HtmlReportRenderer.class.getResourceAsStream(path));
58+
try (InputStream is = HtmlReportRenderer.class.getResourceAsStream(path)) {
59+
byte[] content = FileUtil.getStreamContent(is);
5960
return new String(content, StandardCharsets.UTF_8);
6061
} catch (IOException e) {
6162
throw new RuntimeException("Failed to load " + path);
@@ -65,28 +66,23 @@ static String loadAsString(String path) {
6566
@Override
6667
public IStatus generateReport(IContentFactory factory, String reportName,
6768
Iterable<Report> reportList) {
68-
PrintWriter writer = null;
69-
try {
70-
OutputStream stream = factory.createFileStream(reportName + ".html");
71-
writer = new PrintWriter(new OutputStreamWriter(stream, StandardCharsets.UTF_8));
69+
try (
70+
PrintWriter writer = new PrintWriter(new OutputStreamWriter(
71+
factory.createFileStream(reportName + ".html"), StandardCharsets.UTF_8));) {
7272
renderReport(writer, reportList, factory);
73-
} catch (Exception e) {
74-
return Plugin.UTILS.createError(e);
75-
} finally {
76-
FileUtil.safeClose(writer);
73+
} catch (CoreException e) {
74+
return e.getStatus();
7775
}
7876
return Status.OK_STATUS;
7977
}
8078

81-
82-
8379
protected void renderReport(PrintWriter writer, Iterable<Report> reports, IContentFactory content)
8480
throws CoreException {
8581
writer.println("<html>");
8682
renderHead(writer, null);
8783
writer.println("<body onload=\"installDetailsWorkaround()\">");
88-
Q7Statistics statistics = ReportUtils.calculateStatistics(reports.iterator());
89-
renderSummary(writer, reports, statistics);
84+
Q7Statistics statistics = ReportUtils.calculateStatisticsSlow(reports.iterator());
85+
renderSummary(writer, statistics);
9086
Iterable<Report> passedReports = filter(reports, compose(equalTo(IStatus.OK), reportStatus));
9187
Iterable<Report> skippedReports = filter(reports, compose(matches(IStatus.CANCEL), reportStatus));
9288
Iterable<Report> failedReports = filter(reports,
@@ -161,7 +157,7 @@ public String apply(Screenshot input) {
161157
renderer.render(report);
162158
}
163159

164-
private void renderSummary(PrintWriter writer, Iterable<Report> reports, Q7Statistics statistics) {
160+
private void renderSummary(PrintWriter writer, Q7Statistics statistics) {
165161
renderStatistics(writer, statistics);
166162
}
167163

@@ -208,6 +204,7 @@ public String toString() {
208204
}
209205
}
210206

207+
@Override
211208
public String[] getGeneratedFileNames(String reportName) {
212209
return new String[] { reportName + ".html" };
213210
}

launching/org.eclipse.rcptt.reporting.util/src/org/eclipse/rcptt/reporting/util/FileReportGenerator.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2019 Xored Software Inc and others.
2+
* Copyright (c) 2009 Xored Software Inc and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -31,26 +31,21 @@ public FileReportGenerator() {
3131
public IStatus generateReport(IContentFactory factory, String reportName,
3232
Iterable<Report> report) {
3333

34-
Q7Statistics statistics = ReportUtils.calculateStatistics(report
35-
.iterator());
36-
OutputStream stream = null;
37-
try {
38-
stream = factory.createFileStream(reportName + ".xml");
34+
Q7Statistics statistics = ReportUtils.calculateStatisticsSlow(report.iterator());
35+
36+
try (OutputStream stream = factory.createFileStream(reportName + ".xml")) {
3937
new XMLReportGenerator().generateContent(stream, reportName,
4038
report, statistics);
4139
} catch (CoreException cex) {
4240
return cex.getStatus();
43-
} finally {
44-
try {
45-
stream.close();
46-
} catch (IOException e) {
47-
return Plugin.UTILS.createError(e);
48-
}
41+
} catch (IOException e) {
42+
return Plugin.UTILS.createError(e);
4943
}
5044
return Status.OK_STATUS;
5145
}
5246

5347

48+
@Override
5449
public String[] getGeneratedFileNames(String reportName) {
5550
return new String[] { reportName + ".xml" };
5651
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Xored Software Inc and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v20.html
7+
*
8+
* Contributors:
9+
* Xored Software Inc - initial API and implementation and/or initial documentation
10+
*******************************************************************************/
11+
package org.eclipse.rcptt.reporting.util;
12+
13+
import static java.util.Collections.synchronizedMap;
14+
import static java.util.Objects.requireNonNull;
15+
16+
import java.io.Closeable;
17+
import java.io.IOException;
18+
import java.io.InputStream;
19+
import java.io.UncheckedIOException;
20+
import java.nio.file.Path;
21+
import java.util.HashMap;
22+
import java.util.Map;
23+
import java.util.stream.Stream;
24+
import java.util.zip.ZipEntry;
25+
import java.util.zip.ZipException;
26+
import java.util.zip.ZipFile;
27+
28+
import org.eclipse.rcptt.sherlock.core.model.sherlock.report.Report;
29+
import org.eclipse.rcptt.sherlock.core.streams.SherlockReportFormat;
30+
31+
/** A collection of reports from one execution session grouped in a ZIP file **/
32+
public final class IndexedExecutionReport implements Closeable {
33+
private final ZipFile zipFile;
34+
private final Map<String, Handle> idIndex = synchronizedMap(new HashMap<>());
35+
private final Map<String, Handle> entryIndex = synchronizedMap(new HashMap<>());
36+
public final class Handle {
37+
private final ZipEntry zipEntry;
38+
private ReportEntry reportEntry;
39+
private Handle(ZipEntry entry) {
40+
this.zipEntry = requireNonNull(entry);
41+
}
42+
public String getId() throws IOException {
43+
return getEntry().id;
44+
}
45+
public Report getReport() throws IOException {
46+
try (InputStream is = zipFile.getInputStream(zipEntry)) {
47+
Report report = SherlockReportFormat.loadReport(is, true, true);
48+
reportEntry = ReportEntry.create(report);
49+
idIndex.put(reportEntry.id, this);
50+
return report;
51+
}
52+
}
53+
public ReportEntry getEntry() throws IOException {
54+
if (reportEntry == null) {
55+
getReport();
56+
}
57+
assert reportEntry != null;
58+
return reportEntry;
59+
}
60+
}
61+
public IndexedExecutionReport(Path path) throws ZipException, IOException {
62+
zipFile = new ZipFile(path.toFile());
63+
}
64+
public Stream<Handle> read() {
65+
if (zipFile.size() == entryIndex.size()) {
66+
return entryIndex.values().stream();
67+
}
68+
return zipFile.stream().map(e -> entryIndex.computeIfAbsent(e.getName(), (ignored) -> new Handle(e)) );
69+
}
70+
@Override
71+
public void close() throws IOException {
72+
idIndex.clear();
73+
zipFile.close();
74+
}
75+
public Handle getById(String id) {
76+
Handle result = idIndex.get(id);
77+
if (result != null) {
78+
return result;
79+
}
80+
try (Stream<Handle> s = read()) {
81+
return s.filter(h -> {
82+
try {
83+
return id.equals(h.getId());
84+
} catch (IOException e) {
85+
throw new UncheckedIOException(e);
86+
}
87+
}).findAny().get();
88+
}
89+
}
90+
}

launching/org.eclipse.rcptt.reporting.util/src/org/eclipse/rcptt/reporting/util/JUnitFileReportGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2019 Xored Software Inc and others.
2+
* Copyright (c) 2009 Xored Software Inc and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -43,8 +43,7 @@ public IStatus generateReport(IContentFactory factory, String reportName,
4343
writer = XMLUtils.createWriter(stream);
4444
writer.writeStartDocument();
4545

46-
Q7Statistics statistics = ReportUtils.calculateStatistics(report
47-
.iterator());
46+
Q7Statistics statistics = ReportUtils.calculateStatisticsSlow(report.iterator());
4847
new JUnitXMLReportGenerator().writeSuite(writer, reportName,
4948
report.iterator(), statistics);
5049

@@ -66,6 +65,7 @@ public IStatus generateReport(IContentFactory factory, String reportName,
6665
return Status.OK_STATUS;
6766
}
6867

68+
@Override
6969
public String[] getGeneratedFileNames(String reportName) {
7070
return new String[] { reportName + ".junit.xml" };
7171
}

launching/org.eclipse.rcptt.reporting.util/src/org/eclipse/rcptt/reporting/util/JUnitXMLReportGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2019 Xored Software Inc and others.
2+
* Copyright (c) 2009 Xored Software Inc and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -43,7 +43,7 @@ public void writeContent(Reports reports, OutputStream stream)
4343

4444
for (String suite : reports.getSuiteIds()) {
4545
Q7Statistics statistics = ReportUtils
46-
.calculateStatistics(reports.getReports(suite));
46+
.calculateStatisticsSlow(reports.getReports(suite));
4747
writeSuite(writer, suite, reports.getReports(suite), statistics);
4848
}
4949

launching/org.eclipse.rcptt.reporting.util/src/org/eclipse/rcptt/reporting/util/ReportEntry.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2019 Xored Software Inc and others.
2+
* Copyright (c) 2009 Xored Software Inc and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -12,12 +12,10 @@
1212

1313
import static com.google.common.base.Preconditions.checkNotNull;
1414

15-
import java.io.PrintWriter;
16-
import java.io.StringWriter;
17-
import java.util.ArrayList;
15+
import java.time.Duration;
16+
import java.time.Instant;
1817

1918
import org.eclipse.rcptt.reporting.Q7Info;
20-
import org.eclipse.rcptt.reporting.core.ImageEntry;
2119
import org.eclipse.rcptt.reporting.core.ReportHelper;
2220
import org.eclipse.rcptt.reporting.core.SimpleSeverity;
2321
import org.eclipse.rcptt.sherlock.core.model.sherlock.report.Node;
@@ -29,22 +27,24 @@
2927
public final class ReportEntry {
3028
public final String name;
3129
public final String id;
32-
public final int time;
3330
private final int status;
31+
public int time;
3432
public final String message;
33+
private Instant start, end;
3534

36-
private ReportEntry(String name, String id, int time, int status, String message) {
35+
private ReportEntry(String name, String id, int status, String message, Instant start, Instant end) {
3736
super();
3837
checkNotNull(name);
3938
checkNotNull(id);
40-
checkNotNull(time);
4139
checkNotNull(status);
4240
checkNotNull(message);
4341
this.message = message;
4442
this.name = name;
4543
this.id = id;
46-
this.time = time;
4744
this.status = status;
45+
this.start = checkNotNull(start);
46+
this.end = checkNotNull(end);
47+
this.time = Math.toIntExact(Duration.between(start, end).toMillis());
4848
}
4949

5050
public String getMessage() {
@@ -62,12 +62,22 @@ public int getStatusSeverity() {
6262

6363
public static ReportEntry create(Report next) {
6464
Node root = next.getRoot();
65+
if (root == null) {
66+
return new ReportEntry("Broken report", "Broken report", 0, "A report is missing RCPTT required metadata. This is likely coused by early termination of test runner.", Instant.EPOCH, Instant.EPOCH);
67+
}
6568
Q7Info info = ReportHelper.getInfo(root);
66-
StringWriter writer = new StringWriter();
67-
RcpttReportGenerator.writeResult(new PrintWriter(writer), 0, info.getResult());
68-
ReportEntry entry = new ReportEntry(root.getName(), info.getId(), (int) root.getDuration(),
69-
info.getResult().getSeverity(), writer.toString());
69+
ReportEntry entry = new ReportEntry(root.getName(), info.getId(), info.getResult().getSeverity(),
70+
ReportUtils.getFailMessage(root), Instant.ofEpochMilli(root.getStartTime()), Instant.ofEpochMilli(root.getEndTime()));
7071
return entry;
7172
}
7273

74+
public Instant getStart() {
75+
return start;
76+
}
77+
78+
public Instant getEnd() {
79+
return end;
80+
}
81+
82+
7383
}

0 commit comments

Comments
 (0)