Search in sources :

Example 1 with TeeOutputStream

use of org.apache.tools.ant.util.TeeOutputStream 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 TeeOutputStream

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

the class Redirector method foldFiles.

private OutputStream foldFiles(final File[] file, final String logHead, final int loglevel, final boolean append, final boolean createEmptyFiles) {
    final OutputStream result = new LazyFileOutputStream(file[0], append, createEmptyFiles);
    managingTask.log(logHead + file[0], loglevel);
    final char[] c = new char[logHead.length()];
    Arrays.fill(c, ' ');
    final String indent = new String(c);
    for (int i = 1; i < file.length; i++) {
        outputStream = new TeeOutputStream(outputStream, new LazyFileOutputStream(file[i], append, createEmptyFiles));
        managingTask.log(indent + file[i], loglevel);
    }
    return result;
}
Also used : TeeOutputStream(org.apache.tools.ant.util.TeeOutputStream) LazyFileOutputStream(org.apache.tools.ant.util.LazyFileOutputStream) 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)

Example 3 with TeeOutputStream

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

the class Redirector method createStreams.

/**
 * Create the input, error and output streams based on the configuration
 * options.
 */
public void createStreams() {
    synchronized (outMutex) {
        outStreams();
        if (alwaysLogOut || outputStream == null) {
            final OutputStream outputLog = new LogOutputStream(managingTask, Project.MSG_INFO);
            outputStream = (outputStream == null) ? outputLog : new TeeOutputStream(outputLog, outputStream);
        }
        if ((outputFilterChains != null && outputFilterChains.size() > 0) || !(outputEncoding.equalsIgnoreCase(inputEncoding))) {
            try {
                final LeadPipeInputStream snk = new LeadPipeInputStream();
                snk.setManagingComponent(managingTask);
                InputStream outPumpIn = snk;
                Reader reader = new InputStreamReader(outPumpIn, inputEncoding);
                if (outputFilterChains != null && outputFilterChains.size() > 0) {
                    final ChainReaderHelper helper = new ChainReaderHelper();
                    helper.setProject(managingTask.getProject());
                    helper.setPrimaryReader(reader);
                    helper.setFilterChains(outputFilterChains);
                    reader = helper.getAssembledReader();
                }
                outPumpIn = new ReaderInputStream(reader, outputEncoding);
                final Thread t = new Thread(threadGroup, new StreamPumper(outPumpIn, outputStream, true), "output pumper");
                t.setPriority(Thread.MAX_PRIORITY);
                outputStream = new PipedOutputStream(snk);
                t.start();
            } catch (final IOException eyeOhEx) {
                throw new BuildException("error setting up output stream", eyeOhEx);
            }
        }
    }
    synchronized (errMutex) {
        errorStreams();
        if (alwaysLogErr || errorStream == null) {
            final OutputStream errorLog = new LogOutputStream(managingTask, Project.MSG_WARN);
            errorStream = (errorStream == null) ? errorLog : new TeeOutputStream(errorLog, errorStream);
        }
        if ((errorFilterChains != null && errorFilterChains.size() > 0) || !(errorEncoding.equalsIgnoreCase(inputEncoding))) {
            try {
                final LeadPipeInputStream snk = new LeadPipeInputStream();
                snk.setManagingComponent(managingTask);
                InputStream errPumpIn = snk;
                Reader reader = new InputStreamReader(errPumpIn, inputEncoding);
                if (errorFilterChains != null && errorFilterChains.size() > 0) {
                    final ChainReaderHelper helper = new ChainReaderHelper();
                    helper.setProject(managingTask.getProject());
                    helper.setPrimaryReader(reader);
                    helper.setFilterChains(errorFilterChains);
                    reader = helper.getAssembledReader();
                }
                errPumpIn = new ReaderInputStream(reader, errorEncoding);
                final Thread t = new Thread(threadGroup, new StreamPumper(errPumpIn, errorStream, true), "error pumper");
                t.setPriority(Thread.MAX_PRIORITY);
                errorStream = new PipedOutputStream(snk);
                t.start();
            } catch (final IOException eyeOhEx) {
                throw new BuildException("error setting up error stream", eyeOhEx);
            }
        }
    }
    synchronized (inMutex) {
        // whatever warnings are needed
        if (input != null && input.length > 0) {
            managingTask.log("Redirecting input from file" + ((input.length == 1) ? "" : "s"), Project.MSG_VERBOSE);
            try {
                inputStream = new ConcatFileInputStream(input);
            } catch (final IOException eyeOhEx) {
                throw new BuildException(eyeOhEx);
            }
            ((ConcatFileInputStream) inputStream).setManagingComponent(managingTask);
        } else if (inputString != null) {
            final StringBuffer buf = new StringBuffer("Using input ");
            if (logInputString) {
                buf.append('"').append(inputString).append('"');
            } else {
                buf.append("string");
            }
            managingTask.log(buf.toString(), Project.MSG_VERBOSE);
            inputStream = new ByteArrayInputStream(inputString.getBytes());
        }
        if (inputStream != null && inputFilterChains != null && inputFilterChains.size() > 0) {
            final ChainReaderHelper helper = new ChainReaderHelper();
            helper.setProject(managingTask.getProject());
            try {
                helper.setPrimaryReader(new InputStreamReader(inputStream, inputEncoding));
            } catch (final IOException eyeOhEx) {
                throw new BuildException("error setting up input stream", eyeOhEx);
            }
            helper.setFilterChains(inputFilterChains);
            inputStream = new ReaderInputStream(helper.getAssembledReader(), inputEncoding);
        }
    }
}
Also used : TeeOutputStream(org.apache.tools.ant.util.TeeOutputStream) InputStreamReader(java.io.InputStreamReader) LeadPipeInputStream(org.apache.tools.ant.util.LeadPipeInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ReaderInputStream(org.apache.tools.ant.util.ReaderInputStream) ConcatFileInputStream(org.apache.tools.ant.util.ConcatFileInputStream) InputStream(java.io.InputStream) 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) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) PipedOutputStream(java.io.PipedOutputStream) IOException(java.io.IOException) ConcatFileInputStream(org.apache.tools.ant.util.ConcatFileInputStream) ReaderInputStream(org.apache.tools.ant.util.ReaderInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) LeadPipeInputStream(org.apache.tools.ant.util.LeadPipeInputStream) ChainReaderHelper(org.apache.tools.ant.filters.util.ChainReaderHelper) BuildException(org.apache.tools.ant.BuildException)

Example 4 with TeeOutputStream

use of org.apache.tools.ant.util.TeeOutputStream 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 5 with TeeOutputStream

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

the class ANTLR method run.

/**
 * execute in a forked VM
 */
private int run(String[] command) throws BuildException {
    PumpStreamHandler psh = new PumpStreamHandler(new LogOutputStream(this, Project.MSG_INFO), new TeeOutputStream(new LogOutputStream(this, Project.MSG_WARN), bos));
    Execute exe = new Execute(psh, null);
    exe.setAntRun(getProject());
    if (workingdir != null) {
        exe.setWorkingDirectory(workingdir);
    }
    exe.setCommandline(command);
    try {
        return exe.execute();
    } catch (IOException e) {
        throw new BuildException(e, getLocation());
    } finally {
        FileUtils.close(bos);
    }
}
Also used : TeeOutputStream(org.apache.tools.ant.util.TeeOutputStream) PumpStreamHandler(org.apache.tools.ant.taskdefs.PumpStreamHandler) Execute(org.apache.tools.ant.taskdefs.Execute) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) LogOutputStream(org.apache.tools.ant.taskdefs.LogOutputStream)

Aggregations

TeeOutputStream (org.apache.tools.ant.util.TeeOutputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 OutputStream (java.io.OutputStream)5 KeepAliveOutputStream (org.apache.tools.ant.util.KeepAliveOutputStream)5 IOException (java.io.IOException)4 PipedOutputStream (java.io.PipedOutputStream)4 BuildException (org.apache.tools.ant.BuildException)4 LazyFileOutputStream (org.apache.tools.ant.util.LazyFileOutputStream)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ChannelExec (com.jcraft.jsch.ChannelExec)1 JSchException (com.jcraft.jsch.JSchException)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 ChainReaderHelper (org.apache.tools.ant.filters.util.ChainReaderHelper)1 Execute (org.apache.tools.ant.taskdefs.Execute)1 LogOutputStream (org.apache.tools.ant.taskdefs.LogOutputStream)1 PumpStreamHandler (org.apache.tools.ant.taskdefs.PumpStreamHandler)1