Search in sources :

Example 11 with IBreakpointManager

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();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IAdaptable(org.eclipse.core.runtime.IAdaptable) LaunchClientJob(org.eclipse.wst.server.ui.internal.LaunchClientJob) IServer(org.eclipse.wst.server.core.IServer) IModule(org.eclipse.wst.server.core.IModule) IStatus(org.eclipse.core.runtime.IStatus) IClient(org.eclipse.wst.server.core.internal.IClient) ILaunchableAdapter(org.eclipse.wst.server.core.internal.ILaunchableAdapter) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) ModuleArtifactDelegate(org.eclipse.wst.server.core.model.ModuleArtifactDelegate) ILaunch(org.eclipse.debug.core.ILaunch) IBreakpointManager(org.eclipse.debug.core.IBreakpointManager)

Example 12 with IBreakpointManager

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;
}
Also used : IJavaStratumLineBreakpoint(org.eclipse.jdt.debug.core.IJavaStratumLineBreakpoint) IBreakpointManager(org.eclipse.debug.core.IBreakpointManager) IMarker(org.eclipse.core.resources.IMarker) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint)

Example 13 with IBreakpointManager

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;
}
Also used : ErlangLineBreakpoint(org.erlide.backend.debug.ErlangLineBreakpoint) IErlangBreakpoint(org.erlide.backend.debug.IErlangBreakpoint) IBreakpointManager(org.eclipse.debug.core.IBreakpointManager) IMarker(org.eclipse.core.resources.IMarker) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint)

Example 14 with IBreakpointManager

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;
}
Also used : ErlangLineBreakpoint(org.erlide.backend.debug.ErlangLineBreakpoint) ErlangDebugTarget(org.erlide.backend.debug.model.ErlangDebugTarget) CoreException(org.eclipse.core.runtime.CoreException) IBreakpointManager(org.eclipse.debug.core.IBreakpointManager) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) IErlangBreakpoint(org.erlide.backend.debug.IErlangBreakpoint) ErlangLineBreakpoint(org.erlide.backend.debug.ErlangLineBreakpoint) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

IBreakpointManager (org.eclipse.debug.core.IBreakpointManager)14 IBreakpoint (org.eclipse.debug.core.model.IBreakpoint)12 CoreException (org.eclipse.core.runtime.CoreException)7 IMarker (org.eclipse.core.resources.IMarker)4 ArrayList (java.util.ArrayList)3 BadLocationException (org.eclipse.jface.text.BadLocationException)3 ErlangLineBreakpoint (org.erlide.backend.debug.ErlangLineBreakpoint)3 IResource (org.eclipse.core.resources.IResource)2 IStatus (org.eclipse.core.runtime.IStatus)2 DebugException (org.eclipse.debug.core.DebugException)2 IErlangBreakpoint (org.erlide.backend.debug.IErlangBreakpoint)2 HashSet (java.util.HashSet)1 List (java.util.List)1 IProject (org.eclipse.core.resources.IProject)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 Status (org.eclipse.core.runtime.Status)1 DebugPlugin (org.eclipse.debug.core.DebugPlugin)1 ILaunch (org.eclipse.debug.core.ILaunch)1 ILineBreakpoint (org.eclipse.debug.core.model.ILineBreakpoint)1 IStackFrame (org.eclipse.debug.core.model.IStackFrame)1