use of org.jacoco.core.data.ExecutionDataReader 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);
}
}
Aggregations