use of com.intellij.rt.coverage.data.ClassData 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 com.intellij.rt.coverage.data.ClassData in project intellij-community by JetBrains.
the class CoverageDataManagerImpl method selectSubCoverage.
public void selectSubCoverage(@NotNull final CoverageSuitesBundle suite, final List<String> testNames) {
suite.restoreCoverageData();
final ProjectData data = suite.getCoverageData();
if (data == null)
return;
mySubCoverageIsActive = true;
final Map<String, Set<Integer>> executionTrace = new HashMap<>();
for (CoverageSuite coverageSuite : suite.getSuites()) {
final String fileName = coverageSuite.getCoverageDataFileName();
final File tracesDir = getTracesDirectory(fileName);
for (String testName : testNames) {
final File file = new File(tracesDir, FileUtil.sanitizeFileName(testName) + ".tr");
if (file.exists()) {
DataInputStream in = null;
try {
in = new DataInputStream(new FileInputStream(file));
int traceSize = in.readInt();
for (int i = 0; i < traceSize; i++) {
final String className = in.readUTF();
final int linesSize = in.readInt();
Set<Integer> lines = executionTrace.get(className);
if (lines == null) {
lines = new HashSet<>();
executionTrace.put(className, lines);
}
for (int l = 0; l < linesSize; l++) {
lines.add(in.readInt());
}
}
} catch (Exception e) {
LOG.error(e);
} finally {
try {
in.close();
} catch (IOException e) {
LOG.error(e);
}
}
}
}
}
final ProjectData projectData = new ProjectData();
for (String className : executionTrace.keySet()) {
ClassData loadedClassData = projectData.getClassData(className);
if (loadedClassData == null) {
loadedClassData = projectData.getOrCreateClassData(className);
}
final Set<Integer> lineNumbers = executionTrace.get(className);
final ClassData oldData = data.getClassData(className);
LOG.assertTrue(oldData != null, "missed className: \"" + className + "\"");
final Object[] oldLines = oldData.getLines();
LOG.assertTrue(oldLines != null);
int maxNumber = oldLines.length;
for (Integer lineNumber : lineNumbers) {
if (lineNumber >= maxNumber) {
maxNumber = lineNumber + 1;
}
}
final LineData[] lines = new LineData[maxNumber];
for (Integer line : lineNumbers) {
final int lineIdx = line.intValue() - 1;
String methodSig = null;
if (lineIdx < oldData.getLines().length) {
final LineData oldLineData = oldData.getLineData(lineIdx);
if (oldLineData != null) {
methodSig = oldLineData.getMethodSignature();
}
}
final LineData lineData = new LineData(lineIdx, methodSig);
if (methodSig != null) {
loadedClassData.registerMethodSignature(lineData);
}
lineData.setStatus(LineCoverage.FULL);
lines[lineIdx] = lineData;
}
loadedClassData.setLines(lines);
}
suite.setCoverageData(projectData);
renewCoverageData(suite);
}
use of com.intellij.rt.coverage.data.ClassData in project intellij-community by JetBrains.
the class CoberturaLoaderUtil method load.
public static ProjectData load(final File sessionDataFile) {
ProjectData projectInfo = new ProjectData();
DataInputStream dataFile = null;
try {
dataFile = new DataInputStream(new FileInputStream(sessionDataFile));
int classesCount = dataFile.read();
for (int i = 0; i < classesCount; i++) {
final String classFQName = dataFile.readUTF();
//sourcefilename
dataFile.readUTF();
final ClassData classData = projectInfo.getOrCreateClassData(classFQName);
final int numberOfLines = dataFile.read();
for (int l = 0; l < numberOfLines; l++) {
final int lineNumber = dataFile.read();
//todo classData.getOrCreateLine(lineNumber, dataFile.readUTF() + dataFile.readUTF());
final LineData lineData = null;
long hits = dataFile.readLong();
final int jumpsNumber = dataFile.read();
int trueHits = 0;
int falseHits = 0;
int totalHits = 0;
for (int j = 0; j < jumpsNumber; j++) {
//jump number
dataFile.read();
totalHits++;
if (dataFile.readLong() > 0)
trueHits++;
totalHits++;
if (dataFile.readLong() > 0)
falseHits++;
}
int defaultHitsNumber = 0;
int branchHitNumber = 0;
final int switchNumber = dataFile.read();
for (int s = 0; s < switchNumber; s++) {
//switch number
dataFile.read();
//number of keys
dataFile.read();
long defaultHits = dataFile.readLong();
if (defaultHits > 0)
defaultHitsNumber++;
int coveredSwitchBranches = 0;
final int switchBranchesNumber = dataFile.read();
for (int b = 0; b < switchBranchesNumber; b++) {
final long branchHit = dataFile.readLong();
if (branchHit > 0)
coveredSwitchBranches++;
}
if (coveredSwitchBranches == switchBranchesNumber)
branchHitNumber++;
}
if (hits > 0) {
if (totalHits == trueHits + falseHits) {
if (defaultHitsNumber == switchNumber && branchHitNumber == switchNumber) {
lineData.setStatus(LineCoverage.FULL);
continue;
}
}
lineData.setStatus(LineCoverage.PARTIAL);
} else {
lineData.setStatus(LineCoverage.NONE);
}
}
}
} catch (IOException e) {
LOG.info(e);
} finally {
if (dataFile != null) {
try {
dataFile.close();
} catch (IOException e) {
LOG.error(e);
}
}
}
return projectInfo;
}
use of com.intellij.rt.coverage.data.ClassData in project intellij-community by JetBrains.
the class SimpleCoverageAnnotator method collectBaseFileCoverage.
@Nullable
protected FileCoverageInfo collectBaseFileCoverage(@NotNull final VirtualFile file, @NotNull final Annotator annotator, @NotNull final ProjectData projectData, @NotNull final Map<String, String> normalizedFiles2Files) {
final String filePath = normalizeFilePath(file.getPath());
// process file
final FileCoverageInfo info;
final ClassData classData = getClassData(filePath, projectData, normalizedFiles2Files);
if (classData != null) {
// fill info from coverage data
info = fileInfoForCoveredFile(classData);
} else {
// file wasn't mentioned in coverage information
info = fillInfoForUncoveredFile(VfsUtilCore.virtualToIoFile(file));
}
if (info != null) {
annotator.annotateFile(filePath, info);
}
return info;
}
use of com.intellij.rt.coverage.data.ClassData in project intellij-plugins by JetBrains.
the class DartCoverageRunner method doLoadCoverageData.
@Nullable
private static ProjectData doLoadCoverageData(@NotNull final File sessionDataFile, @NotNull final DartCoverageSuite coverageSuite) {
final ProcessHandler coverageProcess = coverageSuite.getCoverageProcess();
// coverageProcess == null means that we are switching to data gathered earlier
if (coverageProcess != null) {
for (int i = 0; i < 100; ++i) {
ProgressManager.checkCanceled();
if (coverageProcess.waitFor(100)) {
break;
}
}
if (!coverageProcess.isProcessTerminated()) {
coverageProcess.destroyProcess();
return null;
}
}
final Project project = coverageSuite.getProject();
final String contextFilePath = coverageSuite.getContextFilePath();
if (project == null || contextFilePath == null) {
return null;
}
final String contextId = DartAnalysisServerService.getInstance(project).execution_createContext(contextFilePath);
if (contextId == null) {
return null;
}
final ProjectData projectData = new ProjectData();
try {
DartCoverageData data = new Gson().fromJson(new BufferedReader(new FileReader(sessionDataFile)), DartCoverageData.class);
if (data == null) {
LOG.warn("Coverage file does not contain valid data.");
return null;
}
for (Map.Entry<String, SortedMap<Integer, Integer>> entry : data.getMergedDartFileCoverageData().entrySet()) {
ProgressManager.checkCanceled();
String filePath = getFileForUri(project, contextId, entry.getKey());
if (filePath == null) {
// File is not found.
continue;
}
SortedMap<Integer, Integer> lineHits = entry.getValue();
ClassData classData = projectData.getOrCreateClassData(filePath);
if (lineHits.size() == 0) {
classData.setLines(new LineData[1]);
continue;
}
LineData[] lines = new LineData[lineHits.lastKey() + 1];
for (Map.Entry<Integer, Integer> hit : lineHits.entrySet()) {
LineData lineData = new LineData(hit.getKey(), null);
lineData.setHits(hit.getValue());
lines[hit.getKey()] = lineData;
}
classData.setLines(lines);
}
} catch (FileNotFoundException | JsonSyntaxException e) {
LOG.warn(e);
} finally {
DartAnalysisServerService.getInstance(project).execution_deleteContext(contextId);
}
return projectData;
}
Aggregations