Search in sources :

Example 1 with Benchmark

use of com.teamscale.jacoco.agent.util.Benchmark in project teamscale-jacoco-agent by cqse.

the class Agent method dumpReportUnsafe.

private void dumpReportUnsafe() {
    Dump dump;
    try {
        dump = controller.dumpAndReset();
    } catch (JacocoRuntimeController.DumpException e) {
        logger.error("Dumping failed, retrying later", e);
        return;
    }
    try (Benchmark ignored = new Benchmark("Generating the XML report")) {
        File outputFile = options.createTempFile("jacoco", "xml");
        CoverageFile coverageFile = generator.convert(dump, outputFile);
        uploader.upload(coverageFile);
    } catch (IOException e) {
        logger.error("Converting binary dump to XML failed", e);
    } catch (EmptyReportException e) {
        logger.error("No coverage was collected. " + e.getMessage(), e);
    }
}
Also used : CoverageFile(com.teamscale.report.jacoco.CoverageFile) Dump(com.teamscale.report.jacoco.dump.Dump) EmptyReportException(com.teamscale.report.jacoco.EmptyReportException) Benchmark(com.teamscale.jacoco.agent.util.Benchmark) IOException(java.io.IOException) CoverageFile(com.teamscale.report.jacoco.CoverageFile) File(java.io.File)

Example 2 with Benchmark

use of com.teamscale.jacoco.agent.util.Benchmark in project teamscale-jacoco-agent by cqse.

the class Converter method runJaCoCoReportGeneration.

/**
 * Converts one .exec binary coverage file to XML.
 */
public void runJaCoCoReportGeneration() throws IOException, AgentOptionParseException {
    List<File> jacocoExecutionDataList = ReportUtils.listFiles(ETestArtifactFormat.JACOCO, arguments.getInputFiles());
    ExecFileLoader loader = new ExecFileLoader();
    for (File jacocoExecutionData : jacocoExecutionDataList) {
        loader.load(jacocoExecutionData);
    }
    SessionInfo sessionInfo = loader.getSessionInfoStore().getMerged("merged");
    ExecutionDataStore executionDataStore = loader.getExecutionDataStore();
    Logger logger = LoggingUtils.getLogger(this);
    JaCoCoXmlReportGenerator generator = new JaCoCoXmlReportGenerator(arguments.getClassDirectoriesOrZips(), getWildcardIncludeExcludeFilter(), arguments.getDuplicateClassFileBehavior(), arguments.shouldIgnoreUncoveredClasses, wrap(logger));
    try (Benchmark benchmark = new Benchmark("Generating the XML report")) {
        generator.convert(new Dump(sessionInfo, executionDataStore), Paths.get(arguments.outputFile).toFile());
    } catch (EmptyReportException e) {
        logger.warn("Converted report was emtpy.", e);
    }
}
Also used : Dump(com.teamscale.report.jacoco.dump.Dump) EmptyReportException(com.teamscale.report.jacoco.EmptyReportException) ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) Benchmark(com.teamscale.jacoco.agent.util.Benchmark) SessionInfo(org.jacoco.core.data.SessionInfo) JaCoCoXmlReportGenerator(com.teamscale.report.jacoco.JaCoCoXmlReportGenerator) Logger(org.slf4j.Logger) CommandLineLogger(com.teamscale.report.util.CommandLineLogger) ILogger(com.teamscale.report.util.ILogger) File(java.io.File) ExecFileLoader(org.jacoco.core.tools.ExecFileLoader)

Example 3 with Benchmark

use of com.teamscale.jacoco.agent.util.Benchmark in project teamscale-jacoco-agent by cqse.

the class Converter method runTestwiseCoverageReportGeneration.

/**
 * Converts one .exec binary coverage file, test details and test execution files to JSON testwise coverage.
 */
public void runTestwiseCoverageReportGeneration() throws IOException, CoverageGenerationException, AgentOptionParseException {
    List<TestDetails> testDetails = ReportUtils.readObjects(ETestArtifactFormat.TEST_LIST, TestDetails[].class, arguments.getInputFiles());
    List<TestExecution> testExecutions = ReportUtils.readObjects(ETestArtifactFormat.TEST_EXECUTION, TestExecution[].class, arguments.getInputFiles());
    List<File> jacocoExecutionDataList = ReportUtils.listFiles(ETestArtifactFormat.JACOCO, arguments.getInputFiles());
    ILogger logger = new CommandLineLogger();
    JaCoCoTestwiseReportGenerator generator = new JaCoCoTestwiseReportGenerator(arguments.getClassDirectoriesOrZips(), getWildcardIncludeExcludeFilter(), arguments.getDuplicateClassFileBehavior(), logger);
    TestInfoFactory testInfoFactory = new TestInfoFactory(testDetails, testExecutions);
    try (Benchmark benchmark = new Benchmark("Generating the testwise coverage report")) {
        logger.info("Writing report with " + testDetails.size() + " Details/" + testExecutions.size() + " Results");
        try (TestwiseCoverageReportWriter coverageWriter = new TestwiseCoverageReportWriter(testInfoFactory, arguments.getOutputFile(), arguments.getSplitAfter())) {
            for (File executionDataFile : jacocoExecutionDataList) {
                generator.convertAndConsume(executionDataFile, coverageWriter);
            }
        }
    }
}
Also used : TestInfoFactory(com.teamscale.report.testwise.model.factory.TestInfoFactory) TestExecution(com.teamscale.report.testwise.model.TestExecution) Benchmark(com.teamscale.jacoco.agent.util.Benchmark) ILogger(com.teamscale.report.util.ILogger) TestDetails(com.teamscale.client.TestDetails) File(java.io.File) CommandLineLogger(com.teamscale.report.util.CommandLineLogger) TestwiseCoverageReportWriter(com.teamscale.report.testwise.TestwiseCoverageReportWriter) JaCoCoTestwiseReportGenerator(com.teamscale.report.testwise.jacoco.JaCoCoTestwiseReportGenerator)

Aggregations

Benchmark (com.teamscale.jacoco.agent.util.Benchmark)3 File (java.io.File)3 EmptyReportException (com.teamscale.report.jacoco.EmptyReportException)2 Dump (com.teamscale.report.jacoco.dump.Dump)2 CommandLineLogger (com.teamscale.report.util.CommandLineLogger)2 ILogger (com.teamscale.report.util.ILogger)2 TestDetails (com.teamscale.client.TestDetails)1 CoverageFile (com.teamscale.report.jacoco.CoverageFile)1 JaCoCoXmlReportGenerator (com.teamscale.report.jacoco.JaCoCoXmlReportGenerator)1 TestwiseCoverageReportWriter (com.teamscale.report.testwise.TestwiseCoverageReportWriter)1 JaCoCoTestwiseReportGenerator (com.teamscale.report.testwise.jacoco.JaCoCoTestwiseReportGenerator)1 TestExecution (com.teamscale.report.testwise.model.TestExecution)1 TestInfoFactory (com.teamscale.report.testwise.model.factory.TestInfoFactory)1 IOException (java.io.IOException)1 ExecutionDataStore (org.jacoco.core.data.ExecutionDataStore)1 SessionInfo (org.jacoco.core.data.SessionInfo)1 ExecFileLoader (org.jacoco.core.tools.ExecFileLoader)1 Logger (org.slf4j.Logger)1