1 /**
2 Copyright: Copyright (c) 2017, Joakim Brännström. All rights reserved.
3 License: MPL-2
4 Author: Joakim Brännström (joakim.brannstrom@gmx.com)
5 
6 This Source Code Form is subject to the terms of the Mozilla Public License,
7 v.2.0. If a copy of the MPL was not distributed with this file, You can obtain
8 one at http://mozilla.org/MPL/2.0/.
9 
10 This module contains functionality for reporting the mutations. Both the
11 summary and details for each mutation.
12 */
13 module dextool.plugin.mutate.backend.report;
14 
15 import logger = std.experimental.logger;
16 import std.ascii : newline;
17 import std.exception : collectException;
18 
19 import dextool.type;
20 import my.actor;
21 
22 import dextool.plugin.mutate.backend.database : Database;
23 import dextool.plugin.mutate.backend.diff_parser : Diff, diffFromStdin;
24 import dextool.plugin.mutate.backend.interface_ : FilesysIO;
25 import dextool.plugin.mutate.backend.utility : getProfileResult, Profile;
26 import dextool.plugin.mutate.config : ConfigReport;
27 import dextool.plugin.mutate.type : MutationKind, ReportKind;
28 
29 ExitStatusType runReport(const AbsolutePath dbPath, const MutationKind[] kind,
30         ConfigReport conf, FilesysIO fio) @trusted {
31 
32     auto sys = makeSystem;
33 
34     ExitStatusType helper() {
35         Diff diff;
36         if (conf.unifiedDiff) {
37             diff = diffFromStdin;
38         }
39 
40         final switch (conf.reportKind) with (ReportKind) {
41         case plain: {
42                 import dextool.plugin.mutate.backend.report.plain : report;
43 
44                 auto db = Database.make(dbPath);
45                 report(db, kind, conf, fio);
46             }
47             break;
48         case compiler: {
49                 import dextool.plugin.mutate.backend.report.compiler : report;
50 
51                 auto db = Database.make(dbPath);
52                 report(db, kind, conf, fio);
53             }
54             break;
55         case json: {
56                 import dextool.plugin.mutate.backend.report.json : report;
57 
58                 auto db = Database.make(dbPath);
59                 report(db, kind, conf, fio, diff);
60             }
61             break;
62         case html:
63             import dextool.plugin.mutate.backend.report.html : report;
64 
65             report(sys, dbPath, kind, conf, fio, diff);
66             break;
67         }
68 
69         if (conf.profile)
70             try {
71                 import std.stdio : writeln;
72 
73                 writeln(getProfileResult.toString);
74             } catch (Exception e) {
75                 logger.warning("Unable to print the profile data: ", e.msg).collectException;
76             }
77 
78         return ExitStatusType.Ok;
79     }
80 
81     try {
82         return helper();
83     } catch (Exception e) {
84         logger.error(e.msg).collectException;
85     }
86 
87     return ExitStatusType.Errors;
88 }