All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.teamscale.jacoco.agent.testimpact.CoverageViaHttpStrategy Maven / Gradle / Ivy

Go to download

JVM profiler that simplifies various aspects around recording and uploading test coverage

There is a newer version: 34.0.2
Show newest version
package com.teamscale.jacoco.agent.testimpact;

import com.teamscale.jacoco.agent.JacocoRuntimeController;
import com.teamscale.jacoco.agent.options.AgentOptions;
import com.teamscale.jacoco.agent.util.LoggingUtils;
import com.teamscale.report.jacoco.dump.Dump;
import com.teamscale.report.testwise.jacoco.JaCoCoTestwiseReportGenerator;
import com.teamscale.report.testwise.jacoco.cache.CoverageGenerationException;
import com.teamscale.report.testwise.model.TestExecution;
import com.teamscale.report.testwise.model.TestInfo;
import com.teamscale.report.testwise.model.builder.TestInfoBuilder;
import org.slf4j.Logger;

/**
 * Strategy which directly converts the collected coverage into a JSON object in place and returns the result to the
 * caller as response to the http request. If a test execution is given it is merged into the representation and
 * returned together with the coverage.
 */
public class CoverageViaHttpStrategy extends TestEventHandlerStrategyBase {

	private final Logger logger = LoggingUtils.getLogger(this);

	private final JaCoCoTestwiseReportGenerator reportGenerator;

	public CoverageViaHttpStrategy(JacocoRuntimeController controller, AgentOptions agentOptions,
								   JaCoCoTestwiseReportGenerator reportGenerator) {
		super(agentOptions, controller);
		this.reportGenerator = reportGenerator;
	}

	@Override
	public TestInfo testEnd(String test, TestExecution testExecution)
			throws JacocoRuntimeController.DumpException, CoverageGenerationException {
		super.testEnd(test, testExecution);

		TestInfoBuilder builder = new TestInfoBuilder(test);
		Dump dump = controller.dumpAndReset();
		reportGenerator.updateClassDirCache();
		builder.setCoverage(reportGenerator.convert(dump));
		if (testExecution != null) {
			builder.setExecution(testExecution);
		}
		TestInfo testInfo = builder.build();
		logger.debug("Generated test info {}", testInfo.toString());
		return testInfo;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy