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