import java.io.File;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin;
import net.sourceforge.phpeclipse.xdebug.core.IXDebugPreferenceConstants;
import net.sourceforge.phpeclipse.xdebug.core.XDebugCorePlugin;
import net.sourceforge.phpeclipse.xdebug.php.model.XDebugTarget;
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
-public class PHPLaunchConfigurationDelegate extends LaunchConfigurationDelegate {
+public class PHPLaunchConfigurationDelegate extends LaunchConfigurationDelegate implements ILaunchConfigurationDelegate{
/**
* @see ILaunchConfigurationDelegate#launch(ILaunchConfiguration, String, ILaunch, IProgressMonitor)
String phpInterpreter = configuration.getAttribute(IXDebugConstants.ATTR_PHP_INTERPRETER, (String)null);
boolean useDefaultInterpreter= configuration.getAttribute(IXDebugConstants.ATTR_PHP_DEFAULT_INTERPRETER, true);
- if (useDefaultInterpreter)
+ if (useDefaultInterpreter) {
phpInterpreter=XDebugCorePlugin.getDefault().getPreferenceStore().getString(IXDebugPreferenceConstants.PHP_INTERPRETER_PREFERENCE);
-
+ if (phpInterpreter=="") {
+ phpInterpreter=ExternalToolsPlugin.getDefault().getPreferenceStore().getString(ExternalToolsPlugin.PHP_RUN_PREF);
+ }
+ }
File exe = new File(phpInterpreter);
+ // Just to get sure that the interpreter exists
if (!exe.exists()) {
abort(MessageFormat.format("Specified PHP executable {0} does not exist. Check value of PHP-Interpreter.", new String[]{phpInterpreter}), null);
}
commandList.add(phpInterpreter);
- // program name
+ // Project name
String projectName = configuration.getAttribute(IXDebugConstants.ATTR_PHP_PROJECT, (String)null);
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
-
+// Just to get sure that the project exists
if (project == null) {
- abort("PHP-Script unspecified.", null);
+ abort("Project does not exist.", null);
}
String fileName = configuration.getAttribute(IXDebugConstants.ATTR_PHP_FILE, (String)null);
-// String program = project.getFile(fileName);
IFile file = project.getFile(fileName);
-// IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(program));
+ // Just to get sure that the script exists
if (!file.exists()) {
abort(MessageFormat.format("PHP-Script {0} does not exist.", new String[] {file.getFullPath().toString()}), null);
}
- commandList.add(file.getLocation().toOSString());
-// Map nativeEnvVars = DebugPlugin.getDefault().getLaunchManager().getNativeEnvironment();
- // Environment variables
- String[] envp=DebugPlugin.getDefault().getLaunchManager().getEnvironment(configuration);
- // Map envVars=configuration.getAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, nativeEnvVars);
+ commandList.add(file.getFullPath().toOSString());
+
+ // Get the Debugport from the preferences
int debugPort=XDebugCorePlugin.getDefault().getPreferenceStore().getInt(IXDebugPreferenceConstants.DEBUGPORT_PREFERENCE);
- if (debugPort<1024)
+
+ // check for default port
+ if (debugPort==0)
debugPort=IXDebugPreferenceConstants.DEFAULT_DEBUGPORT;
-// if (mode.equals(ILaunchManager.DEBUG_MODE)) {
-// nativeEnvVars.put("XDEBUG_CONFIG", "idekey=xdebug_test remote_enable=1");
-// }
+
+ String[] envp=DebugPlugin.getDefault().getLaunchManager().getEnvironment(configuration);
+ // appends the environment to the native environment
+ if (envp==null) {
+ Map stringVars = DebugPlugin.getDefault().getLaunchManager().getNativeEnvironment();
+ int idx=0;
+ envp= new String[stringVars.size()];
+ for (Iterator i = stringVars.keySet().iterator(); i.hasNext();) {
+ String key = (String) i.next();
+ String value = (String) stringVars.get(key);
+ envp[idx++]=key+"="+value;
+ }
+ }
+ String idekey=fileName+"-"+(int)(Math.random()*100000);
if (mode.equals(ILaunchManager.DEBUG_MODE)) {
- String[] env;
- if (envp!=null) {
- env = new String[envp.length+1];
- for(int i=0;i<envp.length;i++)
+ String[] env = new String[envp.length+1];
+ for(int i=0;i<envp.length;i++)
env[i+1]=envp[i];
- } else
- env = new String[1];
- env[0]="XDEBUG_CONFIG=idekey=xdebug_test remote_enable=1";
+ env[0]="XDEBUG_CONFIG=idekey="+idekey+" remote_enable=1 remote_port="+debugPort;
envp=env;
}
-
+ System.out.println("ideKey= "+idekey);
String[] commandLine = (String[]) commandList.toArray(new String[commandList.size()]);
+
+ XDebugTarget target=null;
+ if (mode.equals(ILaunchManager.DEBUG_MODE)) {
+ target = new XDebugTarget(launch, null, idekey);
+ }
Process process = DebugPlugin.exec(commandLine, null,envp);
IProcess p = DebugPlugin.newProcess(launch, process, phpInterpreter);
+
if (mode.equals(ILaunchManager.DEBUG_MODE)) {
- IDebugTarget target = new XDebugTarget(launch, p, debugPort);
+ target.addProcess(p);
launch.addDebugTarget(target);
}
+
}
/**