Search in sources :

Example 1 with IExecutionDataVisitor

use of org.jacoco.core.data.IExecutionDataVisitor in project jacoco by jacoco.

the class ExecInfo method dump.

private void dump(final File file, final PrintWriter out) throws IOException {
    out.printf("[INFO] Loading exec file %s.%n", file);
    out.println("CLASS ID         HITS/PROBES   CLASS NAME");
    final FileInputStream in = new FileInputStream(file);
    final ExecutionDataReader reader = new ExecutionDataReader(in);
    reader.setSessionInfoVisitor(new ISessionInfoVisitor() {

        public void visitSessionInfo(final SessionInfo info) {
            out.printf("Session \"%s\": %s - %s%n", info.getId(), new Date(info.getStartTimeStamp()), new Date(info.getDumpTimeStamp()));
        }
    });
    reader.setExecutionDataVisitor(new IExecutionDataVisitor() {

        public void visitClassExecution(final ExecutionData data) {
            out.printf("%016x  %3d of %3d   %s%n", Long.valueOf(data.getId()), Integer.valueOf(getHitCount(data.getProbes())), Integer.valueOf(data.getProbes().length), data.getName());
        }
    });
    reader.read();
    in.close();
    out.println();
}
Also used : ISessionInfoVisitor(org.jacoco.core.data.ISessionInfoVisitor) SessionInfo(org.jacoco.core.data.SessionInfo) IExecutionDataVisitor(org.jacoco.core.data.IExecutionDataVisitor) FileInputStream(java.io.FileInputStream) Date(java.util.Date) ExecutionDataReader(org.jacoco.core.data.ExecutionDataReader) ExecutionData(org.jacoco.core.data.ExecutionData)

Example 2 with IExecutionDataVisitor

use of org.jacoco.core.data.IExecutionDataVisitor in project jacoco by jacoco.

the class ExecDump method dump.

private void dump(final String file) throws IOException {
    out.printf("exec file: %s%n", file);
    out.println("CLASS ID         HITS/PROBES   CLASS NAME");
    final FileInputStream in = new FileInputStream(file);
    final ExecutionDataReader reader = new ExecutionDataReader(in);
    reader.setSessionInfoVisitor(new ISessionInfoVisitor() {

        public void visitSessionInfo(final SessionInfo info) {
            out.printf("Session \"%s\": %s - %s%n", info.getId(), new Date(info.getStartTimeStamp()), new Date(info.getDumpTimeStamp()));
        }
    });
    reader.setExecutionDataVisitor(new IExecutionDataVisitor() {

        public void visitClassExecution(final ExecutionData data) {
            out.printf("%016x  %3d of %3d   %s%n", Long.valueOf(data.getId()), Integer.valueOf(getHitCount(data.getProbes())), Integer.valueOf(data.getProbes().length), data.getName());
        }
    });
    reader.read();
    in.close();
    out.println();
}
Also used : ISessionInfoVisitor(org.jacoco.core.data.ISessionInfoVisitor) SessionInfo(org.jacoco.core.data.SessionInfo) IExecutionDataVisitor(org.jacoco.core.data.IExecutionDataVisitor) FileInputStream(java.io.FileInputStream) Date(java.util.Date) ExecutionDataReader(org.jacoco.core.data.ExecutionDataReader) ExecutionData(org.jacoco.core.data.ExecutionData)

Example 3 with IExecutionDataVisitor

use of org.jacoco.core.data.IExecutionDataVisitor in project sonar-java by SonarSource.

the class JaCoCoReportMerger method mergeReports.

/**
 * Merge all reports in reportOverall.
 * @param reportOverall destination file of merge.
 * @param reports files to be merged.
 */
public static void mergeReports(File reportOverall, File... reports) {
    ExecutionDataVisitor edv = new ExecutionDataVisitor();
    boolean isCurrentVersionFormat = loadSourceFiles(edv, reports);
    try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(reportOverall))) {
        Object visitor;
        if (isCurrentVersionFormat) {
            visitor = new ExecutionDataWriter(outputStream);
        } else {
            visitor = new org.jacoco.previous.core.data.ExecutionDataWriter(outputStream);
        }
        for (Map.Entry<String, ExecutionDataStore> entry : edv.getSessions().entrySet()) {
            SessionInfo sessionInfo = new SessionInfo(entry.getKey(), 0, 0);
            ((ISessionInfoVisitor) visitor).visitSessionInfo(sessionInfo);
            entry.getValue().accept((IExecutionDataVisitor) visitor);
        }
    } catch (IOException e) {
        throw new AnalysisException(String.format("Unable to write overall coverage report %s", reportOverall.getAbsolutePath()), e);
    }
}
Also used : ISessionInfoVisitor(org.jacoco.core.data.ISessionInfoVisitor) SessionInfo(org.jacoco.core.data.SessionInfo) IOException(java.io.IOException) IExecutionDataVisitor(org.jacoco.core.data.IExecutionDataVisitor) ExecutionDataStore(org.jacoco.core.data.ExecutionDataStore) FileOutputStream(java.io.FileOutputStream) AnalysisException(org.sonar.java.AnalysisException) ExecutionDataWriter(org.jacoco.core.data.ExecutionDataWriter) BufferedOutputStream(java.io.BufferedOutputStream) Map(java.util.Map)

Aggregations

IExecutionDataVisitor (org.jacoco.core.data.IExecutionDataVisitor)3 ISessionInfoVisitor (org.jacoco.core.data.ISessionInfoVisitor)3 SessionInfo (org.jacoco.core.data.SessionInfo)3 FileInputStream (java.io.FileInputStream)2 Date (java.util.Date)2 ExecutionData (org.jacoco.core.data.ExecutionData)2 ExecutionDataReader (org.jacoco.core.data.ExecutionDataReader)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 Map (java.util.Map)1 ExecutionDataStore (org.jacoco.core.data.ExecutionDataStore)1 ExecutionDataWriter (org.jacoco.core.data.ExecutionDataWriter)1 AnalysisException (org.sonar.java.AnalysisException)1