|
3 | 3 | import java.io.File; |
4 | 4 | import java.util.ArrayList; |
5 | 5 | import java.util.List; |
| 6 | + |
6 | 7 | import org.eclipse.core.resources.ResourcesPlugin; |
7 | 8 | import org.eclipse.core.runtime.CoreException; |
8 | 9 | import org.eclipse.core.runtime.IProgressMonitor; |
| 10 | +import org.eclipse.core.runtime.IStatus; |
| 11 | +import org.eclipse.core.runtime.Status; |
| 12 | +import org.eclipse.core.runtime.jobs.Job; |
9 | 13 | import org.eclipse.debug.core.DebugPlugin; |
10 | 14 | import org.eclipse.debug.core.ILaunch; |
11 | 15 | import org.eclipse.debug.core.ILaunchConfiguration; |
| 16 | +import org.eclipse.debug.core.ILaunchConfigurationType; |
| 17 | +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; |
12 | 18 | import org.eclipse.debug.core.ILaunchManager; |
13 | 19 | import org.eclipse.debug.core.model.ILaunchConfigurationDelegate; |
| 20 | +import org.eclipse.debug.ui.DebugUITools; |
| 21 | +import org.eclipse.swt.widgets.Display; |
14 | 22 | import org.nodeclipse.debug.util.Constants; |
15 | 23 | import org.nodeclipse.ui.Activator; |
16 | | - |
17 | 24 | import org.nodeclipse.ui.preferences.PreferenceConstants; |
18 | 25 |
|
19 | | -public class LaunchConfigurationDelegate implements ILaunchConfigurationDelegate { |
20 | | - |
21 | | - /* |
22 | | - * (non-Javadoc) |
23 | | - * |
24 | | - * @see |
25 | | - * org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org. |
26 | | - * eclipse.debug.core.ILaunchConfiguration, java.lang.String, |
27 | | - * org.eclipse.debug.core.ILaunch, |
28 | | - * org.eclipse.core.runtime.IProgressMonitor) |
29 | | - */ |
30 | | - @Override |
31 | | - public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException { |
32 | | - // Using configuration to build command line |
33 | | - List<String> cmdLine = new ArrayList<String>(); |
34 | | - // Application path should be stored in preference. |
35 | | - cmdLine.add(Activator.getDefault().getPreferenceStore().getString(PreferenceConstants.NODE_PATH)); |
36 | | - if (mode.equals(ILaunchManager.DEBUG_MODE)) { |
37 | | - cmdLine.add("--debug-brk=5858"); |
38 | | - } |
39 | | - String file = configuration.getAttribute(Constants.KEY_FILE_PATH, Constants.BLANK_STRING); |
40 | | - String filePath = ResourcesPlugin.getWorkspace().getRoot().findMember(file).getLocation().toOSString(); |
41 | | - // path is relative, so can not found it. |
42 | | - cmdLine.add(filePath); |
43 | | - String[] cmds = {}; |
44 | | - cmds = cmdLine.toArray(cmds); |
45 | | - // Launch a process to debug.eg, |
46 | | - Process p = DebugPlugin.exec(cmds, (new File(filePath)).getParentFile()); |
47 | | - DebugPlugin.newProcess(launch, p, Constants.PROCESS_MESSAGE); |
48 | | - // if (mode.equals(ILaunchManager.DEBUG_MODE)) { |
49 | | - // DebugTarget target = new DebugTarget(launch, process, p); |
50 | | - // launch.addDebugTarget(target); |
51 | | - // } |
| 26 | +public class LaunchConfigurationDelegate implements |
| 27 | + ILaunchConfigurationDelegate { |
52 | 28 |
|
53 | | - } |
| 29 | + /* |
| 30 | + * (non-Javadoc) |
| 31 | + * |
| 32 | + * @see |
| 33 | + * org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org. |
| 34 | + * eclipse.debug.core.ILaunchConfiguration, java.lang.String, |
| 35 | + * org.eclipse.debug.core.ILaunch, |
| 36 | + * org.eclipse.core.runtime.IProgressMonitor) |
| 37 | + */ |
| 38 | + @Override |
| 39 | + public void launch(ILaunchConfiguration configuration, String mode, |
| 40 | + ILaunch launch, IProgressMonitor monitor) throws CoreException { |
| 41 | + // Using configuration to build command line |
| 42 | + List<String> cmdLine = new ArrayList<String>(); |
| 43 | + // Application path should be stored in preference. |
| 44 | + cmdLine.add(Activator.getDefault().getPreferenceStore() |
| 45 | + .getString(PreferenceConstants.NODE_PATH)); |
| 46 | + if (mode.equals(ILaunchManager.DEBUG_MODE)) { |
| 47 | + cmdLine.add("--debug-brk=5858"); |
| 48 | + } |
| 49 | + String file = configuration.getAttribute(Constants.KEY_FILE_PATH, |
| 50 | + Constants.BLANK_STRING); |
| 51 | + String filePath = ResourcesPlugin.getWorkspace().getRoot() |
| 52 | + .findMember(file).getLocation().toOSString(); |
| 53 | + // path is relative, so can not found it. |
| 54 | + cmdLine.add(filePath); |
| 55 | + String[] cmds = {}; |
| 56 | + cmds = cmdLine.toArray(cmds); |
| 57 | + // Launch a process to debug.eg, |
| 58 | + Process p = DebugPlugin |
| 59 | + .exec(cmds, (new File(filePath)).getParentFile()); |
| 60 | + DebugPlugin.newProcess(launch, p, Constants.PROCESS_MESSAGE); |
| 61 | + // if (mode.equals(ILaunchManager.DEBUG_MODE)) { |
| 62 | + // DebugTarget target = new DebugTarget(launch, process, p); |
| 63 | + // launch.addDebugTarget(target); |
| 64 | + // } |
| 65 | + if (mode.equals(ILaunchManager.DEBUG_MODE)) { |
| 66 | + launchStandaloneV8(mode); |
| 67 | + } |
| 68 | + } |
54 | 69 |
|
| 70 | + private void launchStandaloneV8(final String mode) throws CoreException { |
| 71 | + ILaunchConfigurationType type = DebugPlugin |
| 72 | + .getDefault() |
| 73 | + .getLaunchManager() |
| 74 | + .getLaunchConfigurationType( |
| 75 | + Constants.STANDALONE_V8_LAUNCH_CONFIGURATION_TYPE_ID); |
| 76 | + if (type != null) { |
| 77 | + ILaunchConfigurationWorkingCopy workingCopy = type.newInstance( |
| 78 | + null, "STANDALNE_V8"); |
| 79 | + workingCopy.setAttribute("debug_host", "localhost"); |
| 80 | + workingCopy.setAttribute("debug_port", 5858); |
| 81 | + final ILaunchConfiguration config = workingCopy.doSave(); |
| 82 | + Display.getDefault().asyncExec(new Runnable() { |
| 83 | + @Override |
| 84 | + public void run() { |
| 85 | + DebugUITools.launch(config, mode); |
| 86 | + } |
| 87 | + }); |
| 88 | + } |
| 89 | + } |
55 | 90 | } |
0 commit comments