|
| 1 | +package org.scoverage; |
| 2 | + |
| 3 | +import scoverage.Constants; |
| 4 | +import scoverage.Coverage; |
| 5 | +import scoverage.report.CoberturaXmlWriter; |
| 6 | +import scoverage.report.ScoverageHtmlWriter; |
| 7 | +import scoverage.report.ScoverageXmlWriter; |
| 8 | + |
| 9 | +import java.io.File; |
| 10 | + |
| 11 | +/** |
| 12 | + * Util for generating and saving coverage files. |
| 13 | + * <p/> |
| 14 | + * Copied from sbt-scoverage and converted to Java to avoid dependency to Scala. |
| 15 | + */ |
| 16 | +public class ScoverageWriter { |
| 17 | + |
| 18 | + /** |
| 19 | + * Generates all reports from given data. |
| 20 | + * |
| 21 | + * @param sourceDir directory with project sources |
| 22 | + * @param reportDir directory for generate reports |
| 23 | + * @param coverage coverage data |
| 24 | + * @param coverageOutputCobertura switch for Cobertura output |
| 25 | + * @param coverageOutputXML switch for Scoverage XML output |
| 26 | + * @param coverageOutputHTML switch for Scoverage HTML output |
| 27 | + * @param coverageDebug switch for Scoverage Debug output |
| 28 | + */ |
| 29 | + public static void write(File sourceDir, |
| 30 | + File reportDir, |
| 31 | + Coverage coverage, |
| 32 | + Boolean coverageOutputCobertura, |
| 33 | + Boolean coverageOutputXML, |
| 34 | + Boolean coverageOutputHTML, |
| 35 | + Boolean coverageDebug) { |
| 36 | + |
| 37 | + System.out.println("[scoverage] Generating scoverage reports..."); |
| 38 | + |
| 39 | + reportDir.mkdirs(); |
| 40 | + |
| 41 | + if (coverageOutputCobertura) { |
| 42 | + new CoberturaXmlWriter(sourceDir, reportDir).write(coverage); |
| 43 | + System.out.println("[scoverage] Written Cobertura XML report to " + |
| 44 | + reportDir.getAbsolutePath() + |
| 45 | + File.separator + |
| 46 | + "cobertura.xml"); |
| 47 | + } |
| 48 | + |
| 49 | + if (coverageOutputXML) { |
| 50 | + new ScoverageXmlWriter(sourceDir, reportDir, /* debug = */ false).write(coverage); |
| 51 | + System.out.println("[scoverage] Written XML report to " + |
| 52 | + reportDir.getAbsolutePath() + |
| 53 | + File.separator + |
| 54 | + Constants.XMLReportFilename()); |
| 55 | + if (coverageDebug) { |
| 56 | + new ScoverageXmlWriter(sourceDir, reportDir, /* debug = */ true).write(coverage); |
| 57 | + System.out.println("[scoverage] Written XML report with debug information to " + |
| 58 | + reportDir.getAbsolutePath() + |
| 59 | + File.separator + |
| 60 | + Constants.XMLReportFilenameWithDebug()); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + if (coverageOutputHTML) { |
| 65 | + new ScoverageHtmlWriter(sourceDir, reportDir).write(coverage); |
| 66 | + System.out.println("[scoverage] Written HTML report to " + |
| 67 | + reportDir.getAbsolutePath() + |
| 68 | + File.separator + |
| 69 | + "index.html"); |
| 70 | + } |
| 71 | + |
| 72 | + System.out.println("[scoverage] Coverage reports completed"); |
| 73 | + } |
| 74 | +} |
0 commit comments