This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 37431
Collapse All | Expand All

(-)ant/src/org/apache/tools/ant/module/bridge/AntBridge.java (-4 / +9 lines)
Lines 509-541 Link Here
509
    // Better still would be to let the execution engine handle it entirely,
509
    // Better still would be to let the execution engine handle it entirely,
510
    // by creating a custom InputOutput: #1961
510
    // by creating a custom InputOutput: #1961
511
    
511
    
512
    private static InputStream origIn;
512
    private static PrintStream origOut, origErr;
513
    private static PrintStream origOut, origErr;
513
    
514
    
514
    /**
515
    /**
515
     * Handle I/O scoping for overlapping project runs.
516
     * Handle I/O scoping for overlapping project runs.
516
     * You must call {@link #restoreSystemOutErr} in a finally block.
517
     * You must call {@link #restoreSystemInOutErr} in a finally block.
517
     * @param out new temporary output stream for the VM
518
     * @param out new temporary output stream for the VM
518
     * @param err new temporary error stream for the VM
519
     * @param err new temporary error stream for the VM
519
     * @see "#36396"
520
     * @see "#36396"
520
     */
521
     */
521
    public static synchronized void pushSystemOutErr(PrintStream out, PrintStream err) {
522
    public static synchronized void pushSystemInOutErr(InputStream in, PrintStream out, PrintStream err) {
522
        if (origOut == null) {
523
        if (origOut == null) {
524
            origIn = System.in;
523
            origOut = System.out;
525
            origOut = System.out;
524
            origErr = System.err;
526
            origErr = System.err;
525
        } else {
527
        } else {
526
            // Oh well, old output may be sent to the wrong window...
528
            // Oh well, old output may be sent to the wrong window...
527
        }
529
        }
530
        System.setIn(in);
528
        System.setOut(out);
531
        System.setOut(out);
529
        System.setErr(err);
532
        System.setErr(err);
530
    }
533
    }
531
    
534
    
532
    /**
535
    /**
533
     * Restore original I/O streams after a call to {@link #pushSystemOutErr}.
536
     * Restore original I/O streams after a call to {@link #pushSystemInOutErr}.
534
     */
537
     */
535
    public static synchronized void restoreSystemOutErr() {
538
    public static synchronized void restoreSystemInOutErr() {
536
        if (origOut != null) {
539
        if (origOut != null) {
540
            System.setIn(origIn);
537
            System.setErr(origErr);
541
            System.setErr(origErr);
538
            System.setOut(origOut);
542
            System.setOut(origOut);
543
            origIn = null;
539
            origOut = null;
544
            origOut = null;
540
            origErr = null;
545
            origErr = null;
541
        } else {
546
        } else {
(-)ant/src/org/apache/tools/ant/module/bridge/BridgeInterface.java (-1 / +2 lines)
Lines 14-19 Link Here
14
package org.apache.tools.ant.module.bridge;
14
package org.apache.tools.ant.module.bridge;
15
15
16
import java.io.File;
16
import java.io.File;
17
import java.io.InputStream;
17
import java.io.PrintStream;
18
import java.io.PrintStream;
18
import java.util.List;
19
import java.util.List;
19
import java.util.Properties;
20
import java.util.Properties;
Lines 30-36 Link Here
30
     * @param buildFile an Ant build script
31
     * @param buildFile an Ant build script
31
     * @param targets a list of target names to run, or null to run the default target
32
     * @param targets a list of target names to run, or null to run the default target
32
     */
33
     */
33
    boolean run(File buildFile, FileObject buildFileObject, List targets, PrintStream out, PrintStream err, Properties properties, int verbosity, boolean useStatusLine);
34
    boolean run(File buildFile, FileObject buildFileObject, List targets, InputStream in, PrintStream out, PrintStream err, Properties properties, int verbosity, boolean useStatusLine);
34
    
35
    
35
    /**
36
    /**
36
     * Get some informational value of the Ant version.
37
     * Get some informational value of the Ant version.
(-)ant/src/org/apache/tools/ant/module/run/TargetExecutor.java (-1 / +10 lines)
Lines 36-41 Link Here
36
import org.apache.tools.ant.module.api.AntProjectCookie;
36
import org.apache.tools.ant.module.api.AntProjectCookie;
37
import org.apache.tools.ant.module.api.IntrospectedInfo;
37
import org.apache.tools.ant.module.api.IntrospectedInfo;
38
import org.apache.tools.ant.module.bridge.AntBridge;
38
import org.apache.tools.ant.module.bridge.AntBridge;
39
import org.openide.util.io.ReaderInputStream;
39
40
40
/** Executes an Ant Target asynchronously in the IDE.
41
/** Executes an Ant Target asynchronously in the IDE.
41
 */
42
 */
Lines 248-255 Link Here
248
        // Don't hog the CPU, the build might take a while:
249
        // Don't hog the CPU, the build might take a while:
249
        Thread.currentThread().setPriority((Thread.MIN_PRIORITY + Thread.NORM_PRIORITY) / 2);
250
        Thread.currentThread().setPriority((Thread.MIN_PRIORITY + Thread.NORM_PRIORITY) / 2);
250
        
251
        
252
        InputStream in = null;
253
        try {
254
            in = new ReaderInputStream(io.getIn(),
255
            System.getProperty("file.encoding", "UTF-8")); // NOI18N
256
        } catch (IOException e) {
257
            AntModule.err.notify(ErrorManager.INFORMATIONAL, e);
258
        }
259
        
251
        ok = AntBridge.getInterface().run(buildFile, pcookie.getFileObject(), targetNames,
260
        ok = AntBridge.getInterface().run(buildFile, pcookie.getFileObject(), targetNames,
252
                                          out, err, properties, verbosity, outputStream == null);
261
                                          in, out, err, properties, verbosity, outputStream == null);
253
    }
262
    }
254
263
255
}
264
}
(-)ant/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java (-4 / +31 lines)
Lines 14-20 Link Here
14
package org.apache.tools.ant.module.bridge.impl;
14
package org.apache.tools.ant.module.bridge.impl;
15
15
16
import java.io.*;
16
import java.io.*;
17
import java.lang.reflect.Constructor;
17
import java.lang.reflect.Field;
18
import java.lang.reflect.Field;
19
import java.lang.reflect.Method;
18
import java.lang.reflect.Modifier;
20
import java.lang.reflect.Modifier;
19
import java.net.URL;
21
import java.net.URL;
20
import java.util.*;
22
import java.util.*;
Lines 79-85 Link Here
79
        return null;
81
        return null;
80
    }
82
    }
81
    
83
    
82
    public boolean run(File buildFile, final FileObject buildFileObject, List targets, PrintStream out, PrintStream err, Properties properties, int verbosity, boolean useStatusLine) {
84
    public boolean run(File buildFile, final FileObject buildFileObject, List targets,
85
                       InputStream in, PrintStream out, PrintStream err,
86
                       Properties properties, int verbosity, boolean useStatusLine) {
83
        boolean ok = false;
87
        boolean ok = false;
84
        
88
        
85
        // Make sure "main Ant loader" is used as context loader for duration of the
89
        // Make sure "main Ant loader" is used as context loader for duration of the
Lines 119-124 Link Here
119
            logger.setMessageOutputLevel(verbosity);
123
            logger.setMessageOutputLevel(verbosity);
120
            logger.setOutputPrintStream(out);
124
            logger.setOutputPrintStream(out);
121
            logger.setErrorPrintStream(err);
125
            logger.setErrorPrintStream(err);
126
            try {
127
                Method m = Project.class.getMethod("setDefaultInputStream", new Class[] {InputStream.class}); // NOI18N
128
                m.invoke(project, new Object[] {in});
129
            } catch (NoSuchMethodException e) {
130
                // Fine, Ant 1.5, ignore.
131
            } catch (Exception e) {
132
                // Something unexpected.
133
                AntModule.err.notify(ErrorManager.INFORMATIONAL, e);
134
            }
122
            //writer.println("#2"); // NOI18N
135
            //writer.println("#2"); // NOI18N
123
            project.addBuildListener(logger);
136
            project.addBuildListener(logger);
124
            if (AntModule.err.isLoggable(ErrorManager.INFORMATIONAL)) {
137
            if (AntModule.err.isLoggable(ErrorManager.INFORMATIONAL)) {
Lines 158-163 Link Here
158
            }
171
            }
159
            out.close();
172
            out.close();
160
            err.close();
173
            err.close();
174
            inc.close();
161
            return false;
175
            return false;
162
        }
176
        }
163
        
177
        
Lines 166-173 Link Here
166
        logger.buildStarted(new BuildEvent(project));
180
        logger.buildStarted(new BuildEvent(project));
167
        
181
        
168
        // Save & restore system output streams.
182
        // Save & restore system output streams.
169
        AntBridge.pushSystemOutErr(new PrintStream(new DemuxOutputStream(project, false)),
183
        InputStream is = System.in;
170
                                   new PrintStream(new DemuxOutputStream(project, true)));
184
        try {
185
            Class dis = Class.forName("org.apache.tools.ant.DemuxInputStream"); // NOI18N
186
            Constructor c = dis.getConstructor(new Class[] {Project.class});
187
            is = (InputStream)c.newInstance(new Object[] {project});
188
        } catch (ClassNotFoundException e) {
189
            // fine, Ant 1.5 - ignore
190
        } catch (Exception e) {
191
            // not so good
192
            AntModule.err.notify(ErrorManager.INFORMATIONAL, e);
193
        }
194
        AntBridge.pushSystemInOutErr(is,
195
                                     new PrintStream(new DemuxOutputStream(project, false)),
196
                                     new PrintStream(new DemuxOutputStream(project, true)));
171
197
172
        try {
198
        try {
173
            // Execute the configured project
199
            // Execute the configured project
Lines 199-207 Link Here
199
            ev.setException(e);
225
            ev.setException(e);
200
            logger.buildFinished(ev);
226
            logger.buildFinished(ev);
201
        } finally {
227
        } finally {
202
            AntBridge.restoreSystemOutErr();
228
            AntBridge.restoreSystemInOutErr();
203
            out.close();
229
            out.close();
204
            err.close();
230
            err.close();
231
            in.close();
205
        }
232
        }
206
        
233
        
207
        // Now check to see if the Project defined any cool new custom tasks.
234
        // Now check to see if the Project defined any cool new custom tasks.

Return to bug 37431