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/run/TargetExecutor.java (-1 / +10 lines)
Lines 37-42 Link Here
37
import org.apache.tools.ant.module.api.AntProjectCookie;
37
import org.apache.tools.ant.module.api.AntProjectCookie;
38
import org.apache.tools.ant.module.api.IntrospectedInfo;
38
import org.apache.tools.ant.module.api.IntrospectedInfo;
39
import org.apache.tools.ant.module.bridge.AntBridge;
39
import org.apache.tools.ant.module.bridge.AntBridge;
40
import org.openide.util.io.ReaderInputStream;
40
41
41
/** Executes an Ant Target asynchronously in the IDE.
42
/** Executes an Ant Target asynchronously in the IDE.
42
 */
43
 */
Lines 216-223 Link Here
216
            return;
217
            return;
217
        }
218
        }
218
        
219
        
220
        InputStream in = null;
221
        try {
222
            in = new ReaderInputStream(io.getIn(),
223
            System.getProperty("file.encoding", "UTF-8")); // NOI18N
224
        } catch (IOException e) {
225
            AntModule.err.notify(ErrorManager.INFORMATIONAL, e);
226
        }
227
        
219
        ok = AntBridge.getInterface().run(buildFile, pcookie.getFileObject(), targetNames,
228
        ok = AntBridge.getInterface().run(buildFile, pcookie.getFileObject(), targetNames,
220
                                          out, err, properties, verbosity, outputStream == null);
229
                                          in, out, err, properties, verbosity, outputStream == null);
221
    }
230
    }
222
231
223
    // See #29245 for more details. Relevant only for Ant 1.5.1
232
    // See #29245 for more details. Relevant only for Ant 1.5.1
(-)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/bridge/AntBridge.java (-4 / +9 lines)
Lines 366-398 Link Here
366
    // Better still would be to let the execution engine handle it entirely,
366
    // Better still would be to let the execution engine handle it entirely,
367
    // by creating a custom InputOutput: #1961
367
    // by creating a custom InputOutput: #1961
368
    
368
    
369
    private static InputStream origIn;
369
    private static PrintStream origOut, origErr;
370
    private static PrintStream origOut, origErr;
370
    
371
    
371
    /**
372
    /**
372
     * Handle I/O scoping for overlapping project runs.
373
     * Handle I/O scoping for overlapping project runs.
373
     * You must call {@link #restoreSystemOutErr} in a finally block.
374
     * You must call {@link #restoreSystemInOutErr} in a finally block.
374
     * @param out new temporary output stream for the VM
375
     * @param out new temporary output stream for the VM
375
     * @param err new temporary error stream for the VM
376
     * @param err new temporary error stream for the VM
376
     * @see "#36396"
377
     * @see "#36396"
377
     */
378
     */
378
    public static synchronized void pushSystemOutErr(PrintStream out, PrintStream err) {
379
    public static synchronized void pushSystemInOutErr(InputStream in, PrintStream out, PrintStream err) {
379
        if (origOut == null) {
380
        if (origOut == null) {
381
            origIn = System.in;
380
            origOut = System.out;
382
            origOut = System.out;
381
            origErr = System.err;
383
            origErr = System.err;
382
        } else {
384
        } else {
383
            // Oh well, old output may be sent to the wrong window...
385
            // Oh well, old output may be sent to the wrong window...
384
        }
386
        }
387
        System.setIn(in);
385
        System.setOut(out);
388
        System.setOut(out);
386
        System.setErr(err);
389
        System.setErr(err);
387
    }
390
    }
388
    
391
    
389
    /**
392
    /**
390
     * Restore original I/O streams after a call to {@link #pushSystemOutErr}.
393
     * Restore original I/O streams after a call to {@link #pushSystemInOutErr}.
391
     */
394
     */
392
    public static synchronized void restoreSystemOutErr() {
395
    public static synchronized void restoreSystemInOutErr() {
393
        if (origOut != null) {
396
        if (origOut != null) {
397
            System.setIn(origIn);
394
            System.setErr(origErr);
398
            System.setErr(origErr);
395
            System.setOut(origOut);
399
            System.setOut(origOut);
400
            origIn = null;
396
            origOut = null;
401
            origOut = null;
397
            origErr = null;
402
            origErr = null;
398
        } else {
403
        } else {
(-)ant/src-bridge/org/apache/tools/ant/module/bridge/impl/BridgeImpl.java (-4 / +29 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.util.*;
21
import java.util.*;
20
import org.apache.tools.ant.*;
22
import org.apache.tools.ant.*;
Lines 68-74 Link Here
68
        return null;
70
        return null;
69
    }
71
    }
70
    
72
    
71
    public boolean run(File buildFile, final FileObject buildFileObject, List targets, PrintStream out, PrintStream err, Properties properties, int verbosity, boolean useStatusLine) {
73
    public boolean run(File buildFile, final FileObject buildFileObject, List targets,
74
                       InputStream in, PrintStream out, PrintStream err,
75
                       Properties properties, int verbosity, boolean useStatusLine) {
72
        boolean ok = false;
76
        boolean ok = false;
73
        
77
        
74
        // Make sure "main Ant loader" is used as context loader for duration of the
78
        // Make sure "main Ant loader" is used as context loader for duration of the
Lines 114-119 Link Here
114
            logger.setMessageOutputLevel(verbosity);
118
            logger.setMessageOutputLevel(verbosity);
115
            logger.setOutputPrintStream(out);
119
            logger.setOutputPrintStream(out);
116
            logger.setErrorPrintStream(err);
120
            logger.setErrorPrintStream(err);
121
            try {
122
                Method m = Project.class.getMethod("setDefaultInputStream", new Class[] {InputStream.class}); // NOI18N
123
                m.invoke(project, new Object[] {in});
124
            } catch (NoSuchMethodException e) {
125
                // Fine, Ant 1.5, ignore.
126
            } catch (Exception e) {
127
                // Something unexpected.
128
                AntModule.err.notify(ErrorManager.INFORMATIONAL, e);
129
            }
117
            //writer.println("#2"); // NOI18N
130
            //writer.println("#2"); // NOI18N
118
            project.addBuildListener(logger);
131
            project.addBuildListener(logger);
119
            if (AntModule.err.isLoggable(ErrorManager.INFORMATIONAL)) {
132
            if (AntModule.err.isLoggable(ErrorManager.INFORMATIONAL)) {
Lines 154-161 Link Here
154
        logger.buildStarted(new BuildEvent(project));
167
        logger.buildStarted(new BuildEvent(project));
155
        
168
        
156
        // Save & restore system output streams.
169
        // Save & restore system output streams.
157
        AntBridge.pushSystemOutErr(new PrintStream(new DemuxOutputStream(project, false)),
170
        InputStream is = System.in;
158
                                   new PrintStream(new DemuxOutputStream(project, true)));
171
        try {
172
            Class dis = Class.forName("org.apache.tools.ant.DemuxInputStream"); // NOI18N
173
            Constructor c = dis.getConstructor(new Class[] {Project.class});
174
            is = (InputStream)c.newInstance(new Object[] {project});
175
        } catch (ClassNotFoundException e) {
176
            // fine, Ant 1.5 - ignore
177
        } catch (Exception e) {
178
            // not so good
179
            AntModule.err.notify(ErrorManager.INFORMATIONAL, e);
180
        }
181
        AntBridge.pushSystemInOutErr(is,
182
                                     new PrintStream(new DemuxOutputStream(project, false)),
183
                                     new PrintStream(new DemuxOutputStream(project, true)));
159
184
160
        try {
185
        try {
161
            // Execute the configured project
186
            // Execute the configured project
Lines 187-193 Link Here
187
            ev.setException(e);
212
            ev.setException(e);
188
            logger.buildFinished(ev);
213
            logger.buildFinished(ev);
189
        } finally {
214
        } finally {
190
            AntBridge.restoreSystemOutErr();
215
            AntBridge.restoreSystemInOutErr();
191
        }
216
        }
192
        
217
        
193
        // Now check to see if the Project defined any cool new custom tasks.
218
        // Now check to see if the Project defined any cool new custom tasks.

Return to bug 37431