mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 19:35:36 +02:00
Bug 489051 - JSchProcess#exitValue() should throws IllegalThreadStateException
Call to exitValue() throws IllegalThreadStateException when the process has not terminated insted of -1. Change-Id: Ia119ecf0c7aba34619f2b95c072bd4261f1ac898 Signed-off-by: Wainer dos Santos Moschetta <wainersm@linux.vnet.ibm.com>
This commit is contained in:
parent
ad4c9cf354
commit
731be3a50e
4 changed files with 29 additions and 0 deletions
|
@ -21,6 +21,7 @@ import org.eclipse.remote.core.IRemoteProcessControlService;
|
||||||
import org.eclipse.remote.core.IRemoteProcessSignalService;
|
import org.eclipse.remote.core.IRemoteProcessSignalService;
|
||||||
import org.eclipse.remote.core.IRemoteProcessTerminalService;
|
import org.eclipse.remote.core.IRemoteProcessTerminalService;
|
||||||
import org.eclipse.remote.core.exception.RemoteConnectionException;
|
import org.eclipse.remote.core.exception.RemoteConnectionException;
|
||||||
|
import org.eclipse.remote.internal.jsch.core.messages.Messages;
|
||||||
|
|
||||||
import com.jcraft.jsch.Channel;
|
import com.jcraft.jsch.Channel;
|
||||||
import com.jcraft.jsch.ChannelExec;
|
import com.jcraft.jsch.ChannelExec;
|
||||||
|
@ -162,6 +163,9 @@ public class JSchProcess implements IRemoteProcessControlService, IRemoteProcess
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int exitValue() {
|
public int exitValue() {
|
||||||
|
if(!isCompleted()) {
|
||||||
|
throw new IllegalThreadStateException(Messages.JSchProcess_exitValue_exception_msg);
|
||||||
|
}
|
||||||
return fChannel.getExitStatus();
|
return fChannel.getExitStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ public class Messages extends NLS {
|
||||||
public static String JSchConnectionProxyFactory_ProxyCommandFailed;
|
public static String JSchConnectionProxyFactory_ProxyCommandFailed;
|
||||||
public static String JSchConnectionProxyFactory_timedOut;
|
public static String JSchConnectionProxyFactory_timedOut;
|
||||||
public static String JSchConnectionProxyFactory_wasCanceled;
|
public static String JSchConnectionProxyFactory_wasCanceled;
|
||||||
|
public static String JSchProcess_exitValue_exception_msg;
|
||||||
public static String JSchProcessBuilder_Connection_is_not_open;
|
public static String JSchProcessBuilder_Connection_is_not_open;
|
||||||
public static String JschFileStore_Connection_is_not_open;
|
public static String JschFileStore_Connection_is_not_open;
|
||||||
public static String JschFileStore_File_doesnt_exist;
|
public static String JschFileStore_File_doesnt_exist;
|
||||||
|
|
|
@ -32,6 +32,7 @@ JSchConnectionProxyFactory_failed=failed
|
||||||
JSchConnectionProxyFactory_ProxyCommandFailed=Proxy command "{0}" {1} and printed message "{2}"
|
JSchConnectionProxyFactory_ProxyCommandFailed=Proxy command "{0}" {1} and printed message "{2}"
|
||||||
JSchConnectionProxyFactory_timedOut=timed out
|
JSchConnectionProxyFactory_timedOut=timed out
|
||||||
JSchConnectionProxyFactory_wasCanceled=was canceled
|
JSchConnectionProxyFactory_wasCanceled=was canceled
|
||||||
|
JSchProcess_exitValue_exception_msg=process has not exited
|
||||||
JSchProcessBuilder_Connection_is_not_open=Connection is not open
|
JSchProcessBuilder_Connection_is_not_open=Connection is not open
|
||||||
JschFileStore_Connection_is_not_open=Connection is not open
|
JschFileStore_Connection_is_not_open=Connection is not open
|
||||||
JschFileStore_File_doesnt_exist=File {0} doesn't exist
|
JschFileStore_File_doesnt_exist=File {0} doesn't exist
|
||||||
|
|
|
@ -19,6 +19,7 @@ import org.eclipse.remote.core.IRemoteProcess;
|
||||||
import org.eclipse.remote.core.IRemoteProcessBuilder;
|
import org.eclipse.remote.core.IRemoteProcessBuilder;
|
||||||
import org.eclipse.remote.core.IRemoteProcessService;
|
import org.eclipse.remote.core.IRemoteProcessService;
|
||||||
import org.eclipse.remote.core.IRemoteServicesManager;
|
import org.eclipse.remote.core.IRemoteServicesManager;
|
||||||
|
import org.eclipse.remote.core.RemoteProcessAdapter;
|
||||||
import org.eclipse.remote.internal.jsch.core.JSchConnection;
|
import org.eclipse.remote.internal.jsch.core.JSchConnection;
|
||||||
|
|
||||||
public class ProcessTests extends TestCase {
|
public class ProcessTests extends TestCase {
|
||||||
|
@ -171,6 +172,28 @@ public class ProcessTests extends TestCase {
|
||||||
assertEquals("0123456789", result.toString());
|
assertEquals("0123456789", result.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testExitValue() {
|
||||||
|
IRemoteProcessService processService = fRemoteConnection.getService(IRemoteProcessService.class);
|
||||||
|
assertNotNull(processService);
|
||||||
|
IRemoteProcessBuilder builder = processService.getProcessBuilder(new String[]{"sleep","60"}); //$NON-NLS-1$
|
||||||
|
assertNotNull(builder);
|
||||||
|
IRemoteProcess rp = null;
|
||||||
|
try {
|
||||||
|
rp = builder.start();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
fail(e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
assertNotNull(rp);
|
||||||
|
Process p = new RemoteProcessAdapter(rp);
|
||||||
|
try {
|
||||||
|
p.exitValue();
|
||||||
|
fail("Process has not exited. Should throws an IllegalThreadStateException exception");
|
||||||
|
} catch(IllegalThreadStateException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class);
|
IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class);
|
||||||
|
|
Loading…
Add table
Reference in a new issue