use of org.jacoco.core.analysis.CoverageBuilder in project buck by facebook.
the class ReportGenerator method analyzeStructure.
private IBundleCoverage analyzeStructure() throws IOException {
final CoverageBuilder coverageBuilder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(execFileLoader.getExecutionDataStore(), coverageBuilder);
String[] classesDirs = classesPath.split(":");
for (String classesDir : classesDirs) {
File classesDirFile = new File(classesDir);
if (classesDirFile.exists()) {
for (File clazz : FileUtils.getFiles(classesDirFile, coverageIncludes, coverageExcludes)) {
analyzer.analyzeAll(clazz);
}
}
}
return coverageBuilder.getBundle(title);
}
use of org.jacoco.core.analysis.CoverageBuilder in project jacoco by jacoco.
the class Report method analyze.
private IBundleCoverage analyze(final ExecutionDataStore data, final PrintWriter out) throws IOException {
final CoverageBuilder builder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(data, builder);
for (final File f : classfiles) {
analyzer.analyzeAll(f);
}
printNoMatchWarning(builder.getNoMatchClasses(), out);
return builder.getBundle(name);
}
use of org.jacoco.core.analysis.CoverageBuilder in project jacoco by jacoco.
the class CoreTutorial method execute.
/**
* Run this example.
*
* @throws Exception
* in case of errors
*/
public void execute() throws Exception {
final String targetName = TestTarget.class.getName();
// For instrumentation and runtime we need a IRuntime instance
// to collect execution data:
final IRuntime runtime = new LoggerRuntime();
// The Instrumenter creates a modified version of our test target class
// that contains additional probes for execution data recording:
final Instrumenter instr = new Instrumenter(runtime);
InputStream original = getTargetClass(targetName);
final byte[] instrumented = instr.instrument(original, targetName);
original.close();
// Now we're ready to run our instrumented class and need to startup the
// runtime first:
final RuntimeData data = new RuntimeData();
runtime.startup(data);
// In this tutorial we use a special class loader to directly load the
// instrumented class definition from a byte[] instances.
final MemoryClassLoader memoryClassLoader = new MemoryClassLoader();
memoryClassLoader.addDefinition(targetName, instrumented);
final Class<?> targetClass = memoryClassLoader.loadClass(targetName);
// Here we execute our test target class through its Runnable interface:
final Runnable targetInstance = (Runnable) targetClass.newInstance();
targetInstance.run();
// At the end of test execution we collect execution data and shutdown
// the runtime:
final ExecutionDataStore executionData = new ExecutionDataStore();
final SessionInfoStore sessionInfos = new SessionInfoStore();
data.collect(executionData, sessionInfos, false);
runtime.shutdown();
// Together with the original class definition we can calculate coverage
// information:
final CoverageBuilder coverageBuilder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(executionData, coverageBuilder);
original = getTargetClass(targetName);
analyzer.analyzeClass(original, targetName);
original.close();
// Let's dump some metrics and line coverage information:
for (final IClassCoverage cc : coverageBuilder.getClasses()) {
out.printf("Coverage of class %s%n", cc.getName());
printCounter("instructions", cc.getInstructionCounter());
printCounter("branches", cc.getBranchCounter());
printCounter("lines", cc.getLineCounter());
printCounter("methods", cc.getMethodCounter());
printCounter("complexity", cc.getComplexityCounter());
for (int i = cc.getFirstLine(); i <= cc.getLastLine(); i++) {
out.printf("Line %s: %s%n", Integer.valueOf(i), getColor(cc.getLine(i).getStatus()));
}
}
}
use of org.jacoco.core.analysis.CoverageBuilder in project jacoco by jacoco.
the class ReportGenerator method analyzeStructure.
private IBundleCoverage analyzeStructure() throws IOException {
final CoverageBuilder coverageBuilder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(execFileLoader.getExecutionDataStore(), coverageBuilder);
analyzer.analyzeAll(classesDirectory);
return coverageBuilder.getBundle(title);
}
use of org.jacoco.core.analysis.CoverageBuilder in project jacoco by jacoco.
the class ValidationTestBase method analyze.
private void analyze(final ExecutionDataStore store) throws IOException {
final CoverageBuilder builder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(store, builder);
for (ExecutionData data : store.getContents()) {
analyze(analyzer, data);
}
String srcName = target.getName().replace('.', '/') + ".java";
for (ISourceFileCoverage file : builder.getSourceFiles()) {
if (srcName.equals(file.getPackageName() + "/" + file.getName())) {
sourceCoverage = file;
return;
}
}
fail("No source node found for " + srcName);
}
Aggregations