Search in sources :

Example 11 with ClassData

use of com.intellij.rt.coverage.data.ClassData in project intellij-plugins by JetBrains.

the class JstdCoverageEngine method generateReport.

@Override
public void generateReport(@NotNull Project project, @NotNull DataContext dataContext, @NotNull CoverageSuitesBundle currentSuiteBundle) {
    CoverageReport coverageReport = new CoverageReport();
    for (CoverageSuite suite : currentSuiteBundle.getSuites()) {
        ProjectData projectData = suite.getCoverageData(CoverageDataManager.getInstance(project));
        if (projectData != null) {
            @SuppressWarnings("unchecked") Map<String, ClassData> classDataMap = projectData.getClasses();
            for (Map.Entry<String, ClassData> classDataEntry : classDataMap.entrySet()) {
                String fileName = classDataEntry.getKey();
                ClassData classData = classDataEntry.getValue();
                List<CoverageReport.LineHits> lineHitsList = convertClassDataToLineHits(classData);
                coverageReport.mergeFileReport(fileName, lineHitsList);
            }
        }
    }
    final ExportToHTMLSettings settings = ExportToHTMLSettings.getInstance(project);
    final File outputDir = new File(settings.OUTPUT_DIRECTORY);
    FileUtil.createDirectory(outputDir);
    String outputFileName = getOutputFileName(currentSuiteBundle);
    String title = "Coverage Report Generation";
    try {
        File output = new File(outputDir, outputFileName);
        CoverageSerializationUtils.writeLCOV(coverageReport, output);
        refresh(output);
        String url = "http://ltp.sourceforge.net/coverage/lcov.php";
        Messages.showInfoMessage("<html>Coverage report has been successfully saved as '" + outputFileName + "' file.<br>Use <a href='" + url + "'>" + url + "</a>" + " to generate HTML output." + "</html>", title);
    } catch (IOException e) {
        LOG.warn("Can not export coverage data", e);
        Messages.showErrorDialog("Can not generate coverage report: " + e.getMessage(), title);
    }
}
Also used : CoverageReport(com.google.jstestdriver.idea.rt.coverage.CoverageReport) IOException(java.io.IOException) ExportToHTMLSettings(com.intellij.codeEditor.printing.ExportToHTMLSettings) ClassData(com.intellij.rt.coverage.data.ClassData) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) File(java.io.File) ProjectData(com.intellij.rt.coverage.data.ProjectData)

Example 12 with ClassData

use of com.intellij.rt.coverage.data.ClassData in project intellij-plugins by JetBrains.

the class JstdCoverageRunner method readProjectData.

@NotNull
private static ProjectData readProjectData(@NotNull File dataFile) throws IOException {
    CoverageReport report = CoverageSerializationUtils.readLCOV(dataFile);
    ProjectData projectData = new ProjectData();
    for (Map.Entry<String, List<CoverageReport.LineHits>> entry : report.getInfo().entrySet()) {
        String filePath = SimpleCoverageAnnotator.getFilePath(entry.getKey());
        ClassData classData = projectData.getOrCreateClassData(filePath);
        int max = 0;
        List<CoverageReport.LineHits> lineHitsList = entry.getValue();
        if (lineHitsList.size() > 0) {
            CoverageReport.LineHits lastLineHits = lineHitsList.get(lineHitsList.size() - 1);
            max = lastLineHits.getLineNumber();
        }
        LineData[] lines = new LineData[max + 1];
        for (CoverageReport.LineHits lineHits : lineHitsList) {
            LineData lineData = new LineData(lineHits.getLineNumber(), null);
            lineData.setHits(lineHits.getHits());
            lines[lineHits.getLineNumber()] = lineData;
        }
        classData.setLines(lines);
    }
    return projectData;
}
Also used : CoverageReport(com.google.jstestdriver.idea.rt.coverage.CoverageReport) LineData(com.intellij.rt.coverage.data.LineData) ClassData(com.intellij.rt.coverage.data.ClassData) List(java.util.List) Map(java.util.Map) ProjectData(com.intellij.rt.coverage.data.ProjectData) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with ClassData

use of com.intellij.rt.coverage.data.ClassData in project intellij-plugins by JetBrains.

the class KarmaCoverageRunner method readProjectData.

@NotNull
private static ProjectData readProjectData(@NotNull File dataFile, @NotNull File basePath) throws IOException {
    ProjectData projectData = new ProjectData();
    LcovCoverageReport report = CoverageSerializationUtils.readLCOV(basePath, dataFile);
    for (Map.Entry<String, List<LcovCoverageReport.LineHits>> entry : report.getInfo().entrySet()) {
        String filePath = entry.getKey();
        ClassData classData = projectData.getOrCreateClassData(filePath);
        int max = 0;
        List<LcovCoverageReport.LineHits> lineHitsList = entry.getValue();
        if (lineHitsList.size() > 0) {
            LcovCoverageReport.LineHits lastLineHits = lineHitsList.get(lineHitsList.size() - 1);
            max = lastLineHits.getLineNumber();
        }
        LineData[] lines = new LineData[max + 1];
        for (LcovCoverageReport.LineHits lineHits : lineHitsList) {
            LineData lineData = new LineData(lineHits.getLineNumber(), null);
            lineData.setHits(lineHits.getHits());
            lines[lineHits.getLineNumber()] = lineData;
        }
        classData.setLines(lines);
    }
    return projectData;
}
Also used : LcovCoverageReport(com.intellij.javascript.testFramework.coverage.LcovCoverageReport) LineData(com.intellij.rt.coverage.data.LineData) ClassData(com.intellij.rt.coverage.data.ClassData) List(java.util.List) Map(java.util.Map) ProjectData(com.intellij.rt.coverage.data.ProjectData) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ClassData (com.intellij.rt.coverage.data.ClassData)13 LineData (com.intellij.rt.coverage.data.LineData)9 ProjectData (com.intellij.rt.coverage.data.ProjectData)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Map (java.util.Map)4 Nullable (org.jetbrains.annotations.Nullable)4 PsiFile (com.intellij.psi.PsiFile)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 CoverageReport (com.google.jstestdriver.idea.rt.coverage.CoverageReport)2 Module (com.intellij.openapi.module.Module)2 DataInputStream (java.io.DataInputStream)2 List (java.util.List)2 NotNull (org.jetbrains.annotations.NotNull)2 Gson (com.google.gson.Gson)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 ExportToHTMLSettings (com.intellij.codeEditor.printing.ExportToHTMLSettings)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1 LcovCoverageReport (com.intellij.javascript.testFramework.coverage.LcovCoverageReport)1