}
subMonitor.worked(1);
subMonitor.subTask(LaunchingMessages.StandardVMDebugger_Starting_virtual_machine____4);
ListeningConnector connector= getConnector();
if (connector == null) {
abort(LaunchingMessages.StandardVMDebugger_Couldn__t_find_an_appropriate_debug_connector_2, null, IJavaLaunchConfigurationConstants.ERR_CONNECTOR_NOT_AVAILABLE);
}
Map<String, Argument> map= connector.defaultArguments();
specifyArguments(map, port);
Process p= null;
try {
try {
// check for cancellation
if (monitor.isCanceled()) {
return;
}
connector.startListening(map);
File workingDir = getWorkingDir(config);
p = exec(cmdLine, workingDir, envp);
if (p == null) {
return;
}
// check for cancellation
if (monitor.isCanceled()) {
p.destroy();
return;
}
java.util.Date date= new java.util.Date();
Timestamp ts = new Timestamp(date.getTime());
String format= LaunchingMessages.StandardVMRunner__0____1___2;
String label = NLS.bind(format, new String[] { cmdLine[0], ts.toString() });
IProcess process= newProcess(launch, p, label, getDefaultProcessMap());
process.setAttribute(IProcess.ATTR_CMDLINE, renderCommandLineInternal(cmdLine));
subMonitor.worked(1);
subMonitor.subTask(LaunchingMessages.StandardVMDebugger_Establishing_debug_connection____5);
boolean retry= false;
do {
try {
ConnectRunnable runnable = new ConnectRunnable(connector, map);
Thread connectThread = new Thread(runnable, "Listening Connector"); //$NON-NLS-1$
connectThread.setDaemon(true);
connectThread.start();
while (connectThread.isAlive()) {
if (monitor.isCanceled()) {
connector.stopListening(map);
p.destroy();
return;
}
try {
p.exitValue();
// process has terminated - stop waiting for a connection
try {
connector.stopListening(map);
} catch (IOException e) {
// expected
}
checkErrorMessage(process);
} catch (IllegalThreadStateException e) {
// expected while process is alive
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
Exception ex = runnable.getException();
if (ex instanceof IllegalConnectorArgumentsException) {
throw (IllegalConnectorArgumentsException)ex;
}
if (ex instanceof InterruptedIOException) {
throw (InterruptedIOException)ex;
}
if (ex instanceof IOException) {
throw (IOException)ex;
}
VirtualMachine vm= runnable.getVirtualMachine();
if (vm != null) {
DroolsDebugModel.newDebugTarget(launch, vm, renderDebugTarget(config.getClassToLaunch(), port), process, true, false, config.isResumeOnStartup());
subMonitor.worked(1);
subMonitor.done();
}
return;
} catch (InterruptedIOException e) {
checkErrorMessage(process);
// timeout, consult status handler if there is one
IStatus status = new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), IJavaLaunchConfigurationConstants.ERR_VM_CONNECT_TIMEOUT, "", e); //$NON-NLS-1$
IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status);
retry= false;
if (handler == null) {
// if there is no handler, throw the exception
throw new CoreException(status);
}
Object result = handler.handleStatus(status, this);
if (result instanceof Boolean) {
retry = ((Boolean)result).booleanValue();
}
}
} while (retry);
} finally {
connector.stopListening(map);
}
} catch (IOException e) {
abort(LaunchingMessages.StandardVMDebugger_Couldn__t_connect_to_VM_4, e, IJavaLaunchConfigurationConstants.ERR_CONNECTION_FAILED);
} catch (IllegalConnectorArgumentsException e) {
abort(LaunchingMessages.StandardVMDebugger_Couldn__t_connect_to_VM_5, e, IJavaLaunchConfigurationConstants.ERR_CONNECTION_FAILED);