mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 09:46:02 +02:00
Workaround for j9 bug in PipedInputStream
This commit is contained in:
parent
0d40090288
commit
25e3dfc8f6
1 changed files with 49 additions and 11 deletions
|
@ -28,7 +28,7 @@ public class CommandLauncher {
|
||||||
protected boolean fShowCommand;
|
protected boolean fShowCommand;
|
||||||
protected String[] fCommandArgs;
|
protected String[] fCommandArgs;
|
||||||
|
|
||||||
protected String fErrorMessage;
|
protected String fErrorMessage = "";
|
||||||
|
|
||||||
private String lineSeparator;
|
private String lineSeparator;
|
||||||
|
|
||||||
|
@ -60,6 +60,10 @@ public class CommandLauncher {
|
||||||
return fErrorMessage;
|
return fErrorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setErrorMessage(String error) {
|
||||||
|
fErrorMessage = error;
|
||||||
|
}
|
||||||
|
|
||||||
public String[] getCommandArgs() {
|
public String[] getCommandArgs() {
|
||||||
return fCommandArgs;
|
return fCommandArgs;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +92,7 @@ public class CommandLauncher {
|
||||||
fProcess= ProcessFactory.getFactory().exec(fCommandArgs, env, changeToDirectory.toFile());
|
fProcess= ProcessFactory.getFactory().exec(fCommandArgs, env, changeToDirectory.toFile());
|
||||||
fErrorMessage= "";
|
fErrorMessage= "";
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
fErrorMessage= e.getMessage();
|
setErrorMessage(e.getMessage());
|
||||||
fProcess= null;
|
fProcess= null;
|
||||||
}
|
}
|
||||||
return fProcess;
|
return fProcess;
|
||||||
|
@ -117,9 +121,9 @@ public class CommandLauncher {
|
||||||
* Destroys the process if the monitor becomes canceled
|
* Destroys the process if the monitor becomes canceled
|
||||||
* override to implement a different way to read the process inputs
|
* override to implement a different way to read the process inputs
|
||||||
*/
|
*/
|
||||||
public int waitAndRead(OutputStream out, OutputStream err, IProgressMonitor monitor) {
|
public int waitAndRead(OutputStream output, OutputStream err, IProgressMonitor monitor) {
|
||||||
if (fShowCommand) {
|
if (fShowCommand) {
|
||||||
printCommandLine(fCommandArgs, out);
|
printCommandLine(fCommandArgs, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fProcess == null) {
|
if (fProcess == null) {
|
||||||
|
@ -130,9 +134,42 @@ public class CommandLauncher {
|
||||||
PipedOutputStream outputPipe = new PipedOutputStream();
|
PipedOutputStream outputPipe = new PipedOutputStream();
|
||||||
PipedInputStream errInPipe, inputPipe;
|
PipedInputStream errInPipe, inputPipe;
|
||||||
try {
|
try {
|
||||||
errInPipe = new PipedInputStream(errOutPipe);
|
errInPipe = new PipedInputStream(errOutPipe) {
|
||||||
inputPipe = new PipedInputStream(outputPipe);
|
/**
|
||||||
|
* FIXME: To remove when j9 is fix.
|
||||||
|
* The overloading here corrects a bug in J9
|
||||||
|
* When the ring buffer when full it returns 0 .
|
||||||
|
*/
|
||||||
|
public synchronized int available() throws IOException {
|
||||||
|
if(in < 0)
|
||||||
|
return 0;
|
||||||
|
else if(in == out)
|
||||||
|
return buffer.length;
|
||||||
|
else if (in > out)
|
||||||
|
return in - out;
|
||||||
|
else
|
||||||
|
return in + buffer.length - out;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
inputPipe = new PipedInputStream(outputPipe) {
|
||||||
|
/**
|
||||||
|
* FIXME: To remove when j9 is fix.
|
||||||
|
* The overloading here corrects a bug in J9
|
||||||
|
* When the ring buffer when full returns 0.
|
||||||
|
*/
|
||||||
|
public synchronized int available() throws IOException {
|
||||||
|
if(in < 0)
|
||||||
|
return 0;
|
||||||
|
else if(in == out)
|
||||||
|
return buffer.length;
|
||||||
|
else if (in > out)
|
||||||
|
return in - out;
|
||||||
|
else
|
||||||
|
return in + buffer.length - out;
|
||||||
|
}
|
||||||
|
};
|
||||||
} catch( IOException e ) {
|
} catch( IOException e ) {
|
||||||
|
setErrorMessage("Command canceled");
|
||||||
return COMMAND_CANCELED;
|
return COMMAND_CANCELED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,8 +186,8 @@ public class CommandLauncher {
|
||||||
}
|
}
|
||||||
if ( inputPipe.available() > 0 ) {
|
if ( inputPipe.available() > 0 ) {
|
||||||
nbytes = inputPipe.read(buffer);
|
nbytes = inputPipe.read(buffer);
|
||||||
out.write(buffer, 0, nbytes);
|
output.write(buffer, 0, nbytes);
|
||||||
out.flush();
|
output.flush();
|
||||||
}
|
}
|
||||||
} catch( IOException e) {
|
} catch( IOException e) {
|
||||||
}
|
}
|
||||||
|
@ -167,6 +204,7 @@ public class CommandLauncher {
|
||||||
if (monitor.isCanceled()) {
|
if (monitor.isCanceled()) {
|
||||||
closure.terminate();
|
closure.terminate();
|
||||||
state = COMMAND_CANCELED;
|
state = COMMAND_CANCELED;
|
||||||
|
setErrorMessage("Command canceled");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -186,8 +224,8 @@ public class CommandLauncher {
|
||||||
}
|
}
|
||||||
if ( inputPipe.available() > 0 ) {
|
if ( inputPipe.available() > 0 ) {
|
||||||
nbytes = inputPipe.read(buffer);
|
nbytes = inputPipe.read(buffer);
|
||||||
out.write(buffer, 0, nbytes);
|
output.write(buffer, 0, nbytes);
|
||||||
out.flush();
|
output.flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errInPipe.close();
|
errInPipe.close();
|
||||||
|
|
Loading…
Add table
Reference in a new issue