1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Applied patch for 186405. Fixed some problems with breakpoint actions.

This commit is contained in:
John Cortell 2007-05-14 15:53:36 +00:00
parent c875ab1d89
commit 97d6043d03
7 changed files with 416 additions and 287 deletions

View file

@ -14,7 +14,6 @@ import java.io.ByteArrayOutputStream;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.StringTokenizer;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@ -31,7 +30,11 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.model.IBreakpoint;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@ -96,20 +99,50 @@ public class BreakpointActionManager {
return false;
}
public void executeActions(IBreakpoint breakpoint, IAdaptable context) {
public void executeActions(final IBreakpoint breakpoint, final IAdaptable context) {
if (breakpoint != null) {
IMarker marker = breakpoint.getMarker();
String actionNames = marker.getAttribute(BREAKPOINT_ACTION_ATTRIBUTE, ""); //$NON-NLS-1$
StringTokenizer tok = new StringTokenizer(actionNames, ","); //$NON-NLS-1$
while (tok.hasMoreTokens()) {
String actionName = tok.nextToken();
final String[] actions = actionNames.split(",");
if (actions.length > 0){
Job job = new Job("Execute breakpoint actions") {
public IStatus run(final IProgressMonitor monitor) {
return doExecuteActions(breakpoint, context, actions, monitor);
}
};
job.schedule();
try {
// wait for actions to execute
job.join();
}catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}
private IStatus doExecuteActions(final IBreakpoint breakpoint, final IAdaptable context, String[] actions, IProgressMonitor monitor) {
try {
for (int i = 0; i < actions.length && !monitor.isCanceled(); i++) {
String actionName = actions[i];
IBreakpointAction action = findBreakpointAction(actionName);
if (action != null) {
action.execute(breakpoint, context);
monitor.setTaskName(action.getSummary());
IStatus status = action.execute(breakpoint, context, monitor);
if (status.getCode() != IStatus.OK) {
// do not log status if user canceled.
if (status.getCode() != IStatus.CANCEL)
CDebugCorePlugin.log(status);
return status;
}
}
monitor.worked(1);
}
} catch (Exception e) {
return new Status( IStatus.ERROR, CDebugCorePlugin.getUniqueIdentifier(), CDebugCorePlugin.INTERNAL_ERROR, "Internal Error", e );
}
return monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
}
public IBreakpointAction findBreakpointAction(String name) {

View file

@ -11,6 +11,8 @@
package org.eclipse.cdt.debug.core.breakpointactions;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.debug.core.model.IBreakpoint;
/**
@ -23,7 +25,7 @@ import org.eclipse.debug.core.model.IBreakpoint;
*/
public interface IBreakpointAction {
public void execute(IBreakpoint breakpoint, IAdaptable context);
public IStatus execute(IBreakpoint breakpoint, IAdaptable context, IProgressMonitor monitor);
public String getMemento();

View file

@ -22,9 +22,15 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.eclipse.cdt.debug.core.CDIDebugModel;
import org.eclipse.cdt.debug.core.breakpointactions.AbstractBreakpointAction;
import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchManager;
@ -39,18 +45,38 @@ public class ExternalToolAction extends AbstractBreakpointAction {
private String externalToolName = new String(""); //$NON-NLS-1$
public void execute(IBreakpoint breakpoint, IAdaptable context) {
public IStatus execute(IBreakpoint breakpoint, IAdaptable context, IProgressMonitor monitor) {
IStatus errorStatus = null;
ILaunchManager lcm = DebugPlugin.getDefault().getLaunchManager();
try {
boolean launched = false;
ILaunchConfiguration[] launchConfigurations = lcm.getLaunchConfigurations();
for (int i = 0; i < launchConfigurations.length; i++) {
if (launchConfigurations[i].getName().equals(externalToolName)) {
DebugUITools.launch(launchConfigurations[i], ILaunchManager.RUN_MODE);
launched = true;
break;
}
}
} catch (CoreException e) {
if (!launched) {
String errorMsg = MessageFormat.format(Messages.getString("ExternalToolAction.error.0"), new Object[] { externalToolName }); //$NON-NLS-1$
errorStatus = new Status( IStatus.ERROR, CDIDebugModel.getPluginIdentifier(), ICDebugInternalConstants.STATUS_CODE_ERROR, errorMsg, null);
}
} catch (CoreException e) {
errorStatus = e.getStatus();
} catch (Exception e) {
errorStatus = new Status( IStatus.ERROR, CDIDebugModel.getPluginIdentifier(), ICDebugInternalConstants.STATUS_CODE_ERROR, e.getMessage(), e );
}
if (errorStatus != null) {
String errorMsg = MessageFormat.format(Messages.getString("ExternalToolAction.error.1"), new Object[] { externalToolName }); //$NON-NLS-1$
MultiStatus ms = new MultiStatus( CDIDebugModel.getPluginIdentifier(), ICDebugInternalConstants.STATUS_CODE_ERROR, errorMsg, null );
ms.add(errorStatus);
return ms;
}
return Status.OK_STATUS;
}
public String getDefaultName() {

View file

@ -11,8 +11,8 @@
package org.eclipse.cdt.debug.ui.breakpointactions;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.StringReader;
import java.text.MessageFormat;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@ -22,9 +22,14 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.eclipse.cdt.debug.core.CDIDebugModel;
import org.eclipse.cdt.debug.core.breakpointactions.AbstractBreakpointAction;
import org.eclipse.cdt.debug.core.breakpointactions.ILogActionEnabler;
import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
@ -49,7 +54,12 @@ public class LogAction extends AbstractBreakpointAction {
this.evaluateExpression = evaluateExpression;
}
public void execute(IBreakpoint breakpoint, IAdaptable context) {
/*
* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.breakpointactions.IBreakpointAction#execute(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.runtime.IAdaptable, org.eclipse.core.runtime.IProgressMonitor)
*/
public IStatus execute(IBreakpoint breakpoint, IAdaptable context, IProgressMonitor monitor) {
IStatus result = Status.OK_STATUS;
try {
openConsole(Messages.getString("LogAction.ConsoleTitle")); //$NON-NLS-1$
String logMessage = getMessage();
@ -63,11 +73,11 @@ public class LogAction extends AbstractBreakpointAction {
MessageConsoleStream stream = console.newMessageStream();
stream.println(logMessage);
stream.close();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
String errorMsg = MessageFormat.format(Messages.getString("LogAction.error.0"), new Object[] {getSummary()}); //$NON-NLS-1$
result = new Status( IStatus.ERROR, CDIDebugModel.getPluginIdentifier(), ICDebugInternalConstants.STATUS_CODE_ERROR, errorMsg, e );
}
return result;
}
private void openConsole(String consoleName) {

View file

@ -22,9 +22,17 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.eclipse.cdt.debug.core.CDIDebugModel;
import org.eclipse.cdt.debug.core.breakpointactions.AbstractBreakpointAction;
import org.eclipse.cdt.debug.core.breakpointactions.IResumeActionEnabler;
import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants;
import org.eclipse.cdt.debug.internal.ui.IInternalCDebugUIConstants;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.model.IBreakpoint;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@ -33,16 +41,50 @@ import org.xml.sax.helpers.DefaultHandler;
public class ResumeAction extends AbstractBreakpointAction {
final int INCRIMENT_MSEC = 100;
int pauseTime = 0;
public void execute(IBreakpoint breakpoint, IAdaptable context) {
/*
* (non-Javadoc)
* @see org.eclipse.cdt.debug.core.breakpointactions.IBreakpointAction#execute(org.eclipse.debug.core.model.IBreakpoint, org.eclipse.core.runtime.IAdaptable, org.eclipse.core.runtime.IProgressMonitor)
*/
public IStatus execute(IBreakpoint breakpoint, IAdaptable context, IProgressMonitor monitor) {
IStatus errorStatus = null;
long endTime = System.currentTimeMillis() + getPauseTime()*1000;
IResumeActionEnabler enabler = (IResumeActionEnabler) context.getAdapter(IResumeActionEnabler.class);
if (enabler != null)
if (enabler != null) {
try {
enabler.resume();
} catch (Exception e) {
e.printStackTrace();
monitor.beginTask(getName(), getPauseTime()*1000/INCRIMENT_MSEC);
long currentTime = System.currentTimeMillis();
while (!monitor.isCanceled() && currentTime < endTime ){
monitor.setTaskName(MessageFormat.format(Messages.getString("ResumeAction.SummaryResumeTime"), new Object[] { new Long((endTime - currentTime)/1000) })); //$NON-NLS-1$)
monitor.worked(1);
Thread.sleep(INCRIMENT_MSEC);
currentTime = System.currentTimeMillis();
}
if (!monitor.isCanceled()) {
monitor.setTaskName( Messages.getString("ResumeAction.SummaryImmediately")); //$NON-NLS-1$)
enabler.resume();
}
monitor.worked(1);
} catch (Exception e) {
errorStatus = new Status( IStatus.ERROR, CDIDebugModel.getPluginIdentifier(), ICDebugInternalConstants.STATUS_CODE_ERROR, e.getMessage(), e );
}
} else
errorStatus = new Status( IStatus.ERROR, CDebugUIPlugin.getUniqueIdentifier(), IInternalCDebugUIConstants.INTERNAL_ERROR, Messages.getString("ResumeAction.error.0"), null ); //$NON-NLS-1$
if (errorStatus != null) {
MultiStatus ms = new MultiStatus( CDIDebugModel.getPluginIdentifier(), ICDebugInternalConstants.STATUS_CODE_ERROR, Messages.getString("ResumeAction.error.1"), null ); //$NON-NLS-1$
ms.add( errorStatus);
errorStatus = ms;
} else {
errorStatus = monitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS;
}
return errorStatus;
}
public String getDefaultName() {

View file

@ -14,6 +14,7 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.text.MessageFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
@ -30,8 +31,13 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.eclipse.cdt.debug.core.CDIDebugModel;
import org.eclipse.cdt.debug.core.breakpointactions.AbstractBreakpointAction;
import org.eclipse.cdt.debug.internal.core.ICDebugInternalConstants;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.model.IBreakpoint;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@ -78,10 +84,8 @@ public class SoundAction extends AbstractBreakpointAction {
}
}
;
if (soundFile.exists()) {
new SoundPlayer().start();
}
}
@ -91,8 +95,14 @@ public class SoundAction extends AbstractBreakpointAction {
public SoundAction() {
}
public void execute(IBreakpoint breakpoint, IAdaptable context) {
public IStatus execute(IBreakpoint breakpoint, IAdaptable context, IProgressMonitor monitor) {
if (soundFile == null || !soundFile.exists()) {
String errorMsg = MessageFormat.format(Messages.getString("SoundAction.error.0"), new Object[] {getSummary()}); //$NON-NLS-1$
return new Status( IStatus.ERROR, CDIDebugModel.getPluginIdentifier(), ICDebugInternalConstants.STATUS_CODE_ERROR, errorMsg, null);
}
playSoundFile(soundFile);
return Status.OK_STATUS;
}
public String getDefaultName() {

View file

@ -23,12 +23,14 @@ SoundActionComposite.5=Choose a sound file:
SoundActionComposite.6=Browse...
SoundActionComposite.7=Play Sound
SoundActionComposite.9=That sound file does not exist.
SoundAction.error.0=Missing sound file "{0}"
SoundAction.ActionTypeName=Sound Action
LogActionComposite.0=Message to log when the breakpoint is hit:
LogActionComposite.1=Evaluate as expression
LogAction.ConsoleTitle=Log Action Messages
LogAction.UntitledName=Untitled Log Action
LogAction.TypeName=Log Action
LogAction.error.0=Could not execute log action: "{0}".
ExternalToolActionComposite.ToolLabel=External Tool:
ExternalToolActionComposite.DialogTitle=External Tools
@ -36,6 +38,8 @@ ExternalToolActionComposite.DialogMessage=Choose an External Tool to run
ExternalToolActionComposite.ChooseButtonTitle=Choose...
ExternalToolActionComposite.ExternalToolsButtonTitle=External Tools...
ExternalToolAction.Summary=Run {0}
ExternalToolAction.error.0=There is no launch configuration named "{0}".
ExternalToolAction.error.1=Could not launch "{0}".
ExternalToolAction.TypeName=External Tool Action
ResumeAction.UntitledName=Untitled Resume Action
ResumeAction.SummaryImmediately=Resume immediately
@ -43,3 +47,5 @@ ResumeActionComposite.ResumeAfterLabel=Resume after
ResumeAction.SummaryResumeTime=Resume after {0} seconds
ResumeActionComposite.Seconds=seconds
ResumeAction.TypeName=Resume Action
ResumeAction.error.0=IResumeActionEnabler not registered in context.
ResumeAction.error.1=Could not resume.