From 539d2cdb764e134a6d74ee8b2b50e3d7aba1e882 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Tue, 10 Jun 2003 13:29:56 +0000 Subject: [PATCH] Various I/O fixes to support input from java tasks. Addition of a -noinput flag to indicate input is not allowed to prevent locking up non-interactive builds. PR: 18133 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274657 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/ant/DemuxInputStream.java | 4 +++- src/main/org/apache/tools/ant/Main.java | 10 +++++++++- src/main/org/apache/tools/ant/Project.java | 1 + .../org/apache/tools/ant/taskdefs/LogOutputStream.java | 7 +++++++ src/main/org/apache/tools/ant/taskdefs/Redirector.java | 1 + 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/org/apache/tools/ant/DemuxInputStream.java b/src/main/org/apache/tools/ant/DemuxInputStream.java index f074b724f..d2c157dcc 100644 --- a/src/main/org/apache/tools/ant/DemuxInputStream.java +++ b/src/main/org/apache/tools/ant/DemuxInputStream.java @@ -86,7 +86,9 @@ public class DemuxInputStream extends InputStream { */ public int read() throws IOException { byte[] buffer = new byte[1]; - project.demuxInput(buffer, 0, 1); + if (project.demuxInput(buffer, 0, 1) == -1) { + return -1; + } return buffer[0]; } diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java index 7d08ab9c3..802cde583 100644 --- a/src/main/org/apache/tools/ant/Main.java +++ b/src/main/org/apache/tools/ant/Main.java @@ -108,6 +108,9 @@ public class Main { /** File names of property files to load on startup. */ private Vector propertyFiles = new Vector(5); + /** Indicates whether this build is to support interactive input */ + private boolean allowInput = true; + /** * The Ant logger class. There may be only one logger. It will have * the right to use the 'out' PrintStream. The class must implements the @@ -280,6 +283,8 @@ public class Main { } else if (arg.equals("-debug")) { printVersion(); msgOutputLevel = Project.MSG_DEBUG; + } else if (arg.equals("-noinput")) { + allowInput = false; } else if (arg.equals("-logfile") || arg.equals("-l")) { try { File logFile = new File(args[i + 1]); @@ -571,7 +576,9 @@ public class Main { //System.setSecurityManager(new NoExitSecurityManager()); } try { - project.setDefaultInputStream(System.in); + if (allowInput) { + project.setDefaultInputStream(System.in); + } System.setIn(new DemuxInputStream(project)); System.setOut(new PrintStream(new DemuxOutputStream(project, false))); System.setErr(new PrintStream(new DemuxOutputStream(project, true))); @@ -751,6 +758,7 @@ public class Main { msg.append(" -l ''" + lSep); msg.append(" -logger the class which is to perform logging" + lSep); msg.append(" -listener add an instance of class as a project listener" + lSep); + msg.append(" -noinput do not allow interactive input" + lSep); msg.append(" -buildfile use given buildfile" + lSep); msg.append(" -file ''" + lSep); msg.append(" -f ''" + lSep); diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index c77d51e7b..be442981b 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -1087,6 +1087,7 @@ public class Project { public int defaultInput(byte[] buffer, int offset, int length) throws IOException { if (defaultInputStream != null) { + System.out.flush(); return defaultInputStream.read(buffer, offset, length); } else { throw new EOFException("No input provided for project"); diff --git a/src/main/org/apache/tools/ant/taskdefs/LogOutputStream.java b/src/main/org/apache/tools/ant/taskdefs/LogOutputStream.java index 7afdcbfba..c64815c95 100644 --- a/src/main/org/apache/tools/ant/taskdefs/LogOutputStream.java +++ b/src/main/org/apache/tools/ant/taskdefs/LogOutputStream.java @@ -109,6 +109,13 @@ public class LogOutputStream extends OutputStream { skip = (c == '\r'); } + /** + * Flush this log stream + */ + public void flush() { + processBuffer(); + } + /** * Converts the buffer to a string and sends it to processLine diff --git a/src/main/org/apache/tools/ant/taskdefs/Redirector.java b/src/main/org/apache/tools/ant/taskdefs/Redirector.java index 4081780a2..14533bc73 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Redirector.java +++ b/src/main/org/apache/tools/ant/taskdefs/Redirector.java @@ -399,6 +399,7 @@ public class Redirector { outPrintStream = new PrintStream(outputStream); } outPrintStream.print(line); + outPrintStream.flush(); } /**