Search in sources :

Example 11 with ExecutionDataWriter

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

the class ExecFileLoader method save.

/**
 * Saves the current content into the given output stream.
 *
 * @param stream
 *            stream to save content to
 * @throws IOException
 *             in case of problems while writing to the stream
 */
public void save(final OutputStream stream) throws IOException {
    final ExecutionDataWriter dataWriter = new ExecutionDataWriter(stream);
    sessionInfos.accept(dataWriter);
    executionData.accept(dataWriter);
}
Also used : ExecutionDataWriter(org.jacoco.core.data.ExecutionDataWriter)

Example 12 with ExecutionDataWriter

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

the class ExecDumpTest method createExecFile.

private String createExecFile() throws IOException {
    File f = File.createTempFile("jacoco", ".exec");
    final FileOutputStream out = new FileOutputStream(f);
    final ExecutionDataWriter writer = new ExecutionDataWriter(out);
    writer.visitSessionInfo(new SessionInfo("testid", 1, 2));
    writer.visitClassExecution(new ExecutionData(0x1234, "foo/MyClass", new boolean[] { false, true, true }));
    writer.flush();
    out.close();
    return f.getPath();
}
Also used : FileOutputStream(java.io.FileOutputStream) SessionInfo(org.jacoco.core.data.SessionInfo) ExecutionDataWriter(org.jacoco.core.data.ExecutionDataWriter) File(java.io.File) ExecutionData(org.jacoco.core.data.ExecutionData)

Example 13 with ExecutionDataWriter

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

the class ExecutionDataClient method main.

/**
 * Starts the execution data request.
 *
 * @param args
 * @throws IOException
 */
public static void main(final String[] args) throws IOException {
    final FileOutputStream localFile = new FileOutputStream(DESTFILE);
    final ExecutionDataWriter localWriter = new ExecutionDataWriter(localFile);
    // Open a socket to the coverage agent:
    final Socket socket = new Socket(InetAddress.getByName(ADDRESS), PORT);
    final RemoteControlWriter writer = new RemoteControlWriter(socket.getOutputStream());
    final RemoteControlReader reader = new RemoteControlReader(socket.getInputStream());
    reader.setSessionInfoVisitor(localWriter);
    reader.setExecutionDataVisitor(localWriter);
    // Send a dump command and read the response:
    writer.visitDumpCommand(true, false);
    if (!reader.read()) {
        throw new IOException("Socket closed unexpectedly.");
    }
    socket.close();
    localFile.close();
}
Also used : RemoteControlWriter(org.jacoco.core.runtime.RemoteControlWriter) FileOutputStream(java.io.FileOutputStream) ExecutionDataWriter(org.jacoco.core.data.ExecutionDataWriter) IOException(java.io.IOException) Socket(java.net.Socket) RemoteControlReader(org.jacoco.core.runtime.RemoteControlReader)

Example 14 with ExecutionDataWriter

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

the class ExecutionDataServer method main.

/**
 * Start the server as a standalone program.
 *
 * @param args
 * @throws IOException
 */
public static void main(final String[] args) throws IOException {
    final ExecutionDataWriter fileWriter = new ExecutionDataWriter(new FileOutputStream(DESTFILE));
    final ServerSocket server = new ServerSocket(PORT, 0, InetAddress.getByName(ADDRESS));
    while (true) {
        final Handler handler = new Handler(server.accept(), fileWriter);
        new Thread(handler).start();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) ServerSocket(java.net.ServerSocket) ExecutionDataWriter(org.jacoco.core.data.ExecutionDataWriter)

Example 15 with ExecutionDataWriter

use of org.jacoco.core.data.ExecutionDataWriter 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

ExecutionDataWriter (org.jacoco.core.data.ExecutionDataWriter)15 FileOutputStream (java.io.FileOutputStream)10 ExecutionData (org.jacoco.core.data.ExecutionData)6 File (java.io.File)5 IOException (java.io.IOException)5 OutputStream (java.io.OutputStream)5 SessionInfo (org.jacoco.core.data.SessionInfo)4 Test (org.junit.Test)4 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 Map (java.util.Map)1 ExecutionDataStore (org.jacoco.core.data.ExecutionDataStore)1 IExecutionDataVisitor (org.jacoco.core.data.IExecutionDataVisitor)1 ISessionInfoVisitor (org.jacoco.core.data.ISessionInfoVisitor)1 RemoteControlReader (org.jacoco.core.runtime.RemoteControlReader)1 RemoteControlWriter (org.jacoco.core.runtime.RemoteControlWriter)1 AnalysisException (org.sonar.java.AnalysisException)1