Index: ant/src/org/apache/tools/ant/module/run/TargetExecutor.java =================================================================== RCS file: /cvs/ant/src/org/apache/tools/ant/module/run/TargetExecutor.java,v retrieving revision 1.33 diff -u -r1.33 TargetExecutor.java --- ant/src/org/apache/tools/ant/module/run/TargetExecutor.java 22 Nov 2003 00:12:11 -0000 1.33 +++ ant/src/org/apache/tools/ant/module/run/TargetExecutor.java 22 Nov 2003 15:45:15 -0000 @@ -37,6 +37,7 @@ import org.apache.tools.ant.module.api.AntProjectCookie; import org.apache.tools.ant.module.api.IntrospectedInfo; import org.apache.tools.ant.module.bridge.AntBridge; +import org.openide.util.io.ReaderInputStream; /** Executes an Ant Target asynchronously in the IDE. */ @@ -216,8 +217,16 @@ return; } + InputStream in = null; + try { + in = new ReaderInputStream(io.getIn(), + System.getProperty("file.encoding", "UTF-8")); // NOI18N + } catch (IOException e) { + AntModule.err.notify(ErrorManager.INFORMATIONAL, e); + } + ok = AntBridge.getInterface().run(buildFile, pcookie.getFileObject(), targetNames, - out, err, properties, verbosity, outputStream == null); + in, out, err, properties, verbosity, outputStream == null); } // See #29245 for more details. Relevant only for Ant 1.5.1 Index: ant/src/org/apache/tools/ant/module/bridge/BridgeInterface.java =================================================================== RCS file: /cvs/ant/src/org/apache/tools/ant/module/bridge/BridgeInterface.java,v retrieving revision 1.2 diff -u -r1.2 BridgeInterface.java --- ant/src/org/apache/tools/ant/module/bridge/BridgeInterface.java 7 Jul 2003 16:23:03 -0000 1.2 +++ ant/src/org/apache/tools/ant/module/bridge/BridgeInterface.java 22 Nov 2003 15:45:15 -0000 @@ -14,6 +14,7 @@ package org.apache.tools.ant.module.bridge; import java.io.File; +import java.io.InputStream; import java.io.PrintStream; import java.util.List; import java.util.Properties; @@ -30,7 +31,7 @@ * @param buildFile an Ant build script * @param targets a list of target names to run, or null to run the default target */ - boolean run(File buildFile, FileObject buildFileObject, List targets, PrintStream out, PrintStream err, Properties properties, int verbosity, boolean useStatusLine); + boolean run(File buildFile, FileObject buildFileObject, List targets, InputStream in, PrintStream out, PrintStream err, Properties properties, int verbosity, boolean useStatusLine); /** * Get some informational value of the Ant version. Index: ant/src/org/apache/tools/ant/module/bridge/AntBridge.java =================================================================== RCS file: /cvs/ant/src/org/apache/tools/ant/module/bridge/AntBridge.java,v retrieving revision 1.6 diff -u -r1.6 AntBridge.java --- ant/src/org/apache/tools/ant/module/bridge/AntBridge.java 22 Oct 2003 20:30:23 -0000 1.6 +++ ant/src/org/apache/tools/ant/module/bridge/AntBridge.java 22 Nov 2003 15:45:15 -0000 @@ -366,33 +366,38 @@ // Better still would be to let the execution engine handle it entirely, // by creating a custom InputOutput: #1961 + private static InputStream origIn; private static PrintStream origOut, origErr; /** * Handle I/O scoping for overlapping project runs. - * You must call {@link #restoreSystemOutErr} in a finally block. + * You must call {@link #restoreSystemInOutErr} in a finally block. * @param out new temporary output stream for the VM * @param err new temporary error stream for the VM * @see "#36396" */ - public static synchronized void pushSystemOutErr(PrintStream out, PrintStream err) { + public static synchronized void pushSystemInOutErr(InputStream in, PrintStream out, PrintStream err) { if (origOut == null) { + origIn = System.in; origOut = System.out; origErr = System.err; } else { // Oh well, old output may be sent to the wrong window... } + System.setIn(in); System.setOut(out); System.setErr(err); } /** - * Restore original I/O streams after a call to {@link #pushSystemOutErr}. + * Restore original I/O streams after a call to {@link #pushSystemInOutErr}. */ - public static synchronized void restoreSystemOutErr() { + public static synchronized void restoreSystemInOutErr() { if (origOut != null) { + System.setIn(origIn); System.setErr(origErr); System.setOut(origOut); + origIn = null; origOut = null; origErr = null; } else { Index: ant/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java =================================================================== RCS file: /cvs/ant/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java,v retrieving revision 1.6 diff -u -r1.6 BridgeImpl.java --- ant/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java 14 Nov 2003 12:17:01 -0000 1.6 +++ ant/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java 22 Nov 2003 15:45:15 -0000 @@ -14,7 +14,9 @@ package org.apache.tools.ant.module.bridge.impl; import java.io.*; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.*; import org.apache.tools.ant.*; @@ -68,7 +70,9 @@ return null; } - public boolean run(File buildFile, final FileObject buildFileObject, List targets, PrintStream out, PrintStream err, Properties properties, int verbosity, boolean useStatusLine) { + public boolean run(File buildFile, final FileObject buildFileObject, List targets, + InputStream in, PrintStream out, PrintStream err, + Properties properties, int verbosity, boolean useStatusLine) { boolean ok = false; // Make sure "main Ant loader" is used as context loader for duration of the @@ -114,6 +118,15 @@ logger.setMessageOutputLevel(verbosity); logger.setOutputPrintStream(out); logger.setErrorPrintStream(err); + try { + Method m = Project.class.getMethod("setDefaultInputStream", new Class[] {InputStream.class}); // NOI18N + m.invoke(project, new Object[] {in}); + } catch (NoSuchMethodException e) { + // Fine, Ant 1.5, ignore. + } catch (Exception e) { + // Something unexpected. + AntModule.err.notify(ErrorManager.INFORMATIONAL, e); + } //writer.println("#2"); // NOI18N project.addBuildListener(logger); if (AntModule.err.isLoggable(ErrorManager.INFORMATIONAL)) { @@ -154,8 +167,20 @@ logger.buildStarted(new BuildEvent(project)); // Save & restore system output streams. - AntBridge.pushSystemOutErr(new PrintStream(new DemuxOutputStream(project, false)), - new PrintStream(new DemuxOutputStream(project, true))); + InputStream is = System.in; + try { + Class dis = Class.forName("org.apache.tools.ant.DemuxInputStream"); // NOI18N + Constructor c = dis.getConstructor(new Class[] {Project.class}); + is = (InputStream)c.newInstance(new Object[] {project}); + } catch (ClassNotFoundException e) { + // fine, Ant 1.5 - ignore + } catch (Exception e) { + // not so good + AntModule.err.notify(ErrorManager.INFORMATIONAL, e); + } + AntBridge.pushSystemInOutErr(is, + new PrintStream(new DemuxOutputStream(project, false)), + new PrintStream(new DemuxOutputStream(project, true))); try { // Execute the configured project @@ -187,7 +212,7 @@ ev.setException(e); logger.buildFinished(ev); } finally { - AntBridge.restoreSystemOutErr(); + AntBridge.restoreSystemInOutErr(); } // Now check to see if the Project defined any cool new custom tasks.