Merge xdebug from 1.3.x.
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / launching / PHPRemoteLaunchConfigurationDelegate.java
1 package net.sourceforge.phpeclipse.xdebug.php.launching;
2
3 import net.sourceforge.phpeclipse.xdebug.core.IProxyEventListener;
4 import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin;
5 import net.sourceforge.phpeclipse.xdebug.core.XDebugProxy;
6 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget;
7
8 import org.eclipse.core.resources.IProject;
9 import org.eclipse.core.resources.ResourcesPlugin;
10 import org.eclipse.core.runtime.CoreException;
11 import org.eclipse.core.runtime.IProgressMonitor;
12 import org.eclipse.core.runtime.IStatus;
13 import org.eclipse.core.runtime.Status;
14 import org.eclipse.debug.core.ILaunch;
15 import org.eclipse.debug.core.ILaunchConfiguration;
16 import org.eclipse.debug.core.ILaunchManager;
17 import org.eclipse.debug.core.model.IDebugTarget;
18 //import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
19 import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
20
21 public class PHPRemoteLaunchConfigurationDelegate extends LaunchConfigurationDelegate /*implements ILaunchConfigurationDelegate*/ {
22         public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
23                 String projectName = configuration.getAttribute(IXDebugConstants.ATTR_PHP_PROJECT, (String)null);
24                 IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
25 //               Just to get sure that the project exists
26                 if (project == null) {
27                         abort("Project does not exist.", null);
28                 }
29
30                 XDebugProxy proxy = XDebugCorePlugin.getDefault().getXDebugProxy();
31                 proxy.start();
32                 String ideID = configuration.getAttribute(IXDebugConstants.ATTR_PHP_IDE_ID, "testID");
33
34                 if (mode.equals(ILaunchManager.DEBUG_MODE)) {
35                         IDebugTarget target = new XDebugTarget(launch, null, ideID);
36                         proxy.addProxyEventListener((IProxyEventListener) target, ideID);
37                         launch.addDebugTarget(target);
38                 }
39         }
40         
41         /**
42          * Throws an exception with a new status containing the given
43          * message and optional exception.
44          * 
45          * @param message error message
46          * @param e underlying exception
47          * @throws CoreException
48          */
49         private void abort(String message, Throwable e) throws CoreException {
50                 throw new CoreException(new Status(IStatus.ERROR, IXDebugConstants.ID_PHP_DEBUG_MODEL, 0, message, e));
51         }
52 }