aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpacien2018-10-10 16:41:04 +0200
committerpacien2018-10-10 16:41:04 +0200
commit8f30fc76e498b3c561f511e218a6d4a0b0fc6d16 (patch)
tree0cb9ce497b2e6f75ee9badbec71e97a14c7528c0 /src
parent6f3fc8c44a917ba8248388c886ea1c97dfe4285e (diff)
downloadjacoco-viewer-8f30fc76e498b3c561f511e218a6d4a0b0fc6d16.tar.gz
Initial implementation
Diffstat (limited to 'src')
-rw-r--r--src/App.css65
-rw-r--r--src/App.js121
-rw-r--r--src/Blocks.js99
-rw-r--r--src/logo.svg7
4 files changed, 248 insertions, 44 deletions
<
diff --git a/src/App.css b/src/App.css
index 92f956e..d0870a2 100644
--- a/src/App.css
+++ b/src/App.css
@@ -1,32 +1,53 @@
1/*
2 * JaCoCo Report Viewer, a web-based coverage report viewer
3 * Copyright (C) 2018 Pacien TRAN-GIRARD
4 * Adam NAILI
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
1.App { 20.App {
2 text-align: center; 21 margin: 1rem;
22}
23
24.App label {
25 display: inline-block;
26 width: 6rem;
27}
28
29.App ul {
30 padding-left: 1.75rem;
31}
32
33.App ul[inline-list="true"] {
34 display: inline;
35 padding-left: 0.75rem;
3} 36}
4 37
5.App-logo { 38.App ul[inline-list="true"] li {
6 animation: App-logo-spin infinite 20s linear; 39 display: inline;
7 height: 40vmin; 40 list-style: none;
8} 41}
9 42
10.App-header { 43.App ul[inline-list="true"] li:not(:first-child) {
11 background-color: #282c34; 44 padding-left: 0.75rem;
12 min-height: 100vh;
13 display: flex;
14 flex-direction: column;
15 align-items: center;
16 justify-content: center;
17 font-size: calc(10px + 2vmin);
18 color: white;
19} 45}
20 46
21.App-link { 47.App li[well-covered="true"] {
22 color: #61dafb; 48 color: green;
23} 49}
24 50
25@keyframes App-logo-spin { 51.App li[well-covered="false"] {
26 from { 52 color: red;
27 transform: rotate(0deg);
28 }
29 to {
30 transform: rotate(360deg);
31 }
32} 53}
diff --git a/src/App.js b/src/App.js
index 7e261ca..347d243 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,28 +1,119 @@
1/*
2 * JaCoCo Report Viewer, a web-based coverage report viewer
3 * Copyright (C) 2018 Pacien TRAN-GIRARD
4 * Adam NAILI
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
1import React, { Component } from 'react'; 20import React, { Component } from 'react';
2import logo from './logo.svg'; 21import {Parser} from 'xml2js';
22
23import {Counters, SessionInfo, PackagesCoverage} from './Blocks.js';
3import './App.css'; 24import './App.css';
4 25
5class App extends Component { 26class App extends Component {
27 constructor(props) {
28 super(props);
29 this.state = {
30 report: null,
31 hasError: false
32 };
33 }
34
35 componentDidCatch(error, info) {
36 this.setState({ hasError: true });
37 console.err(error, info);
38 }
39
40 _useReportFile(file) {
41 const fileReader = new FileReader();
42 fileReader.onloadend = (readEvent) => this._useReport(readEvent.target.result);
43 fileReader.readAsText(file);
44 }
45
46 _useReport(xmlString) {
47 const xmlParser = new Parser();
48 xmlParser.parseString(xmlString, (err, result) => this.setState({ report: result.report }));
49 }
50
51 _renderError() {
52 return (
53 <span>
54 Something went wrong while rendering the report.
55 Are the provided files valid?
56 </span>
57 );
58 }
59
60 _renderReport() {
61 return this.state.hasError ? this._renderError(): (<Report report={this.state.report} />);
62 }
63
6 render() { 64 render() {
7 return ( 65 return (
8 <div className="App"> 66 <div className="App">
9 <header className="App-header"> 67 <h1>JaCoCo Report Viewer</h1>
10 <img src={logo} className="App-logo" alt="logo" /> 68
11 <p> 69 <div>
12 Edit <code>src/App.js</code> and save to reload. 70 <label htmlFor="reportFile">XML report: </label>
13 </p> 71 <input id="reportFile" type="file" accept=".xml" onChange={event => this._useReportFile(event.target.files[0])} />
14 <a 72 </div>
15 className="App-link" 73
16 href="https://reactjs.org" 74 <div>
17 target="_blank" 75 <label htmlFor="sourceJar">Source JAR: </label>
18 rel="noopener noreferrer" 76 <input id="sourceJar" type="file" accept=".jar" onChange={event => null} />
19 > 77 </div>
20 Learn React 78
21 </a> 79 <hr />
22 </header> 80 {this._renderReport()}
81 </div>
82 );
83 }
84}
85
86class Report extends Component {
87 _renderNone() {
88 return (<span>Please provide a JaCoCo XML report file to visualise.</span>);
89 }
90
91 _renderReport() {
92 return (
93 <div>
94 <h2>Viewing report: "{this.props.report.$.name}"</h2>
95
96 <section>
97 <h3>Session info</h3>
98 <SessionInfo data={this.props.report.sessioninfo} />
99 </section>
100
101 <section>
102 <h3>Global coverage</h3>
103 <Counters data={this.props.report.counter} />
104 </section>
105
106 <section>
107 <h3>Details</h3>
108 <PackagesCoverage packages={this.props.report.package} />
109 </section>
23 </div> 110 </div>
24 ); 111 );
25 } 112 }
113
114 render() {
115 return this.props.report ? this._renderReport() : this._renderNone();
116 }
26} 117}
27 118
28export default App; 119export default App;
diff --git a/src/Blocks.js b/src/Blocks.js
new file mode 100644
index 0000000..48e0376
--- /dev/null
+++ b/src/Blocks.js
@@ -0,0 +1,99 @@
1/*
2 * JaCoCo Report Viewer, a web-based coverage report viewer
3 * Copyright (C) 2018 Pacien TRAN-GIRARD
4 * Adam NAILI
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20import React, { Component } from 'react';
21
22function renderRows(renderRowFunc, rows, inline) {
23 const renderedRows = rows ? rows.map(renderRowFunc) : (<li>None.</li>);
24 return (<ul inline-list={inline.toString()}>{renderedRows}</ul>);
25}
26
27export class SessionInfo extends Component {
28 _renderRow(row) {
29 const date = new Date(parseInt(row.start));
30 return (<li key={row.id}>{row.id}: {date.toISOString()} ({row.dump - row.start} ms)</li>);
31 }
32
33 render() {
34 return renderRows(row => this._renderRow(row.$), this.props.data, false);
35 }
36