use of org.jacoco.core.data.ISessionInfoVisitor in project intellij-community by JetBrains.
the class JaCoCoCoverageRunner method loadExecutionData.
private static void loadExecutionData(@NotNull final File sessionDataFile, ProjectData data, @NotNull Project project) throws IOException {
final ExecutionDataStore executionDataStore = new ExecutionDataStore();
FileInputStream fis = null;
try {
fis = new FileInputStream(sessionDataFile);
final ExecutionDataReader executionDataReader = new ExecutionDataReader(fis);
executionDataReader.setExecutionDataVisitor(executionDataStore);
executionDataReader.setSessionInfoVisitor(new ISessionInfoVisitor() {
public void visitSessionInfo(SessionInfo info) {
System.out.println(info.toString());
}
});
while (executionDataReader.read()) {
}
} finally {
if (fis != null) {
fis.close();
}
}
final CoverageBuilder coverageBuilder = new CoverageBuilder();
final Analyzer analyzer = new Analyzer(executionDataStore, coverageBuilder);
final Module[] modules = ModuleManager.getInstance(project).getModules();
for (Module module : modules) {
final CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module);
if (compilerModuleExtension != null) {
final VirtualFile[] roots = compilerModuleExtension.getOutputRoots(true);
for (VirtualFile root : roots) {
analyzer.analyzeAll(VfsUtil.virtualToIoFile(root));
}
}
}
for (IClassCoverage classCoverage : coverageBuilder.getClasses()) {
String className = classCoverage.getName();
className = className.replace('\\', '.').replace('/', '.');
final ClassData classData = data.getOrCreateClassData(className);
final Collection<IMethodCoverage> methods = classCoverage.getMethods();
LineData[] lines = new LineData[classCoverage.getLastLine() + 1];
for (IMethodCoverage method : methods) {
final String desc = method.getName() + method.getDesc();
// Line numbers are 1-based here.
final int firstLine = method.getFirstLine();
final int lastLine = method.getLastLine();
for (int i = firstLine; i <= lastLine; i++) {
final ILine methodLine = method.getLine(i);
final int methodLineStatus = methodLine.getStatus();
if (methodLineStatus == ICounter.EMPTY)
continue;
final LineData lineData = new LineData(i, desc) {
@Override
public int getStatus() {
switch(methodLineStatus) {
case ICounter.FULLY_COVERED:
return LineCoverage.FULL;
case ICounter.PARTLY_COVERED:
return LineCoverage.PARTIAL;
default:
return LineCoverage.NONE;
}
}
};
lineData.setHits(methodLineStatus == ICounter.FULLY_COVERED || methodLineStatus == ICounter.PARTLY_COVERED ? 1 : 0);
lines[i] = lineData;
}
}
classData.setLines(lines);
}
}
use of org.jacoco.core.data.ISessionInfoVisitor in project jacoco by jacoco.
the class ExecInfo method dump.
private void dump(final File file, final PrintWriter out) throws IOException {
out.printf("[INFO] Loading exec file %s.%n", file);
out.println("CLASS ID HITS/PROBES CLASS NAME");
final FileInputStream in = new FileInputStream(file);
final ExecutionDataReader reader = new ExecutionDataReader(in);
reader.setSessionInfoVisitor(new ISessionInfoVisitor() {
public void visitSessionInfo(final SessionInfo info) {
out.printf("Session \"%s\": %s - %s%n", info.getId(), new Date(info.getStartTimeStamp()), new Date(info.getDumpTimeStamp()));
}
});
reader.setExecutionDataVisitor(new IExecutionDataVisitor() {
public void visitClassExecution(final ExecutionData data) {
out.printf("%016x %3d of %3d %s%n", Long.valueOf(data.getId()), Integer.valueOf(getHitCount(data.getProbes())), Integer.valueOf(data.getProbes().length), data.getName());
}
});
reader.read();
in.close();
out.println();
}
use of org.jacoco.core.data.ISessionInfoVisitor in project jacoco by jacoco.
the class ExecDump method dump.
private void dump(final String file) throws IOException {
out.printf("exec file: %s%n", file);
out.println("CLASS ID HITS/PROBES CLASS NAME");
final FileInputStream in = new FileInputStream(file);
final ExecutionDataReader reader = new ExecutionDataReader(in);
reader.setSessionInfoVisitor(new ISessionInfoVisitor() {
public void visitSessionInfo(final SessionInfo info) {
out.printf("Session \"%s\": %s - %s%n", info.getId(), new Date(info.getStartTimeStamp()), new Date(info.getDumpTimeStamp()));
}
});
reader.setExecutionDataVisitor(new IExecutionDataVisitor() {
public void visitClassExecution(final ExecutionData data) {
out.printf("%016x %3d of %3d %s%n", Long.valueOf(data.getId()), Integer.valueOf(getHitCount(data.getProbes())), Integer.valueOf(data.getProbes().length), data.getName());
}
});
reader.read();
in.close();
out.println();
}
use of org.jacoco.core.data.ISessionInfoVisitor in project sonar-java by SonarSource.
the class JaCoCoReportMerger method mergeReports.
/**
* Merge all reports in reportOverall.
* @param reportOverall destination file of merge.
* @param reports files to be merged.
*/
public static void mergeReports(File reportOverall, File... reports) {
ExecutionDataVisitor edv = new ExecutionDataVisitor();
boolean isCurrentVersionFormat = loadSourceFiles(edv, reports);
try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(reportOverall))) {
Object visitor;
if (isCurrentVersionFormat) {
visitor = new ExecutionDataWriter(outputStream);
} else {
visitor = new org.jacoco.previous.core.data.ExecutionDataWriter(outputStream);
}
for (Map.Entry<String, ExecutionDataStore> entry : edv.getSessions().entrySet()) {
SessionInfo sessionInfo = new SessionInfo(entry.getKey(), 0, 0);
((ISessionInfoVisitor) visitor).visitSessionInfo(sessionInfo);
entry.getValue().accept((IExecutionDataVisitor) visitor);
}
} catch (IOException e) {
throw new AnalysisException(String.format("Unable to write overall coverage report %s", reportOverall.getAbsolutePath()), e);
}
}
Aggregations