fix-batch-output-as-errors.diff
src/com/goldencode/p2j/ui/ErrorWriterBatch.java 2023-01-27 12:36:05 +0000 | ||
---|---|---|
72 | 72 | |
73 | 73 |
package com.goldencode.p2j.ui; |
74 | 74 | |
75 |
import com.goldencode.p2j.ui.client.chui.driver.batch.*; |
|
75 | 76 |
import com.goldencode.p2j.util.*; |
76 | 77 |
import com.goldencode.util.*; |
77 | 78 | |
... | ... | |
79 | 80 |
* Implements display outputs for batch mode. |
80 | 81 |
*/ |
81 | 82 |
public class ErrorWriterBatch |
82 |
implements ErrorWriter |
|
83 |
implements ErrorWriter, |
|
84 |
BatchPrimitives.OutputWriter |
|
83 | 85 |
{ |
84 | 86 |
/** Client exports access. */ |
85 | 87 |
private ClientExports client = null; |
... | ... | |
232 | 234 |
} |
233 | 235 |
} |
234 | 236 | |
237 |
public void displayOutput(String output) |
|
238 |
{ |
|
239 |
// if the terminal is redirected to a stream, print the output to stream's screen buffer |
|
240 |
if (client != null && client.isRedirected()) |
|
241 |
{ |
|
242 |
client.displayErrorMessage(output, false, null, false); |
|
243 |
} |
|
244 | ||
245 |
if (PlatformHelper.isUnderWindowsFamily() && !isBatchInBackground() && !FileChecker.isConsoleRedirected()) |
|
246 |
{ |
|
247 |
// TODO: In Windows the native message box should be displayed here. |
|
248 |
} |
|
249 | ||
250 |
// then log it to redirected console |
|
251 |
System.out.println(output); |
|
252 |
} |
|
253 | ||
235 | 254 |
/** |
236 | 255 |
* Checks if the client is running in batch background mode. |
237 | 256 |
* |
src/com/goldencode/p2j/ui/client/OutputManager.java 2023-01-27 12:36:05 +0000 | ||
---|---|---|
406 | 406 |
if ((spInsp != null && spInsp.isBatchMode()) || |
407 | 407 |
(mgr != null && mgr.isBatchModeOverride())) |
408 | 408 |
{ |
409 |
ErrorManager.initErrorWriter(new ErrorWriterBatch(ThinClient.getInstance())); |
|
409 |
ErrorWriterBatch errorWriterBatch = new ErrorWriterBatch(ThinClient.getInstance()); |
|
410 |
ErrorManager.initErrorWriter(errorWriterBatch); |
|
411 | ||
412 |
OutputPrimitives op = getDriver().getPrimitives(); |
|
413 |
if (op instanceof BatchPrimitives) |
|
414 |
{ |
|
415 |
((BatchPrimitives) op).setOutputWriter(errorWriterBatch); |
|
416 |
} |
|
410 | 417 |
} |
411 | 418 |
else |
412 | 419 |
{ |
src/com/goldencode/p2j/ui/client/chui/driver/batch/BatchPrimitives.java 2023-01-27 12:36:05 +0000 | ||
---|---|---|
87 | 87 |
{ |
88 | 88 |
/** Flag indicating whether we need to do special processing or just ignore calls. */ |
89 | 89 |
private boolean isActive = false; |
90 |
|
|
91 |
private OutputWriter outputWriter; |
|
90 | 92 | |
91 | 93 |
/** |
92 | 94 |
* Constructor. |
... | ... | |
273 | 275 |
// Output to STDOUT only if we have something to output |
274 | 276 |
if (lineOut.length() > 0) |
275 | 277 |
{ |
276 |
ErrorManager.displayError(lineOut); |
|
278 |
if (outputWriter != null) |
|
279 |
{ |
|
280 |
outputWriter.displayOutput(lineOut); |
|
281 |
} |
|
282 |
else |
|
283 |
{ |
|
284 |
ErrorManager.displayError(lineOut); |
|
285 |
} |
|
277 | 286 |
} |
278 | 287 |
} |
279 | 288 |
} |
... | ... | |
287 | 296 |
} |
288 | 297 |
} |
289 | 298 |
} |
299 |
|
|
300 |
public void setOutputWriter(OutputWriter outputWriter) |
|
301 |
{ |
|
302 |
this.outputWriter = outputWriter; |
|
303 |
} |
|
304 |
|
|
305 |
public interface OutputWriter |
|
306 |
{ |
|
307 |
void displayOutput(String output); |
|
308 |
} |
|
290 | 309 |
} |