1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 IBM Corporation - Initial implementation
10 Vicente Fernando - www.alfersoft.com.ar
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.xdebug.php.launching;
15 import java.text.MessageFormat;
16 import java.util.ArrayList;
17 import java.util.List;
19 import net.sourceforge.phpeclipse.xdebug.core.IXDebugPreferenceConstants;
20 import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin;
21 import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget;
23 import org.eclipse.core.resources.IFile;
24 import org.eclipse.core.resources.IProject;
25 import org.eclipse.core.resources.ResourcesPlugin;
26 import org.eclipse.core.runtime.CoreException;
27 import org.eclipse.core.runtime.IProgressMonitor;
28 import org.eclipse.core.runtime.IStatus;
29 import org.eclipse.core.runtime.Status;
30 import org.eclipse.debug.core.DebugPlugin;
31 import org.eclipse.debug.core.ILaunch;
32 import org.eclipse.debug.core.ILaunchConfiguration;
33 import org.eclipse.debug.core.ILaunchManager;
34 import org.eclipse.debug.core.model.IDebugTarget;
35 import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
36 import org.eclipse.debug.core.model.IProcess;
37 import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
40 public class PHPLaunchConfigurationDelegate extends LaunchConfigurationDelegate {
43 * @see ILaunchConfigurationDelegate#launch(ILaunchConfiguration, String, ILaunch, IProgressMonitor)
45 public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
46 List commandList = new ArrayList();
48 String phpInterpreter = configuration.getAttribute(IXDebugConstants.ATTR_PHP_INTERPRETER, (String)null);
49 boolean useDefaultInterpreter= configuration.getAttribute(IXDebugConstants.ATTR_PHP_DEFAULT_INTERPRETER, true);
51 if (useDefaultInterpreter)
52 phpInterpreter=XDebugCorePlugin.getDefault().getPreferenceStore().getString(IXDebugPreferenceConstants.PHP_INTERPRETER_PREFERENCE);
54 File exe = new File(phpInterpreter);
56 abort(MessageFormat.format("Specified PHP executable {0} does not exist. Check value of PHP-Interpreter.", new String[]{phpInterpreter}), null);
58 commandList.add(phpInterpreter);
61 String projectName = configuration.getAttribute(IXDebugConstants.ATTR_PHP_PROJECT, (String)null);
62 IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
64 if (project == null) {
65 abort("PHP-Script unspecified.", null);
67 String fileName = configuration.getAttribute(IXDebugConstants.ATTR_PHP_FILE, (String)null);
69 // String program = project.getFile(fileName);
70 IFile file = project.getFile(fileName);
71 // IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(program));
73 abort(MessageFormat.format("PHP-Script {0} does not exist.", new String[] {file.getFullPath().toString()}), null);
76 commandList.add(file.getLocation().toOSString());
77 // Map nativeEnvVars = DebugPlugin.getDefault().getLaunchManager().getNativeEnvironment();
78 // Environment variables
79 String[] envp=DebugPlugin.getDefault().getLaunchManager().getEnvironment(configuration);
80 // Map envVars=configuration.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, nativeEnvVars);
81 int debugPort=XDebugCorePlugin.getDefault().getPreferenceStore().getInt(IXDebugPreferenceConstants.DEBUGPORT_PREFERENCE);
83 debugPort=IXDebugPreferenceConstants.DEFAULT_DEBUGPORT;
84 // if (mode.equals(ILaunchManager.DEBUG_MODE)) {
85 // nativeEnvVars.put("XDEBUG_CONFIG", "idekey=xdebug_test remote_enable=1");
87 if (mode.equals(ILaunchManager.DEBUG_MODE)) {
90 env = new String[envp.length+1];
91 for(int i=0;i<envp.length;i++)
95 env[0]="XDEBUG_CONFIG=idekey=xdebug_test remote_enable=1";
100 String[] commandLine = (String[]) commandList.toArray(new String[commandList.size()]);
101 Process process = DebugPlugin.exec(commandLine, null,envp);
102 IProcess p = DebugPlugin.newProcess(launch, process, phpInterpreter);
103 if (mode.equals(ILaunchManager.DEBUG_MODE)) {
104 IDebugTarget target = new XDebugTarget(launch, p, debugPort);
105 launch.addDebugTarget(target);
110 * Throws an exception with a new status containing the given
111 * message and optional exception.
113 * @param message error message
114 * @param e underlying exception
115 * @throws CoreException
117 private void abort(String message, Throwable e) throws CoreException {
118 // TODO: the plug-in code should be the example plug-in, not Perl debug model id
119 throw new CoreException(new Status(IStatus.ERROR, IXDebugConstants.ID_PHP_DEBUG_MODEL, 0, message, e));