use of com.intellij.rt.coverage.data.LineData 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.LineData in project intellij-community by JetBrains.
the class SimpleCoverageAnnotator method fileInfoForCoveredFile.
@Nullable
private FileCoverageInfo fileInfoForCoveredFile(@NotNull final ClassData classData) {
final Object[] lines = classData.getLines();
// class data lines = [0, 1, ... count] but first element with index = #0 is fake and isn't
// used thus count = length = 1
final int count = lines.length - 1;
if (count == 0) {
return null;
}
final FileCoverageInfo info = new FileCoverageInfo();
info.coveredLineCount = 0;
info.totalLineCount = 0;
// let's count covered lines
for (int i = 1; i <= count; i++) {
final LineData lineData = classData.getLineData(i);
processLineData(info, lineData);
}
return info;
}
use of com.intellij.rt.coverage.data.LineData 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;
}
use of com.intellij.rt.coverage.data.LineData in project Perl5-IDEA by Camelcade.
the class PerlCoverageRunner method parsePerlFileData.
@NotNull
private static ProjectData parsePerlFileData(@NotNull PerlFileData[] filesData) {
ProjectData projectData = new ProjectData();
for (PerlFileData perlFileData : filesData) {
if (StringUtil.isEmpty(perlFileData.name) || perlFileData.lines == null) {
continue;
}
ClassData classData = projectData.getOrCreateClassData(FileUtil.toSystemIndependentName(perlFileData.name));
Set<Map.Entry<Integer, PerlLineData>> linesEntries = perlFileData.lines.entrySet();
Integer maxLineNumber = linesEntries.stream().map(Map.Entry::getKey).max(Integer::compare).orElse(0);
LineData[] linesData = new LineData[maxLineNumber + 1];
for (Map.Entry<Integer, PerlLineData> lineEntry : linesEntries) {
PerlLineData perlLineData = lineEntry.getValue();
final Integer lineNumber = lineEntry.getKey();
LineData lineData = new LineData(lineNumber, null) {
@Override
public int getStatus() {
if (perlLineData.cover == 0) {
return LineCoverage.NONE;
} else if (perlLineData.cover < perlLineData.data) {
return LineCoverage.PARTIAL;
}
return LineCoverage.FULL;
}
};
lineData.setHits(perlLineData.cover);
linesData[lineNumber] = lineData;
}
classData.setLines(linesData);
}
return projectData;
}
use of com.intellij.rt.coverage.data.LineData in project intellij by bazelbuild.
the class BlazeCoverageRunnerTest method testIgnoreUnrecognizedPrefixes.
@Test
public void testIgnoreUnrecognizedPrefixes() throws IOException {
ProjectData data = BlazeCoverageRunner.parseCoverage(mockResolver, inputStream("SF:path/to/file.txt", "DA:4,0", "DA:8,0", "FS:0", "unrecognized junk", "DA:9,1", "DA:23,3", "end_of_record"));
assertThat(data.getClasses()).hasSize(1);
LineData[] lines = (LineData[]) data.getClassData("/root/path/to/file.txt").getLines();
assertThat(lines).hasLength(24);
assertEquals(lines[4], lineData(4, 0));
assertEquals(lines[9], lineData(9, 1));
assertEquals(lines[23], lineData(23, 3));
}
Aggregations