use of com.intellij.rt.coverage.data.ProjectData 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.ProjectData in project intellij-community by JetBrains.
the class JavaCoverageSuite method getCoverageData.
@Nullable
public ProjectData getCoverageData(final CoverageDataManager coverageDataManager) {
final ProjectData data = getCoverageData();
if (data != null)
return data;
ProjectData map = loadProjectInfo();
if (mySuiteToMerge != null) {
JavaCoverageSuite toMerge = null;
final CoverageSuite[] suites = coverageDataManager.getSuites();
for (CoverageSuite suite : suites) {
if (Comparing.strEqual(suite.getPresentableName(), mySuiteToMerge)) {
if (!Comparing.strEqual(((JavaCoverageSuite) suite).getSuiteToMerge(), getPresentableName())) {
toMerge = (JavaCoverageSuite) suite;
}
break;
}
}
if (toMerge != null) {
final ProjectData projectInfo = toMerge.getCoverageData(coverageDataManager);
if (map != null) {
map.merge(projectInfo);
} else {
map = projectInfo;
}
}
}
setCoverageData(map);
return map;
}
use of com.intellij.rt.coverage.data.ProjectData 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.ProjectData 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.ProjectData in project intellij-plugins by JetBrains.
the class KarmaCoverageEngine method findRootDir.
/**
* Finds a root directory for Coverage toolwindow view.
* Returns a content root containing at least one covered file.
*/
@Nullable
private static VirtualFile findRootDir(@NotNull final Project project, @NotNull final CoverageSuitesBundle suitesBundle) {
return ReadAction.compute(() -> {
CoverageDataManager coverageDataManager = CoverageDataManager.getInstance(project);
for (CoverageSuite suite : suitesBundle.getSuites()) {
ProjectData data = suite.getCoverageData(coverageDataManager);
if (data != null) {
for (Object key : data.getClasses().keySet()) {
if (key instanceof String) {
String path = (String) key;
VirtualFile file = VfsUtil.findFileByIoFile(new File(path), false);
if (file != null && file.isValid()) {
ProjectFileIndex projectFileIndex = ProjectFileIndex.SERVICE.getInstance(project);
VirtualFile contentRoot = projectFileIndex.getContentRootForFile(file);
if (contentRoot != null && contentRoot.isDirectory() && contentRoot.isValid()) {
return contentRoot;
}
}
}
}
}
}
return null;
});
}
Aggregations