use of org.eclipse.debug.core.IBreakpointManager 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();
}
use of org.eclipse.debug.core.IBreakpointManager in project xtext-eclipse by eclipse.
the class StratumBreakpointAdapterFactory method findExistingBreakpoint.
protected IJavaStratumLineBreakpoint findExistingBreakpoint(IResource res, SourceRelativeURI uri, int line) throws CoreException {
IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
IBreakpoint[] breakpoints = manager.getBreakpoints();
if (uri == null) {
for (IBreakpoint breakpoint : breakpoints) {
IMarker marker = breakpoint.getMarker();
if (breakpoint instanceof IJavaStratumLineBreakpoint && marker.getResource().equals(res)) {
final IJavaStratumLineBreakpoint stratumBreakpoint = (IJavaStratumLineBreakpoint) breakpoint;
if (stratumBreakpoint.getLineNumber() == line) {
return stratumBreakpoint;
}
}
}
} else {
String uriString = uri.toString();
for (IBreakpoint breakpoint : breakpoints) {
IMarker marker = breakpoint.getMarker();
if (breakpoint instanceof IJavaStratumLineBreakpoint && marker.getResource().equals(res) && uriString.equals(marker.getAttribute(JarFileMarkerAnnotationModel.MARKER_URI))) {
final IJavaStratumLineBreakpoint stratumBreakpoint = (IJavaStratumLineBreakpoint) breakpoint;
if (stratumBreakpoint.getLineNumber() == line) {
return stratumBreakpoint;
}
}
}
}
return null;
}
use of org.eclipse.debug.core.IBreakpointManager in project erlide_eclipse by erlang.
the class BreakpointMarkerUpdater method lineBreakpointExists.
/**
* Searches for an existing line breakpoint on the specified line in the current type
* that does not match the id of the specified marker
*
* @param resource
* the resource to care about
* @param typeName
* the name of the type the breakpoint is in
* @param lineNumber
* the number of the line the breakpoint is on
* @param currentmarker
* the current marker we are comparing to see if it will be moved onto an
* existing one
* @return an existing line breakpoint on the current line of the given resource and
* type if there is one
* @throws CoreException
*
* @since 3.4
*/
private IErlangBreakpoint lineBreakpointExists(final IResource resource, final int lineNumber, final IMarker currentmarker) throws CoreException {
final IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
final IBreakpoint[] breakpoints = manager.getBreakpoints(ErlDebugConstants.ID_ERLANG_DEBUG_MODEL);
final String markerType = currentmarker.getType();
for (final IBreakpoint breakpoint1 : breakpoints) {
if (!(breakpoint1 instanceof IErlangBreakpoint)) {
continue;
}
final IErlangBreakpoint breakpoint = (IErlangBreakpoint) breakpoint1;
final IMarker marker = breakpoint.getMarker();
if (marker != null && marker.exists() && marker.getType().equals(markerType) && currentmarker.getId() != marker.getId()) {
if (marker instanceof ErlangLineBreakpoint) {
final ErlangLineBreakpoint erlangLineBreakpoint = (ErlangLineBreakpoint) marker;
if (erlangLineBreakpoint.getLineNumber() == lineNumber) {
return erlangLineBreakpoint;
}
}
}
}
return null;
}
use of org.eclipse.debug.core.IBreakpointManager in project erlide_eclipse by erlang.
the class BreakpointMarkerUpdater method updateMarker.
@Override
public boolean updateMarker(final IMarker marker, final IDocument document, final Position position) {
if (position.isDeleted()) {
return false;
}
try {
final int line = MarkerUtilities.getLineNumber(marker);
final int newLine = document.getLineOfOffset(position.getOffset()) + 1;
if (line == newLine) {
return true;
}
final IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager();
final IBreakpoint breakpoint = manager.getBreakpoint(marker);
if (breakpoint == null) {
return false;
}
if (breakpoint instanceof ErlangLineBreakpoint) {
final ErlangLineBreakpoint erlangLineBreakpoint = (ErlangLineBreakpoint) breakpoint;
final ErlangDebugTarget target = erlangLineBreakpoint.getTarget();
erlangLineBreakpoint.remove(target);
MarkerUtilities.setLineNumber(marker, newLine);
erlangLineBreakpoint.install(target);
return true;
}
// if there exists a breakpoint on the line remove this one
if (BreakpointMarkerUpdater.isLineBreakpointMarker(marker)) {
ensureRanges(document, marker, line);
return lineBreakpointExists(marker.getResource(), line, marker) == null;
}
// a line breakpoint must be removed
if (BreakpointMarkerUpdater.isLineBreakpointMarker(marker) && line == -1) {
return false;
}
MarkerUtilities.setLineNumber(marker, line);
if (BreakpointMarkerUpdater.isLineBreakpointMarker(marker)) {
ensureRanges(document, marker, line);
}
return true;
} catch (final BadLocationException e) {
ErlLogger.error(e);
} catch (final CoreException e) {
ErlLogger.error(e);
}
return false;
}
Aggregations