01: package org.drools.eclipse.launching;
02:
03: import java.text.MessageFormat;
04:
05: import org.drools.eclipse.debug.core.IDroolsDebugConstants;
06: import org.eclipse.core.runtime.CoreException;
07: import org.eclipse.core.runtime.IProgressMonitor;
08: import org.eclipse.core.runtime.NullProgressMonitor;
09: import org.eclipse.debug.core.DebugPlugin;
10: import org.eclipse.debug.core.ILaunch;
11: import org.eclipse.debug.core.ILaunchConfiguration;
12: import org.eclipse.debug.core.ILaunchManager;
13: import org.eclipse.debug.core.model.IBreakpoint;
14: import org.eclipse.jdt.internal.launching.LaunchingMessages;
15: import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
16: import org.eclipse.jdt.launching.IVMInstall;
17: import org.eclipse.jdt.launching.IVMRunner;
18: import org.eclipse.jdt.launching.JavaLaunchDelegate;
19:
20: public class DroolsLaunchConfigurationDelegate extends
21: JavaLaunchDelegate {
22:
23: public void launch(ILaunchConfiguration configuration, String mode,
24: ILaunch launch, IProgressMonitor monitor)
25: throws CoreException {
26: if (monitor == null) {
27: monitor = new NullProgressMonitor();
28: }
29: if (monitor.isCanceled()) {
30: return;
31: }
32: // TODO make sure that all DRLs needed during execution are built and cached
33: super .launch(configuration, mode, launch, monitor);
34: if (mode.equals(ILaunchManager.DEBUG_MODE)) {
35: // TODO only retrieve breakpoints of this project or any
36: // of its dependent projects
37: IBreakpoint[] breakpoints = getDroolsBreakpoints();
38: for (int i = 0; i < breakpoints.length; i++) {
39: launch.getDebugTarget().breakpointAdded(breakpoints[i]);
40: }
41: }
42: }
43:
44: private IBreakpoint[] getDroolsBreakpoints() {
45: return DebugPlugin.getDefault().getBreakpointManager()
46: .getBreakpoints(
47: IDroolsDebugConstants.ID_DROOLS_DEBUG_MODEL);
48: }
49:
50: public IVMRunner getVMRunner(ILaunchConfiguration configuration,
51: String mode) throws CoreException {
52: IVMInstall vm = verifyVMInstall(configuration);
53: IVMRunner runner = new DroolsVMDebugger(vm);
54: if (runner == null) {
55: abort(
56: MessageFormat
57: .format(
58: LaunchingMessages.JavaLocalApplicationLaunchConfigurationDelegate_0,
59: new String[] { vm.getName(), mode }),
60: null,
61: IJavaLaunchConfigurationConstants.ERR_VM_RUNNER_DOES_NOT_EXIST);
62: }
63: return runner;
64: }
65:
66: }
|