Browse Source

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
master
Conor MacNeill 22 years ago
parent
commit
539d2cdb76
5 changed files with 21 additions and 2 deletions
  1. +3
    -1
      src/main/org/apache/tools/ant/DemuxInputStream.java
  2. +9
    -1
      src/main/org/apache/tools/ant/Main.java
  3. +1
    -0
      src/main/org/apache/tools/ant/Project.java
  4. +7
    -0
      src/main/org/apache/tools/ant/taskdefs/LogOutputStream.java
  5. +1
    -0
      src/main/org/apache/tools/ant/taskdefs/Redirector.java

+ 3
- 1
src/main/org/apache/tools/ant/DemuxInputStream.java View File

@@ -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];
}


+ 9
- 1
src/main/org/apache/tools/ant/Main.java View File

@@ -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 <file> ''" + lSep);
msg.append(" -logger <classname> the class which is to perform logging" + lSep);
msg.append(" -listener <classname> add an instance of class as a project listener" + lSep);
msg.append(" -noinput do not allow interactive input" + lSep);
msg.append(" -buildfile <file> use given buildfile" + lSep);
msg.append(" -file <file> ''" + lSep);
msg.append(" -f <file> ''" + lSep);


+ 1
- 0
src/main/org/apache/tools/ant/Project.java View File

@@ -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");


+ 7
- 0
src/main/org/apache/tools/ant/taskdefs/LogOutputStream.java View File

@@ -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 <code>processLine</code>


+ 1
- 0
src/main/org/apache/tools/ant/taskdefs/Redirector.java View File

@@ -399,6 +399,7 @@ public class Redirector {
outPrintStream = new PrintStream(outputStream);
}
outPrintStream.print(line);
outPrintStream.flush();
}
/**


Loading…
Cancel
Save