Browse Source

BR 50960. Use autoflush so that content get pushed to the forked application

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1086741 13f79535-47bb-0310-9956-ffa450edef68
master
Nicolas Lalevee 14 years ago
parent
commit
9fb3d4fa86
4 changed files with 56 additions and 4 deletions
  1. +3
    -0
      WHATSNEW
  2. +6
    -0
      src/etc/testcases/taskdefs/java.xml
  3. +3
    -4
      src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java
  4. +44
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java

+ 3
- 0
WHATSNEW View File

@@ -29,6 +29,9 @@ Fixed bugs:
files.
Bugzilla Report 50866.

* Read on System.in hangs for forked java task.
Bugzilla Report 50960.

Other changes:
--------------



+ 6
- 0
src/etc/testcases/taskdefs/java.xml View File

@@ -387,6 +387,11 @@ redirect.err=&quot;${redirect.err}&quot; should be empty</fail>

</target>

<target name="flushedInput">
<java classname="org.apache.tools.ant.taskdefs.JavaTest$$ReadPoint" fork="true"
classpath="${tests-classpath.value}" failonerror="true" timeout="2000" />
</target>

<target name="cleanup">
<delete>
<fileset file="${logFile}" />
@@ -395,4 +400,5 @@ redirect.err=&quot;${redirect.err}&quot; should be empty</fail>
</target>

<target name="foo" />

</project>

+ 3
- 4
src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java View File

@@ -273,10 +273,9 @@ public class PumpStreamHandler implements ExecuteStreamHandler {
*/
protected Thread createPump(InputStream is, OutputStream os,
boolean closeWhenExhausted, boolean nonBlockingIO) {
final Thread result
= new ThreadWithPumper(new StreamPumper(is, os,
closeWhenExhausted,
nonBlockingIO));
StreamPumper pumper = new StreamPumper(is, os, closeWhenExhausted, nonBlockingIO);
pumper.setAutoflush(true);
final Thread result = new ThreadWithPumper(pumper);
result.setDaemon(true);
return result;
}


+ 44
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java View File

@@ -18,10 +18,12 @@

package org.apache.tools.ant.taskdefs;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PipedInputStream;
@@ -260,6 +262,40 @@ public class JavaTest extends BuildFileTest {
assertEquals("foo", project.getProperty("input.value"));
}

public void testFlushedInput() throws Exception {
final PipedOutputStream out = new PipedOutputStream();
final PipedInputStream in = new PipedInputStream(out);
project.setInputHandler(new DefaultInputHandler() {
protected InputStream getInputStream() {
return in;
}
});
project.setDefaultInputStream(in);

final boolean[] timeout = new boolean[1];
timeout[0] = false;

Thread writingThread = new Thread(new Runnable() {
public void run() {
try {
// wait a little bit to have the target executed
Thread.sleep(500);
} catch (InterruptedException e) {
// don't care
}
try {
out.write("foo-FlushedInput\n".getBytes());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
writingThread.setDaemon(true);

writingThread.start();
executeTarget("flushedInput");
}

/**
* entry point class with no dependencies other
* than normal JRE runtime
@@ -372,4 +408,12 @@ public class JavaTest extends BuildFileTest {
}
}
}

public static class ReadPoint {
public static void main(String[] args) throws IOException {
String line = new BufferedReader(new InputStreamReader(System.in)).readLine();
System.out.println(line);
}
}

}

Loading…
Cancel
Save