use of com.intellij.rt.coverage.data.ProjectData in project intellij-community by JetBrains.
the class IDEACoverageRunner method loadCoverageData.
public ProjectData loadCoverageData(@NotNull final File sessionDataFile, @Nullable final CoverageSuite coverageSuite) {
ProjectData projectData = ProjectDataLoader.load(sessionDataFile);
File sourceMapFile = new File(JavaCoverageEnabledConfiguration.getSourceMapPath(sessionDataFile.getPath()));
if (sourceMapFile.exists()) {
try {
loadSourceMap(projectData, sourceMapFile);
} catch (IOException e) {
LOG.warn("Error reading source map associated with coverage data", e);
}
}
return projectData;
}
use of com.intellij.rt.coverage.data.ProjectData in project intellij-community by JetBrains.
the class JavaCoverageEngine method generateJavaReport.
protected static void generateJavaReport(@NotNull final Project project, final File tempFile, final CoverageSuitesBundle currentSuite) {
final ExportToHTMLSettings settings = ExportToHTMLSettings.getInstance(project);
final ProjectData projectData = currentSuite.getCoverageData();
ProgressManager.getInstance().run(new Task.Backgroundable(project, "Generating coverage report ...") {
final Exception[] myExceptions = new Exception[1];
public void run(@NotNull final ProgressIndicator indicator) {
try {
new SaveHook(tempFile, true, new IdeaClassFinder(project, currentSuite)).save(projectData);
final HTMLReportBuilder builder = ReportBuilderFactory.createHTMLReportBuilder();
builder.setReportDir(new File(settings.OUTPUT_DIRECTORY));
final SourceCodeProvider sourceCodeProvider = new SourceCodeProvider() {
public String getSourceCode(@NotNull final String classname) throws IOException {
return DumbService.getInstance(project).runReadActionInSmartMode(() -> {
if (project.isDisposed())
return "";
final PsiClass psiClass = ClassUtil.findPsiClassByJVMName(PsiManager.getInstance(project), classname);
return psiClass != null ? psiClass.getNavigationElement().getContainingFile().getText() : "";
});
}
};
builder.generateReport(new IDEACoverageData(projectData, sourceCodeProvider) {
@NotNull
@Override
public Collection<ClassInfo> getClasses() {
final Collection<ClassInfo> classes = super.getClasses();
if (!currentSuite.isTrackTestFolders()) {
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
final GlobalSearchScope productionScope = GlobalSearchScopesCore.projectProductionScope(project);
for (Iterator<ClassInfo> iterator = classes.iterator(); iterator.hasNext(); ) {
final ClassInfo aClass = iterator.next();
final PsiClass psiClass = DumbService.getInstance(project).runReadActionInSmartMode(() -> {
if (project.isDisposed())
return null;
return psiFacade.findClass(aClass.getFQName(), productionScope);
});
if (psiClass == null) {
iterator.remove();
}
}
}
return classes;
}
});
} catch (IOException e) {
LOG.error(e);
} catch (ReportGenerationFailedException e) {
myExceptions[0] = e;
}
}
@Override
public void onSuccess() {
if (myExceptions[0] != null) {
Messages.showErrorDialog(project, myExceptions[0].getMessage(), CommonBundle.getErrorTitle());
return;
}
if (settings.OPEN_IN_BROWSER) {
BrowserUtil.browse(new File(settings.OUTPUT_DIRECTORY, "index.html"));
}
}
});
}
use of com.intellij.rt.coverage.data.ProjectData in project intellij-community by JetBrains.
the class PackageAnnotator method annotateFilteredClass.
public void annotateFilteredClass(PsiClass psiClass, CoverageSuitesBundle bundle, Annotator annotator) {
final ProjectData data = bundle.getCoverageData();
if (data == null)
return;
final Module module = ModuleUtil.findModuleForPsiElement(psiClass);
if (module != null) {
final boolean isInTests = ProjectRootManager.getInstance(module.getProject()).getFileIndex().isInTestSourceContent(psiClass.getContainingFile().getVirtualFile());
final CompilerModuleExtension moduleExtension = CompilerModuleExtension.getInstance(module);
final VirtualFile outputPath = isInTests ? moduleExtension.getCompilerOutputPathForTests() : moduleExtension.getCompilerOutputPath();
if (outputPath != null) {
final String qualifiedName = psiClass.getQualifiedName();
if (qualifiedName == null)
return;
final String packageVMName = StringUtil.getPackageName(qualifiedName).replace('.', '/');
final File packageRoot = findRelativeFile(packageVMName, outputPath);
if (packageRoot != null && packageRoot.exists()) {
Map<String, ClassCoverageInfo> toplevelClassCoverage = new HashMap<>();
final File[] files = packageRoot.listFiles();
if (files != null) {
for (File child : files) {
if (isClassFile(child)) {
final String childName = getClassName(child);
final String classFqVMName = packageVMName.length() > 0 ? packageVMName + "/" + childName : childName;
final String toplevelClassSrcFQName = getSourceToplevelFQName(classFqVMName);
if (toplevelClassSrcFQName.equals(qualifiedName)) {
collectClassCoverageInformation(child, psiClass, new PackageCoverageInfo(), data, toplevelClassCoverage, classFqVMName.replace("/", "."), toplevelClassSrcFQName);
}
}
}
}
for (ClassCoverageInfo coverageInfo : toplevelClassCoverage.values()) {
annotator.annotateClass(qualifiedName, coverageInfo);
}
}
}
}
}
use of com.intellij.rt.coverage.data.ProjectData in project intellij-community by JetBrains.
the class PackageAnnotator method annotate.
//get read lock myself when needed
public void annotate(final CoverageSuitesBundle suite, Annotator annotator) {
final ProjectData data = suite.getCoverageData();
if (data == null)
return;
final String qualifiedName = myPackage.getQualifiedName();
boolean filtered = false;
for (CoverageSuite coverageSuite : suite.getSuites()) {
if (((JavaCoverageSuite) coverageSuite).isPackageFiltered(qualifiedName)) {
filtered = true;
break;
}
}
if (!filtered)
return;
final GlobalSearchScope scope = suite.getSearchScope(myProject);
final Module[] modules = myCoverageManager.doInReadActionIfProjectOpen(() -> ModuleManager.getInstance(myProject).getModules());
if (modules == null)
return;
Map<String, PackageCoverageInfo> packageCoverageMap = new HashMap<>();
Map<String, PackageCoverageInfo> flattenPackageCoverageMap = new HashMap<>();
for (final Module module : modules) {
if (!scope.isSearchInModuleContent(module))
continue;
final String rootPackageVMName = qualifiedName.replaceAll("\\.", "/");
final VirtualFile output = myCoverageManager.doInReadActionIfProjectOpen(() -> CompilerModuleExtension.getInstance(module).getCompilerOutputPath());
if (output != null) {
File outputRoot = findRelativeFile(rootPackageVMName, output);
if (outputRoot.exists()) {
collectCoverageInformation(outputRoot, packageCoverageMap, flattenPackageCoverageMap, data, rootPackageVMName, annotator, module, suite.isTrackTestFolders(), false);
}
}
if (suite.isTrackTestFolders()) {
final VirtualFile testPackageRoot = myCoverageManager.doInReadActionIfProjectOpen(() -> CompilerModuleExtension.getInstance(module).getCompilerOutputPathForTests());
if (testPackageRoot != null) {
final File outputRoot = findRelativeFile(rootPackageVMName, testPackageRoot);
if (outputRoot.exists()) {
collectCoverageInformation(outputRoot, packageCoverageMap, flattenPackageCoverageMap, data, rootPackageVMName, annotator, module, suite.isTrackTestFolders(), true);
}
}
}
}
for (Map.Entry<String, PackageCoverageInfo> entry : packageCoverageMap.entrySet()) {
final String packageFQName = entry.getKey().replaceAll("/", ".");
final PackageCoverageInfo info = entry.getValue();
annotator.annotatePackage(packageFQName, info);
}
for (Map.Entry<String, PackageCoverageInfo> entry : flattenPackageCoverageMap.entrySet()) {
final String packageFQName = entry.getKey().replaceAll("/", ".");
final PackageCoverageInfo info = entry.getValue();
annotator.annotatePackage(packageFQName, info, true);
}
}
use of com.intellij.rt.coverage.data.ProjectData in project intellij-community by JetBrains.
the class CoverageSuitesBundle method getCoverageData.
@Nullable
public ProjectData getCoverageData() {
final ProjectData projectData = myData.get();
if (projectData != null)
return projectData;
ProjectData data = new ProjectData();
for (CoverageSuite suite : mySuites) {
final ProjectData coverageData = suite.getCoverageData(null);
if (coverageData != null) {
data.merge(coverageData);
}
}
myData = new SoftReference<>(data);
return data;
}
Aggregations