jglick 2005/03/16 08:52:27
Modified: . Tag: ANT_16_BRANCH WHATSNEW
docs/manual/CoreTasks Tag: ANT_16_BRANCH java.html
src/main/org/apache/tools/ant/taskdefs Tag: ANT_16_BRANCH
Java.java PumpStreamHandler.java Redirector.java
StreamPumper.java
Log:
Merging <java fork="true"> console input fix to Ant 1.6.3.
PR: 24918
Revision Changes Path
No revision
No revision
1.503.2.200 +4 -0 ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/ant/WHATSNEW,v
retrieving revision 1.503.2.199
retrieving revision 1.503.2.200
diff -u -r1.503.2.199 -r1.503.2.200
--- WHATSNEW 15 Mar 2005 20:57:30 -0000 1.503.2.199
+++ WHATSNEW 16 Mar 2005 16:52:25 -0000 1.503.2.200
@@ -129,6 +129,10 @@
Fixed bugs:
-----------
+* Programs run with <java fork="true"> can now accept standard input
+ from the Ant console. (Programs run with <java fork="false"> could
+ already do so.) Bugzilla 24918.
+
* AbstractCvsTask prematurely closed its outputStream and errorStream.
Bugzilla 30097.
No revision
No revision
1.24.2.12 +7 -7 ant/docs/manual/CoreTasks/java.html
Index: java.html
===================================================================
RCS file: /home/cvs/ant/docs/manual/CoreTasks/java.html,v
retrieving revision 1.24.2.11
retrieving revision 1.24.2.12
diff -u -r1.24.2.11 -r1.24.2.12
--- java.html 10 Mar 2005 13:07:43 -0000 1.24.2.11
+++ java.html 16 Mar 2005 16:52:26 -0000 1.24.2.12
@@ -16,10 +16,9 @@
If odd things go wrong when you run this task, set fork="true" to use a new
JVM.
-<p>Note that you cannot interact with a forked VM, the only way to
-send input to it is via the input and inputstring attributes. Also note that
-in Ant 1.6, any attempt to read input in the forked VM will receive an
-EOF (-1). This is a change from Ant 1.5, where such an attempt would
block.</p>
+<p>As of Ant 1.6.3, you can interact with a forked VM, as well as
+sending input to it via the <code>input</code> and <code>inputstring</code>
+attributes.</p>
<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
@@ -156,14 +155,16 @@
<td valign="top">A file from which the executed command's standard input
is taken. This attribute is mutually exclusive with the
inputstring attribute</td>
- <td align="center" valign="top">No</td>
+ <td align="center" valign="top">No; default is to take standard input
from console
+ (unless <code>spawn="true"</code>)</td>
</tr>
<tr>
<td valign="top">inputstring</td>
<td valign="top">A string which serves as the input stream for the
executed command. This attribute is mutually exclusive
with the
input attribute.</td>
- <td align="center" valign="top">No</td>
+ <td align="center" valign="top">No; default is to take standard input
from console
+ (unless <code>spawn="true"</code>)</td>
</tr>
<tr>
<td valign="top">newenvironment</td>
@@ -314,4 +315,3 @@
</body>
</html>
-
No revision
No revision
1.77.2.12 +8 -6 ant/src/main/org/apache/tools/ant/taskdefs/Java.java
Index: Java.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Java.java,v
retrieving revision 1.77.2.11
retrieving revision 1.77.2.12
diff -u -r1.77.2.11 -r1.77.2.12
--- Java.java 23 Jun 2004 19:17:12 -0000 1.77.2.11
+++ Java.java 16 Mar 2005 16:52:27 -0000 1.77.2.12
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@
import org.apache.tools.ant.types.Assertions;
import org.apache.tools.ant.types.Permissions;
import org.apache.tools.ant.types.RedirectorElement;
+import org.apache.tools.ant.util.KeepAliveInputStream;
/**
* Launcher for Java applications. Allows use of
@@ -624,11 +625,8 @@
*/
public int handleInput(byte[] buffer, int offset, int length)
throws IOException {
- if (redirector.getInputStream() != null) {
- return redirector.handleInput(buffer, offset, length);
- } else {
- return super.handleInput(buffer, offset, length);
- }
+ // Should work whether or not redirector.inputStream == null:
+ return redirector.handleInput(buffer, offset, length);
}
/**
@@ -687,6 +685,10 @@
if (redirectorElement != null) {
redirectorElement.configure(redirector);
}
+ if (!spawn && input == null && inputString == null) {
+ // #24918: send standard input to the process by default.
+ redirector.setInputStream(new
KeepAliveInputStream(getProject().getDefaultInputStream()));
+ }
}
/**
1.14.2.6 +20 -10
ant/src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java
Index: PumpStreamHandler.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/PumpStreamHandler.java,v
retrieving revision 1.14.2.5
retrieving revision 1.14.2.6
diff -u -r1.14.2.5 -r1.14.2.6
--- PumpStreamHandler.java 20 Apr 2004 22:18:56 -0000 1.14.2.5
+++ PumpStreamHandler.java 16 Mar 2005 16:52:27 -0000 1.14.2.6
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2004 The Apache Software Foundation
+ * Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@
private Thread outputThread;
private Thread errorThread;
- private Thread inputThread;
+ private StreamPumper inputPump;
private OutputStream out;
private OutputStream err;
@@ -101,7 +101,7 @@
*/
public void setProcessInputStream(OutputStream os) {
if (input != null) {
- inputThread = createPump(input, os, true);
+ inputPump = createInputPump(input, os, true);
} else {
try {
os.close();
@@ -117,7 +117,9 @@
public void start() {
outputThread.start();
errorThread.start();
- if (inputThread != null) {
+ if (inputPump != null) {
+ Thread inputThread = new Thread(inputPump);
+ inputThread.setDaemon(true);
inputThread.start();
}
}
@@ -137,12 +139,8 @@
// ignore
}
- if (inputThread != null) {
- try {
- inputThread.join();
- } catch (InterruptedException e) {
- // ignore
- }
+ if (inputPump != null) {
+ inputPump.stop();
}
try {
@@ -210,5 +208,17 @@
result.setDaemon(true);
return result;
}
+
+ /**
+ * Creates a stream pumper to copy the given input stream to the
+ * given output stream. Used for standard input.
+ * @since Ant 1.6.3
+ */
+ /*protected*/ StreamPumper createInputPump(InputStream is, OutputStream
os,
+ boolean closeWhenExhausted) {
+ StreamPumper pumper = new StreamPumper(is, os, closeWhenExhausted);
+ pumper.setAutoflush(true);
+ return pumper;
+ }
}
1.11.2.12 +10 -1
ant/src/main/org/apache/tools/ant/taskdefs/Redirector.java
Index: Redirector.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Redirector.java,v
retrieving revision 1.11.2.11
retrieving revision 1.11.2.12
diff -u -r1.11.2.11 -r1.11.2.12
--- Redirector.java 4 Feb 2005 08:13:46 -0000 1.11.2.11
+++ Redirector.java 16 Mar 2005 16:52:27 -0000 1.11.2.12
@@ -214,6 +214,15 @@
this.inputString = inputString;
}
+ /**
+ * Set a stream to use as input.
+ *
+ * @param inputStream the stream from which input will be read
+ * @since Ant 1.6.3
+ */
+ /*public*/ void setInputStream(InputStream inputStream) {
+ this.inputStream = inputStream;
+ }
/**
* File the output of the process is redirected to. If error is not
@@ -555,7 +564,7 @@
}
}
- // if input files are specified, inputString is ignored;
+ // if input files are specified, inputString and inputStream are
ignored;
// classes that work with redirector attributes can enforce
// whatever warnings are needed
if (input != null && input.length > 0) {
1.16.2.5 +27 -2
ant/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java
Index: StreamPumper.java
===================================================================
RCS file:
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java,v
retrieving revision 1.16.2.4
retrieving revision 1.16.2.5
diff -u -r1.16.2.4 -r1.16.2.5
--- StreamPumper.java 9 Mar 2004 17:01:34 -0000 1.16.2.4
+++ StreamPumper.java 16 Mar 2005 16:52:27 -0000 1.16.2.5
@@ -1,5 +1,5 @@
/*
- * Copyright 2000,2002-2004 The Apache Software Foundation
+ * Copyright 2000,2002-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,6 +36,7 @@
private OutputStream os;
private boolean finished;
private boolean closeWhenExhausted;
+ private boolean autoflush = false;
/**
* Create a new stream pumper.
@@ -62,6 +63,14 @@
this(is, os, false);
}
+ /**
+ * Set whether data should be flushed through to the output stream.
+ * @param autoflush if true, push through data; if false, let it be
buffered
+ * @since Ant 1.6.3
+ */
+ /*public*/ void setAutoflush(boolean autoflush) {
+ this.autoflush = autoflush;
+ }
/**
* Copies data from the input stream to the output stream.
@@ -78,8 +87,11 @@
int length;
try {
- while ((length = is.read(buf)) > 0) {
+ while ((length = is.read(buf)) > 0 && !finished) {
os.write(buf, 0, length);
+ if (autoflush) {
+ os.flush();
+ }
}
} catch (Exception e) {
// ignore errors
@@ -116,4 +128,17 @@
wait();
}
}
+
+ /**
+ * Stop the pumper as soon as possible.
+ * Note that it may continue to block on the input stream
+ * but it will really stop the thread as soon as it gets EOF
+ * or any byte, and it will be marked as finished.
+ * @since Ant 1.6.3
+ */
+ /*public*/ synchronized void stop() {
+ finished = true;
+ notifyAll();
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]