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 : ReportKind; 28 29 ExitStatusType runReport(const AbsolutePath dbPath, ConfigReport conf, FilesysIO fio) @trusted { 30 31 auto sys = makeSystem; 32 33 ExitStatusType helper() { 34 Diff diff; 35 if (conf.unifiedDiff) { 36 diff = diffFromStdin; 37 } 38 39 final switch (conf.reportKind) with (ReportKind) { 40 case plain: { 41 import dextool.plugin.mutate.backend.report.plain : report; 42 43 auto db = Database.make(dbPath); 44 report(db, conf, fio); 45 } 46 break; 47 case compiler: { 48 import dextool.plugin.mutate.backend.report.compiler : report; 49 50 auto db = Database.make(dbPath); 51 report(db, conf, fio); 52 } 53 break; 54 case json: { 55 import dextool.plugin.mutate.backend.report.json : report; 56 57 auto db = Database.make(dbPath); 58 report(db, conf, fio, diff); 59 } 60 break; 61 case html: 62 import dextool.plugin.mutate.backend.report.html : report; 63 64 report(sys, dbPath, conf, fio, diff); 65 break; 66 } 67 68 if (conf.profile) 69 try { 70 import std.stdio : writeln; 71 72 writeln(getProfileResult.toString); 73 } catch (Exception e) { 74 logger.warning("Unable to print the profile data: ", e.msg).collectException; 75 } 76 77 return ExitStatusType.Ok; 78 } 79 80 try { 81 return helper(); 82 } catch (Exception e) { 83 logger.info(e).collectException; 84 logger.error(e.msg).collectException; 85 } 86 87 return ExitStatusType.Errors; 88 }