/** * Returns the first bytes of a file that represents a valid execution data * file. In any case every execution data file starts with the three bytes * <code>0x01 0xC0 0xC0</code>. * * @return first bytes of a execution data file */ public static final byte[] getFileHeader() { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try { new ExecutionDataWriter(buffer); } catch (final IOException e) { // Must not happen with ByteArrayOutputStream throw new AssertionError(e); } return buffer.toByteArray(); }
/** * Creates a new writer based on the given output stream. Depending on the * nature of the underlying stream output should be buffered as most data is * written in single bytes. * * @param output * binary stream to write execution data to * @throws IOException * if the header can't be written */ public ExecutionDataWriter(final OutputStream output) throws IOException { this.out = new CompactDataOutput(output); writeHeader(); }
private void createExecFile(IProgressMonitor monitor) throws IOException, CoreException { monitor.beginTask( NLS.bind(CoreMessages.ExportingSession_task, session.getDescription()), 1); final OutputStream out = new BufferedOutputStream(new FileOutputStream( destination)); final ExecutionDataWriter writer = new ExecutionDataWriter(out); session.accept(writer, writer); out.close(); monitor.done(); }
/** * 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); }
/** * Creates a new execution data file containing the content of the given * source. * * @param source * source to dump into the file * @return created file */ public IExecutionDataSource newFile(IExecutionDataSource source) throws CoreException { try { final File file = File.createTempFile("session", ".exec", folder); //$NON-NLS-1$ //$NON-NLS-2$ final OutputStream out = new BufferedOutputStream(new FileOutputStream( file)); final ExecutionDataWriter writer = new ExecutionDataWriter(out); source.accept(writer, writer); out.close(); return new URLExecutionDataSource(file.toURL()); } catch (IOException e) { throw new CoreException(EclEmmaStatus.EXEC_FILE_CREATE_ERROR.getStatus(e)); } }
private void mergeReports(File reportOverall, File... reports) { SessionInfoStore infoStore = new SessionInfoStore(); ExecutionDataStore dataStore = new ExecutionDataStore(); loadSourceFiles(infoStore, dataStore, reports); BufferedOutputStream outputStream = null; try { outputStream = new BufferedOutputStream(new FileOutputStream(reportOverall)); ExecutionDataWriter dataWriter = new ExecutionDataWriter(outputStream); infoStore.accept(dataWriter); dataStore.accept(dataWriter); } catch (IOException e) { throw new IllegalStateException(String.format("Unable to write overall coverage report %s", reportOverall.getAbsolutePath(), e)); } finally { Closeables.closeQuietly(outputStream); } }
private void mergeReports(File reportOverall, File... reports) { SessionInfoStore infoStore = new SessionInfoStore(); ExecutionDataStore dataStore = new ExecutionDataStore(); loadSourceFiles(infoStore, dataStore, reports); BufferedOutputStream outputStream = null; try { outputStream = new BufferedOutputStream(new FileOutputStream(reportOverall)); ExecutionDataWriter dataWriter = new ExecutionDataWriter(outputStream); infoStore.accept(dataWriter); dataStore.accept(dataWriter); } catch (IOException e) { throw new SonarException(String.format("Unable to write overall coverage report %s", reportOverall.getAbsolutePath()), e); } finally { Closeables.closeQuietly(outputStream); } }
private void mergeReports(File reportOverall, File... reports) { SessionInfoStore infoStore = new SessionInfoStore(); ExecutionDataStore dataStore = new ExecutionDataStore(); loadSourceFiles(infoStore, dataStore, reports); BufferedOutputStream outputStream = null; try { outputStream = new BufferedOutputStream(new FileOutputStream(reportOverall)); ExecutionDataWriter dataWriter = new ExecutionDataWriter(outputStream); infoStore.accept(dataWriter); dataStore.accept(dataWriter); } catch (IOException e) { throw new SonarException(String.format("Unable to write overall coverage report %s", reportOverall.getAbsolutePath()), e); } finally { Closeables.closeQuietly(outputStream); } }
/** * 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(); loadSourceFiles(edv, reports); try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(reportOverall))) { Object visitor = new 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); } }
/** * 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) { SessionInfoStore infoStore = new SessionInfoStore(); ExecutionDataStore dataStore = new ExecutionDataStore(); boolean isCurrentVersionFormat = loadSourceFiles(infoStore, dataStore, 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); } infoStore.accept((ISessionInfoVisitor) visitor); dataStore.accept((IExecutionDataVisitor) visitor); } catch (IOException e) { throw new IllegalStateException(String.format("Unable to write overall coverage report %s", reportOverall.getAbsolutePath()), e); } }
public void writeCoverageData(@Observes AfterSuite arqEvent) throws Exception { ArquillianRuntime runtime = (ArquillianRuntime) runtimeInst.get(); if (runtime != null) { ByteArrayOutputStream coverageOutputStream = null; try { coverageOutputStream = new ByteArrayOutputStream(); ExecutionDataWriter writer = new ExecutionDataWriter(coverageOutputStream); runtime.getRuntimeData().collect(writer, writer, true); } finally { runtime.shutdown(); if (coverageOutputStream != null) { try { coverageOutputStream.close(); } catch (Exception e) { throw new RuntimeException("Could not close coverage file", e); } } } getCommandService().execute(new CoverageDataCommand(coverageOutputStream.toByteArray())); } }
public void writeCoverageData(@Observes AfterSuite arqEvent) throws Exception { ArquillianRuntime runtime = (ArquillianRuntime) runtimeInst.get(); if (runtime != null) { ByteArrayOutputStream coverageOutputStream = null; try { coverageOutputStream = new ByteArrayOutputStream(); ExecutionDataWriter writer = new ExecutionDataWriter(coverageOutputStream); runtime.getRuntimeData().collect(writer, writer, true); } finally { runtime.shutdown(); if (coverageOutputStream != null) { try { coverageOutputStream.close(); } catch (Exception e) { throw new RuntimeException("Could not close coverage file", e); } } } getCommandService().execute(new CoverageDataCommand(coverageOutputStream.toByteArray())); } }
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { ExecFileLoader loader = new ExecFileLoader(); for (File exec : files) { loader.load(exec); } rsp.setContentType("application/octet-stream"); final ExecutionDataWriter dataWriter = new ExecutionDataWriter(rsp.getOutputStream()); loader.getSessionInfoStore().accept(dataWriter); loader.getExecutionDataStore().accept(dataWriter); } };