Search in sources :

Example 1 with Dump

use of com.teamscale.report.jacoco.dump.Dump 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 Dump

use of com.teamscale.report.jacoco.dump.Dump in project teamscale-jacoco-agent by cqse.

the class JacocoRuntimeController method dumpAndReset.

/**
 * Dumps execution data and resets it.
 *
 * @throws DumpException if dumping fails. This should never happen in real life. Dumping should simply be retried
 *                       later if this ever happens.
 */
public Dump dumpAndReset() throws DumpException {
    byte[] binaryData = agent.getExecutionData(true);
    try (ByteArrayInputStream inputStream = new ByteArrayInputStream(binaryData)) {
        ExecutionDataReader reader = new ExecutionDataReader(inputStream);
        ExecutionDataStore store = new ExecutionDataStore();
        reader.setExecutionDataVisitor(store::put);
        SessionInfoVisitor sessionInfoVisitor = new SessionInfoVisitor();
        reader.setSessionInfoVisitor(sessionInfoVisitor);
        reader.read();
        return new Dump(sessionInfoVisitor.sessionInfo, store);
    } catch (IOException e) {
        throw new DumpException("should never happen for the ByteArrayInputStream", e);
    }
}
Also used : ISessionInfoVisitor(org.jacoco.core.data.ISessionInfoVisitor) Dump(com.teamscale.report.jacoco.dump.Dump) ByteArrayInputStream(java.io.ByteArrayInputStream) ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) IOException(java.io.IOException) ExecutionDataReader(org.jacoco.core.data.ExecutionDataReader)

Example 3 with Dump

use of com.teamscale.report.jacoco.dump.Dump in project teamscale-jacoco-agent by cqse.

the class JaCoCoXmlReportGeneratorTest method createDummyDump.

/**
 * Creates a dummy dump with the specified class ID. The class ID can currently be calculated with {@link
 * org.jacoco.core.internal.data.CRC64#classId(byte[])}. This might change in the future, as it's considered an
 * implementation detail of JaCoCo (c.f. <a href="https://www.jacoco.org/jacoco/trunk/doc/classids.html">
 * https://www.jacoco.org/jacoco/trunk/doc/classids.html</a>)
 */
private static Dump createDummyDump(long classId) {
    ExecutionDataStore store = new ExecutionDataStore();
    store.put(new ExecutionData(classId, "TestClass", new boolean[] { true, true, true }));
    SessionInfo info = new SessionInfo("session-id", 124L, 125L);
    return new Dump(info, store);
}
Also used : Dump(com.teamscale.report.jacoco.dump.Dump) ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) SessionInfo(org.jacoco.core.data.SessionInfo) ExecutionData(org.jacoco.core.data.ExecutionData)

Example 4 with Dump

use of com.teamscale.report.jacoco.dump.Dump 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 5 with Dump

use of com.teamscale.report.jacoco.dump.Dump in project teamscale-jacoco-agent by cqse.

the class CoverageViaHttpStrategy method testEnd.

@Override
public String testEnd(String test, TestExecution testExecution) throws JacocoRuntimeController.DumpException, CoverageGenerationException {
    super.testEnd(test, testExecution);
    TestInfoBuilder builder = new TestInfoBuilder(test);
    Dump dump = controller.dumpAndReset();
    builder.setCoverage(reportGenerator.convert(dump));
    if (testExecution != null) {
        builder.setExecution(testExecution);
    }
    TestInfo testInfo = builder.build();
    String testInfoJson = testInfoJsonAdapter.toJson(testInfo);
    logger.debug("Generated test info {}", testInfoJson);
    return testInfoJson;
}
Also used : Dump(com.teamscale.report.jacoco.dump.Dump) TestInfoBuilder(com.teamscale.report.testwise.model.builder.TestInfoBuilder) TestInfo(com.teamscale.report.testwise.model.TestInfo)

Aggregations

Dump (com.teamscale.report.jacoco.dump.Dump)5 ExecutionDataStore (org.jacoco.core.data.ExecutionDataStore)3 Benchmark (com.teamscale.jacoco.agent.util.Benchmark)2 EmptyReportException (com.teamscale.report.jacoco.EmptyReportException)2 File (java.io.File)2 IOException (java.io.IOException)2 SessionInfo (org.jacoco.core.data.SessionInfo)2 CoverageFile (com.teamscale.report.jacoco.CoverageFile)1 JaCoCoXmlReportGenerator (com.teamscale.report.jacoco.JaCoCoXmlReportGenerator)1 TestInfo (com.teamscale.report.testwise.model.TestInfo)1 TestInfoBuilder (com.teamscale.report.testwise.model.builder.TestInfoBuilder)1 CommandLineLogger (com.teamscale.report.util.CommandLineLogger)1 ILogger (com.teamscale.report.util.ILogger)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ExecutionData (org.jacoco.core.data.ExecutionData)1 ExecutionDataReader (org.jacoco.core.data.ExecutionDataReader)1 ISessionInfoVisitor (org.jacoco.core.data.ISessionInfoVisitor)1 ExecFileLoader (org.jacoco.core.tools.ExecFileLoader)1 Logger (org.slf4j.Logger)1