Skip to contentPackage: TestInfo
TestInfo
Coverage
1: /*
2: * *********************************************************************************************************************
3: *
4: * Mistral: open source imaging engine
5: * http://tidalwave.it/projects/mistral
6: *
7: * Copyright (C) 2003 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/mistral-src
23: * git clone https://github.com/tidalwave-it/mistral-src
24: *
25: * *********************************************************************************************************************
26: */
27: /*
28: * TestReportFormatter.java
29: *
30: * Created on November 26, 2006, 2:43 PM
31: *
32: * To change this template, choose Tools | Template Manager
33: * and open the template in the editor.
34: */
35: package it.tidalwave.image.tools;
36:
37: import java.util.ArrayList;
38: import java.util.Collections;
39: import java.util.List;
40: import java.util.Set;
41: import java.util.TreeSet;
42: import java.io.BufferedReader;
43: import java.io.FileReader;
44: import java.io.FileWriter;
45: import java.io.IOException;
46: import java.io.PrintWriter;
47: import java.nio.file.Files;
48: import java.nio.file.Path;
49:
50:
51: /**
52: * @author Fabrizio Giudici
53: */
54: class TestInfo implements Comparable<TestInfo>
55: {
56: private final String revision;
57: private final String test;
58: private final String quality;
59: private final String file;
60: private Set<TestResults> results = new TreeSet<>();
61:
62: public TestInfo (final String body)
63: {
64: System.err.println(body);
65:
66: final var tmp = body.split("::");
67: revision = tmp[0];
68: test = tmp[3];
69: quality = tmp[4];
70: file = tmp[5];
71: }
72:
73: public void add (final TestResults testResults)
74: {
75: results.add(testResults);
76: }
77:
78: public void printHeader (final PrintWriter pw)
79: {
80: pw.println(
81: "<tr><td rowspan='2'>Revision</td><td rowspan='2'>Test</td><td rowspan='2'>Quality</td><td " +
82: "rowspan='2'>Path</td>");
83:
84:• for (final var testResults : results)
85: {
86: pw.println("<td>" + testResults.host + "</td>");
87: }
88:
89: pw.println("</tr>");
90: pw.println("<tr>");
91:
92:• for (final var testResults : results)
93: {
94: pw.println("<td>" + testResults.os + "</td>");
95: }
96:
97: pw.println("</tr>");
98: }
99:
100: private static String latestTest = "";
101: private String[] colors = new String[]{"#ffffff", "#dddddd"};
102: private static int k;
103:
104: public void print (final PrintWriter pw)
105: {
106:• if (!latestTest.equals(test + quality))
107: {
108: k++;
109: latestTest = test + quality;
110: }
111:
112: pw.print("<tr bgcolor='" + colors[k % colors.length] + "'><td align='right'>" + revision + "</td>");
113: pw.print("<td>" + test + "</td>");
114: pw.print("<td>" + quality + "</td>");
115: pw.print("<td>" + file + "</td>");
116:
117:• for (final var testResults : results)
118: {
119: testResults.print(pw);
120: }
121:
122: pw.println("</tr>");
123: }
124:
125: @Override
126: public int compareTo (final TestInfo o)
127: {
128: var r = test.compareTo(o.test);
129:
130:• if (r != 0)
131: {
132: return r;
133: }
134:
135: r = quality.compareTo(o.quality);
136:
137:• if (r != 0)
138: {
139: return r;
140: }
141:
142: r = file.compareTo(o.file);
143:
144:• if (r != 0)
145: {
146: return r;
147: }
148:
149: var tRevision = revision;
150: var i = tRevision.lastIndexOf('.');
151:
152:• if (i > 0)
153: {
154: tRevision = revision.substring(i + 1);
155: }
156:
157: var oRevision = o.revision;
158: i = oRevision.lastIndexOf('.');
159:
160:• if (i > 0)
161: {
162: oRevision = oRevision.substring(i + 1);
163: }
164:
165: r = tRevision.compareTo(oRevision);
166:
167: return r;
168: }
169:
170: @Override
171: public boolean equals (final Object o)
172: {
173:• if (!(o instanceof TestInfo))
174: {
175: return false;
176: }
177:
178:• return compareTo((TestInfo)o) == 0;
179: }
180:
181: public int hashcode()
182: {
183: return revision.hashCode() ^ test.hashCode() ^ quality.hashCode() ^ file.hashCode();
184: }
185: }
186:
187:
188: class TestResults implements Comparable<TestResults>
189: {
190: private final String value;
191: public final String host;
192: public final String os;
193:
194: public TestResults (final String body, final String value)
195: {
196: final var tmp = body.split("::");
197: host = tmp[1];
198: os = tmp[2];
199: this.value = value;
200: }
201:
202: @Override
203: public int compareTo (final TestResults o)
204: {
205: var r = host.compareTo(o.host);
206:
207: if (r != 0)
208: {
209: return r;
210: }
211:
212: r = os.compareTo(o.os);
213:
214: return r;
215: }
216:
217: public void print (final PrintWriter pw)
218: {
219: var color = "black";
220:
221: if (value.equals("FAILS") || (!value.equals("-") && (Integer.parseInt(value) > 50000)))
222: {
223: color = "red";
224: }
225:
226: pw.print("<td align='right'><font color='" + color + "'>" + value + "</font></td>");
227: }
228: }
229:
230:
231: public class TestReportFormatter
232: {
233: private final Path reportFile;
234: private final Path htmlFile;
235: private List<TestInfo> tests = new ArrayList<>();
236:
237: /**
238: * Creates a new instance of TestReportFormatter
239: */
240: public TestReportFormatter (final Path reportFile, final Path htmlFile)
241: {
242: this.reportFile = reportFile;
243: this.htmlFile = htmlFile;
244: }
245:
246: public void run()
247: throws IOException
248: {
249: try (final var br = Files.newBufferedReader(reportFile))
250: {
251: for (;;)
252: {
253: var s = br.readLine();
254:
255: if (s == null)
256: {
257: break;
258: }
259:
260: s = s.split("#")[0].trim();
261:
262: if ("".equals(s))
263: {
264: continue;
265: }
266:
267: final var tmp = s.split("=");
268: final var body = tmp[0].trim();
269: final var value = tmp[1].trim();
270: var testInfo = new TestInfo(body);
271: final var testResults = new TestResults(body, value);
272:
273: final var i = tests.indexOf(testInfo);
274:
275: if (i < 0)
276: {
277: tests.add(testInfo);
278: }
279:
280: else
281: {
282: testInfo = tests.get(i);
283: }
284:
285: testInfo.add(testResults);
286: }
287: }
288:
289: Collections.sort(tests);
290:
291: try (final var pw = new PrintWriter(Files.newBufferedWriter(htmlFile)))
292: {
293: pw.println("<table border='1' cellpadding='2' cellspacing='0'>");
294: tests.get(0).printHeader(pw);
295:
296: for (final var testInfo : tests)
297: {
298: testInfo.print(pw);
299: }
300:
301: pw.println("</table>");
302: }
303: }
304:
305: public static void main (final String[] args)
306: throws IOException
307: {
308: new TestReportFormatter(Path.of(
309: "/Users/fritz/Business/Tidalwave/Projects/Mistral/trunk/src/EditableImage/TestReport.txt"),
310: Path.of(
311: "/Users/fritz/Business/Tidalwave/Projects/Mistral/trunk/src/EditableImage/TestReport.html")).run();
312: }
313: }