Search in sources :

Example 1 with ExecutionDataStore

use of org.jacoco.core.data.ExecutionDataStore 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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ISessionInfoVisitor(org.jacoco.core.data.ISessionInfoVisitor) SessionInfo(org.jacoco.core.data.SessionInfo) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension) FileInputStream(java.io.FileInputStream) ExecutionDataReader(org.jacoco.core.data.ExecutionDataReader) LineData(com.intellij.rt.coverage.data.LineData) ClassData(com.intellij.rt.coverage.data.ClassData) ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) Module(com.intellij.openapi.module.Module)

Example 2 with ExecutionDataStore

use of org.jacoco.core.data.ExecutionDataStore in project powermock by powermock.

the class JacocoCoverageTest method getExecutionDataStore.

private ExecutionDataStore getExecutionDataStore(RuntimeData data) {
    final ExecutionDataStore executionData = new ExecutionDataStore();
    final SessionInfoStore sessionInfos = new SessionInfoStore();
    data.collect(executionData, sessionInfos, false);
    return executionData;
}
Also used : ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) SessionInfoStore(org.jacoco.core.data.SessionInfoStore)

Aggregations

ExecutionDataStore (org.jacoco.core.data.ExecutionDataStore)2 Module (com.intellij.openapi.module.Module)1 CompilerModuleExtension (com.intellij.openapi.roots.CompilerModuleExtension)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ClassData (com.intellij.rt.coverage.data.ClassData)1 LineData (com.intellij.rt.coverage.data.LineData)1 FileInputStream (java.io.FileInputStream)1 ExecutionDataReader (org.jacoco.core.data.ExecutionDataReader)1 ISessionInfoVisitor (org.jacoco.core.data.ISessionInfoVisitor)1 SessionInfo (org.jacoco.core.data.SessionInfo)1 SessionInfoStore (org.jacoco.core.data.SessionInfoStore)1