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