use of org.eclipse.wst.server.ui.internal.LaunchClientJob in project webtools.servertools by eclipse.
the class RunOnServerLaunchConfigurationDelegate method launch.
public void launch(ILaunchConfiguration configuration, String launchMode, final ILaunch launch2, IProgressMonitor monitor) throws CoreException {
String serverId = configuration.getAttribute(ATTR_SERVER_ID, (String) null);
String moduleArt = configuration.getAttribute(ATTR_MODULE_ARTIFACT, (String) null);
String moduleArtifactClass = configuration.getAttribute(ATTR_MODULE_ARTIFACT_CLASS, (String) null);
String laId = configuration.getAttribute(ATTR_LAUNCHABLE_ADAPTER_ID, (String) null);
String clientId = configuration.getAttribute(ATTR_CLIENT_ID, (String) null);
IServer server = ServerCore.findServer(serverId);
IModule module = null;
ModuleArtifactDelegate moduleArtifact = null;
ILaunchableAdapter launchableAdapter = null;
if (laId != null)
launchableAdapter = ServerPlugin.findLaunchableAdapter(laId);
IClient client = ServerPlugin.findClient(clientId);
try {
Class c = Class.forName(moduleArtifactClass);
moduleArtifact = (ModuleArtifactDelegate) c.newInstance();
moduleArtifact.deserialize(moduleArt);
module = moduleArtifact.getModule();
} catch (Throwable t) {
if (Trace.WARNING) {
Trace.trace(Trace.STRING_WARNING, "Could not load module artifact delegate class");
}
}
if (moduleArtifact == null)
throw new CoreException(new Status(IStatus.ERROR, ServerUIPlugin.PLUGIN_ID, Messages.errorLaunchConfig));
if (module == null)
throw new CoreException(new Status(IStatus.ERROR, ServerUIPlugin.PLUGIN_ID, Messages.errorLaunchConfig));
if (server == null)
throw new CoreException(new Status(IStatus.ERROR, ServerUIPlugin.PLUGIN_ID, Messages.errorInvalidServer));
if (launchableAdapter == null)
throw new CoreException(new Status(IStatus.ERROR, ServerUIPlugin.PLUGIN_ID, Messages.errorLaunchConfig));
final Shell[] shell2 = new Shell[1];
Display.getDefault().syncExec(new Runnable() {
public void run() {
shell2[0] = EclipseUtil.getShell();
}
});
final Shell shell = shell2[0];
final IAdaptable info = new IAdaptable() {
public Object getAdapter(Class adapter) {
if (Shell.class.equals(adapter))
return shell;
return null;
}
};
if (client == null) {
// if there is no client, use a dummy
client = new IClient() {
public String getDescription() {
return Messages.clientDefaultDescription;
}
public String getId() {
return "org.eclipse.wst.server.ui.client.default";
}
public String getName() {
return Messages.clientDefaultName;
}
public IStatus launch(IServer server3, Object launchable2, String launchMode3, ILaunch launch) {
return Status.OK_STATUS;
}
public boolean supports(IServer server3, Object launchable2, String launchMode3) {
return true;
}
};
}
if (Trace.FINEST) {
Trace.trace(Trace.STRING_FINEST, "Ready to launch");
}
launch2.addProcess(new RunOnServerProcess(launch2));
// start server if it's not already started
// and cue the client to start
// TODO: get parent hierarchy correct
IModule[] modules = new IModule[] { module };
int state = server.getServerState();
if (state == IServer.STATE_STARTING) {
final LaunchClientJob clientJob = new LaunchClientJob(server, modules, launchMode, moduleArtifact, launchableAdapter, client);
final IServer server2 = server;
if (server2.shouldPublish()) {
server2.publish(IServer.PUBLISH_INCREMENTAL, null, info, new IServer.IOperationListener() {
public void done(IStatus result) {
if (result.isOK()) {
clientJob.schedule();
}
}
});
} else {
clientJob.schedule();
}
} else if (state == IServer.STATE_STARTED) {
boolean restart = false;
String mode = server.getMode();
IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
boolean disabledBreakpoints = false;
if (server.getServerRestartState()) {
// TODO - restart state might not be set until after publish
int result = RunOnServerActionDelegate.openRestartDialog(shell);
if (result == 0) {
launchMode = mode;
restart = true;
} else if (result == 9) {
// cancel
launch2.terminate();
return;
}
}
if (!restart) {
if (!ILaunchManager.RUN_MODE.equals(mode) && ILaunchManager.RUN_MODE.equals(launchMode)) {
boolean breakpointsOption = false;
if (breakpointManager.isEnabled() && ILaunchManager.DEBUG_MODE.equals(mode))
breakpointsOption = true;
int result = RunOnServerActionDelegate.openOptionsDialog(shell, Messages.wizRunOnServerTitle, Messages.dialogModeWarningRun, breakpointsOption);
if (result == 0)
restart = true;
else if (result == 1) {
breakpointManager.setEnabled(false);
disabledBreakpoints = true;
launchMode = mode;
} else if (result == 2)
launchMode = mode;
else {
// result == 9 // cancel
launch2.terminate();
return;
}
} else if (!ILaunchManager.DEBUG_MODE.equals(mode) && ILaunchManager.DEBUG_MODE.equals(launchMode)) {
int result = RunOnServerActionDelegate.openOptionsDialog(shell, Messages.wizDebugOnServerTitle, Messages.dialogModeWarningDebug, false);
if (result == 0)
restart = true;
else if (result == 1)
launchMode = mode;
else {
// result == 9 // cancel
launch2.terminate();
return;
}
} else if (!ILaunchManager.PROFILE_MODE.equals(mode) && ILaunchManager.PROFILE_MODE.equals(launchMode)) {
boolean breakpointsOption = false;
if (breakpointManager.isEnabled() && ILaunchManager.DEBUG_MODE.equals(mode))
breakpointsOption = true;
int result = RunOnServerActionDelegate.openOptionsDialog(shell, Messages.wizProfileOnServerTitle, Messages.dialogModeWarningProfile, breakpointsOption);
if (result == 0)
restart = true;
else if (result == 1) {
breakpointManager.setEnabled(false);
disabledBreakpoints = true;
launchMode = mode;
} else if (result == 2)
launchMode = mode;
else {
// result == 9 // cancel
launch2.terminate();
return;
}
}
if (ILaunchManager.DEBUG_MODE.equals(launchMode)) {
if (!breakpointManager.isEnabled() && !disabledBreakpoints) {
int result = RunOnServerActionDelegate.openBreakpointDialog(shell);
if (result == 0)
breakpointManager.setEnabled(true);
else if (result == 1) {
// ignore
} else {
// result == 2
launch2.terminate();
return;
}
}
}
}
final LaunchClientJob clientJob = new LaunchClientJob(server, modules, launchMode, moduleArtifact, launchableAdapter, client);
if (restart) {
final String launchMode2 = launchMode;
final IServer server2 = server;
// If the server requires publish before starting and before launching the client, publish
// before the restart (see bug# 288008)
final boolean startBeforePublish = ((ServerType) server2.getServerType()).startBeforePublish();
if (server2.shouldPublish() && !startBeforePublish) {
server2.publish(IServer.PUBLISH_INCREMENTAL, null, info, null);
}
server2.restart(launchMode2, new IServer.IOperationListener() {
public void done(IStatus result2) {
if (result2.isOK()) {
// publish after the restart
if (server2.shouldPublish() && startBeforePublish) {
server2.publish(IServer.PUBLISH_INCREMENTAL, null, info, new IServer.IOperationListener() {
public void done(IStatus result3) {
if (result3.isOK()) {
clientJob.schedule();
}
}
});
} else
clientJob.schedule();
}
}
});
} else {
// Only publish if the server requires publish before launching the client.
if (server.shouldPublish()) {
server.publish(IServer.PUBLISH_INCREMENTAL, null, info, new IServer.IOperationListener() {
public void done(IStatus result) {
if (result.isOK())
clientJob.schedule();
}
});
} else {
clientJob.schedule();
}
}
} else if (state != IServer.STATE_STOPPING) {
final LaunchClientJob clientJob = new LaunchClientJob(server, modules, launchMode, moduleArtifact, launchableAdapter, client);
server.start(launchMode, new IServer.IOperationListener() {
public void done(IStatus result) {
if (result.isOK())
clientJob.schedule();
}
});
}
launch2.terminate();
}
Aggregations