Lines 6-12
Link Here
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
7 |
* |
8 |
* Contributors: |
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Siemens AG, Nils Hagge - Added using the different output, error, |
11 |
* and info streams |
10 |
*******************************************************************************/ |
12 |
*******************************************************************************/ |
11 |
package org.eclipse.cdt.core; |
13 |
package org.eclipse.cdt.core; |
12 |
|
14 |
|
Lines 33-42
Link Here
|
33 |
import org.eclipse.core.runtime.IPath; |
35 |
import org.eclipse.core.runtime.IPath; |
34 |
import org.eclipse.core.runtime.Path; |
36 |
import org.eclipse.core.runtime.Path; |
35 |
|
37 |
|
36 |
public class ErrorParserManager extends OutputStream { |
38 |
public class ErrorParserManager //extends OutputStream |
37 |
|
39 |
{ |
38 |
private int nOpens; |
|
|
39 |
|
40 |
|
|
|
41 |
// private int nOpens; |
42 |
private int nTotalOpens; // Nils |
43 |
|
40 |
private final static String OLD_PREF_ERROR_PARSER = "errorOutputParser"; //$NON-NLS-1$ |
44 |
private final static String OLD_PREF_ERROR_PARSER = "errorOutputParser"; //$NON-NLS-1$ |
41 |
public final static String PREF_ERROR_PARSER = CCorePlugin.PLUGIN_ID + ".errorOutputParser"; //$NON-NLS-1$ |
45 |
public final static String PREF_ERROR_PARSER = CCorePlugin.PLUGIN_ID + ".errorOutputParser"; //$NON-NLS-1$ |
42 |
|
46 |
|
Lines 52-58
Link Here
|
52 |
private IPath fBaseDirectory; |
56 |
private IPath fBaseDirectory; |
53 |
|
57 |
|
54 |
private String previousLine; |
58 |
private String previousLine; |
55 |
private OutputStream outputStream; |
59 |
|
|
|
60 |
//private OutputStream outputStream; |
61 |
// keep output and error stream separate |
62 |
private ScanOutputStream outputSink = new ScanOutputStream(); //Nils |
63 |
private ScanOutputStream errorSink = new ScanOutputStream(); |
64 |
|
56 |
private StringBuffer currentLine = new StringBuffer(); |
65 |
private StringBuffer currentLine = new StringBuffer(); |
57 |
|
66 |
|
58 |
private StringBuffer scratchBuffer = new StringBuffer(); |
67 |
private StringBuffer scratchBuffer = new StringBuffer(); |
Lines 360-366
Link Here
|
360 |
* @param cos |
369 |
* @param cos |
361 |
*/ |
370 |
*/ |
362 |
public void setOutputStream(OutputStream os) { |
371 |
public void setOutputStream(OutputStream os) { |
363 |
outputStream = os; |
372 |
//outputStream = os; |
|
|
373 |
outputSink.setTarget(os); |
364 |
} |
374 |
} |
365 |
|
375 |
|
366 |
/** |
376 |
/** |
Lines 369-423
Link Here
|
369 |
* @return OutputStream |
379 |
* @return OutputStream |
370 |
*/ |
380 |
*/ |
371 |
public OutputStream getOutputStream() { |
381 |
public OutputStream getOutputStream() { |
372 |
nOpens++; |
382 |
//nOpens++; |
373 |
return this; |
383 |
outputSink.open(); |
374 |
} |
384 |
return outputSink; |
375 |
|
|
|
376 |
/** |
377 |
* @see java.io.OutputStream#close() |
378 |
*/ |
379 |
public void close() throws IOException { |
380 |
if (nOpens > 0 && --nOpens == 0) { |
381 |
checkLine(true); |
382 |
fDirectoryStack.removeAllElements(); |
383 |
fBaseDirectory = null; |
384 |
if (outputStream != null) |
385 |
outputStream.close(); |
386 |
} |
387 |
} |
385 |
} |
388 |
|
386 |
|
389 |
/** |
387 |
public OutputStream getErrorStream() |
390 |
* @see java.io.OutputStream#flush() |
388 |
{ |
391 |
*/ |
389 |
errorSink.open(); |
392 |
public void flush() throws IOException { |
390 |
return errorSink; |
393 |
if (outputStream != null) |
|
|
394 |
outputStream.flush(); |
395 |
} |
391 |
} |
396 |
|
392 |
|
397 |
/** |
393 |
public void setErrorStream(OutputStream es) |
398 |
* @see java.io.OutputStream#write(int) |
394 |
{ |
399 |
*/ |
395 |
errorSink.setTarget(es); |
400 |
public synchronized void write(int b) throws IOException { |
|
|
401 |
currentLine.append((char) b); |
402 |
checkLine(false); |
403 |
if (outputStream != null) |
404 |
outputStream.write(b); |
405 |
} |
396 |
} |
406 |
|
397 |
|
407 |
public synchronized void write(byte[] b, int off, int len) throws IOException { |
398 |
// Nils Hagge |
408 |
if (b == null) { |
399 |
private class ScanOutputStream extends OutputStream |
409 |
throw new NullPointerException(); |
400 |
{ |
410 |
} else if (off != 0 || (len < 0) || (len > b.length)) { |
401 |
private OutputStream target = null; |
411 |
throw new IndexOutOfBoundsException(); |
402 |
private int nOpens; // number of references to this ScanOutputStream |
412 |
} else if (len == 0) { |
403 |
|
413 |
return; |
404 |
public void open() |
|
|
405 |
{ |
406 |
nOpens++; |
407 |
nTotalOpens++; |
408 |
} |
409 |
|
410 |
public void setTarget(OutputStream target) |
411 |
{ |
412 |
this.target = target; |
413 |
} |
414 |
|
415 |
/** |
416 |
* @see java.io.OutputStream#flush() |
417 |
*/ |
418 |
public void flush() throws IOException |
419 |
{ |
420 |
if(target != null) |
421 |
target.flush(); |
422 |
} |
423 |
|
424 |
/** |
425 |
* @see java.io.OutputStream#write(int) |
426 |
*/ |
427 |
public synchronized void write(int b) throws IOException |
428 |
{ |
429 |
currentLine.append((char) b); |
430 |
checkLine(false); |
431 |
if(target != null) |
432 |
target.write(b); |
433 |
} |
434 |
|
435 |
public synchronized void write(byte[] b, int off, int len) |
436 |
throws IOException |
437 |
{ |
438 |
if(b == null) |
439 |
throw new NullPointerException(); |
440 |
else if(off != 0 || (len < 0) || (len > b.length)) |
441 |
throw new IndexOutOfBoundsException(); |
442 |
else if(len == 0) |
443 |
return; |
444 |
|
445 |
currentLine.append(new String(b, 0, len)); |
446 |
checkLine(false); |
447 |
if(target != null) |
448 |
target.write(b, off, len); |
449 |
} |
450 |
|
451 |
/** |
452 |
* @see java.io.OutputStream#close() |
453 |
*/ |
454 |
public void close() throws IOException { |
455 |
if(nTotalOpens > 0 && --nTotalOpens == 0) |
456 |
{ |
457 |
checkLine(true); |
458 |
fDirectoryStack.removeAllElements(); |
459 |
fBaseDirectory = null; |
460 |
} |
461 |
if (nOpens > 0 && --nOpens == 0) |
462 |
{ |
463 |
if(target != null) |
464 |
target.close(); |
465 |
} |
414 |
} |
466 |
} |
415 |
currentLine.append(new String(b, 0, len)); |
|
|
416 |
checkLine(false); |
417 |
if (outputStream != null) |
418 |
outputStream.write(b, off, len); |
419 |
} |
467 |
} |
420 |
|
468 |
|
421 |
private void checkLine(boolean flush) { |
469 |
private void checkLine(boolean flush) { |
422 |
String buffer = currentLine.toString(); |
470 |
String buffer = currentLine.toString(); |
423 |
int i = 0; |
471 |
int i = 0; |
Lines 440-446
Link Here
|
440 |
|
488 |
|
441 |
public boolean reportProblems() { |
489 |
public boolean reportProblems() { |
442 |
boolean reset = false; |
490 |
boolean reset = false; |
443 |
if (nOpens == 0) { |
491 |
if (nTotalOpens == 0) { |
444 |
Iterator iter = fErrors.iterator(); |
492 |
Iterator iter = fErrors.iterator(); |
445 |
while (iter.hasNext()) { |
493 |
while (iter.hasNext()) { |
446 |
ProblemMarkerInfo problemMarkerInfo = (ProblemMarkerInfo) iter.next(); |
494 |
ProblemMarkerInfo problemMarkerInfo = (ProblemMarkerInfo) iter.next(); |