Search in sources :

Example 1 with KeepAliveOutputStream

use of org.apache.tools.ant.util.KeepAliveOutputStream in project ant by apache.

the class Redirector method outStreams.

/**
 * outStreams
 */
private void outStreams() {
    if (out != null && out.length > 0) {
        final String logHead = "Output " + ((appendOut) ? "appended" : "redirected") + " to ";
        outputStream = foldFiles(out, logHead, Project.MSG_VERBOSE, appendOut, createEmptyFilesOut);
    }
    if (outputProperty != null) {
        if (baos == null) {
            baos = new PropertyOutputStream(outputProperty);
            managingTask.log("Output redirected to property: " + outputProperty, Project.MSG_VERBOSE);
        }
        // shield it from being closed by a filtering StreamPumper
        final OutputStream keepAliveOutput = new KeepAliveOutputStream(baos);
        outputStream = (outputStream == null) ? keepAliveOutput : new TeeOutputStream(outputStream, keepAliveOutput);
    } else {
        baos = null;
    }
}
Also used : TeeOutputStream(org.apache.tools.ant.util.TeeOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) KeepAliveOutputStream(org.apache.tools.ant.util.KeepAliveOutputStream) OutputStream(java.io.OutputStream) LazyFileOutputStream(org.apache.tools.ant.util.LazyFileOutputStream) PipedOutputStream(java.io.PipedOutputStream) TeeOutputStream(org.apache.tools.ant.util.TeeOutputStream) KeepAliveOutputStream(org.apache.tools.ant.util.KeepAliveOutputStream)

Example 2 with KeepAliveOutputStream

use of org.apache.tools.ant.util.KeepAliveOutputStream in project ant by apache.

the class Redirector method errorStreams.

private void errorStreams() {
    if (error != null && error.length > 0) {
        final String logHead = "Error " + ((appendErr) ? "appended" : "redirected") + " to ";
        errorStream = foldFiles(error, logHead, Project.MSG_VERBOSE, appendErr, createEmptyFilesErr);
    } else if (!(logError || outputStream == null) && errorProperty == null) {
        final long funnelTimeout = 0L;
        final OutputStreamFunneler funneler = new OutputStreamFunneler(outputStream, funnelTimeout);
        try {
            outputStream = funneler.getFunnelInstance();
            errorStream = funneler.getFunnelInstance();
            if (!outputIsBinary) {
                outputStream = new LineOrientedOutputStreamRedirector(outputStream);
                errorStream = new LineOrientedOutputStreamRedirector(errorStream);
            }
        } catch (final IOException eyeOhEx) {
            throw new BuildException("error splitting output/error streams", eyeOhEx);
        }
    }
    if (errorProperty != null) {
        if (errorBaos == null) {
            errorBaos = new PropertyOutputStream(errorProperty);
            managingTask.log("Error redirected to property: " + errorProperty, Project.MSG_VERBOSE);
        }
        // shield it from being closed by a filtering StreamPumper
        final OutputStream keepAliveError = new KeepAliveOutputStream(errorBaos);
        errorStream = (error == null || error.length == 0) ? keepAliveError : new TeeOutputStream(errorStream, keepAliveError);
    } else {
        errorBaos = null;
    }
}
Also used : OutputStreamFunneler(org.apache.tools.ant.util.OutputStreamFunneler) TeeOutputStream(org.apache.tools.ant.util.TeeOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) KeepAliveOutputStream(org.apache.tools.ant.util.KeepAliveOutputStream) OutputStream(java.io.OutputStream) LazyFileOutputStream(org.apache.tools.ant.util.LazyFileOutputStream) PipedOutputStream(java.io.PipedOutputStream) TeeOutputStream(org.apache.tools.ant.util.TeeOutputStream) KeepAliveOutputStream(org.apache.tools.ant.util.KeepAliveOutputStream) LineOrientedOutputStreamRedirector(org.apache.tools.ant.util.LineOrientedOutputStreamRedirector) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException)

Example 3 with KeepAliveOutputStream

use of org.apache.tools.ant.util.KeepAliveOutputStream in project ant by apache.

the class JUnitLauncherTask method setupResultFormatter.

private void setupResultFormatter(final TestRequest testRequest, final ListenerDefinition formatterDefinition, final TestResultFormatter resultFormatter) {
    testRequest.closeUponCompletion(resultFormatter);
    // set the execution context
    resultFormatter.setContext(new InVMExecution());
    // set the destination output stream for writing out the formatted result
    final TestDefinition test = testRequest.getOwner();
    final java.nio.file.Path outputDir = test.getOutputDir() != null ? Paths.get(test.getOutputDir()) : getProject().getBaseDir().toPath();
    final String filename = formatterDefinition.requireResultFile(test);
    final java.nio.file.Path resultOutputFile = Paths.get(outputDir.toString(), filename);
    try {
        final OutputStream resultOutputStream = Files.newOutputStream(resultOutputFile);
        // enroll the output stream to be closed when the execution of the TestRequest completes
        testRequest.closeUponCompletion(resultOutputStream);
        resultFormatter.setDestination(new KeepAliveOutputStream(resultOutputStream));
    } catch (IOException e) {
        throw new BuildException(e);
    }
    // check if system.out/system.err content needs to be passed on to the listener
    if (formatterDefinition.shouldSendSysOut()) {
        testRequest.addSysOutInterest(resultFormatter);
    }
    if (formatterDefinition.shouldSendSysErr()) {
        testRequest.addSysErrInterest(resultFormatter);
    }
}
Also used : KeepAliveOutputStream(org.apache.tools.ant.util.KeepAliveOutputStream) OutputStream(java.io.OutputStream) PipedOutputStream(java.io.PipedOutputStream) KeepAliveOutputStream(org.apache.tools.ant.util.KeepAliveOutputStream) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException)

Aggregations

OutputStream (java.io.OutputStream)3 PipedOutputStream (java.io.PipedOutputStream)3 KeepAliveOutputStream (org.apache.tools.ant.util.KeepAliveOutputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 BuildException (org.apache.tools.ant.BuildException)2 LazyFileOutputStream (org.apache.tools.ant.util.LazyFileOutputStream)2 TeeOutputStream (org.apache.tools.ant.util.TeeOutputStream)2 LineOrientedOutputStreamRedirector (org.apache.tools.ant.util.LineOrientedOutputStreamRedirector)1 OutputStreamFunneler (org.apache.tools.ant.util.OutputStreamFunneler)1