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;
}
}
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;
}
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);
}
}
}
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;
}
}
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);
}
}
Aggregations