Importing the XDebugProxy code in the HEAD. The repo was tagged with T_BEFORE_XDEBUGP...
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.core / src / net / sourceforge / phpeclipse / xdebug / php / launching / PHPLaunchConfigurationDelegate.java
index 6117961..d464f64 100644 (file)
@@ -18,6 +18,7 @@ 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;
@@ -50,9 +51,12 @@ public class PHPLaunchConfigurationDelegate extends LaunchConfigurationDelegate
                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()) {
@@ -77,12 +81,11 @@ public class PHPLaunchConfigurationDelegate extends LaunchConfigurationDelegate
                
                commandList.add(file.getLocation().toOSString());
 
-               // Get de Debugport form the Launchconfiguration or from the preferences
-               int debugPort  = configuration.getAttribute(IXDebugConstants.ATTR_PHP_DEBUGPORT,-1);
-               boolean useDefaultPort= configuration.getAttribute(IXDebugConstants.ATTR_PHP_DEFAULT_DEBUGPORT, true);
-               if (useDefaultPort)
-                       debugPort=XDebugCorePlugin.getDefault().getPreferenceStore().getInt(IXDebugPreferenceConstants.DEBUGPORT_PREFERENCE);
-               if (debugPort<1024)
+               // Get the Debugport  from the preferences
+               int debugPort=XDebugCorePlugin.getDefault().getPreferenceStore().getInt(IXDebugPreferenceConstants.DEBUGPORT_PREFERENCE);
+               
+               // check for default port
+               if (debugPort==0)
                        debugPort=IXDebugPreferenceConstants.DEFAULT_DEBUGPORT;
 
                String[] envp=DebugPlugin.getDefault().getLaunchManager().getEnvironment(configuration);
@@ -97,21 +100,30 @@ public class PHPLaunchConfigurationDelegate extends LaunchConfigurationDelegate
                                envp[idx++]=key+"="+value;
                        }
                }
+               String idekey=fileName+"-"+(int)(Math.random()*100000);
                if (mode.equals(ILaunchManager.DEBUG_MODE)) {
                        String[] env = new String[envp.length+1];
                        for(int i=0;i<envp.length;i++)
                                        env[i+1]=envp[i];
-                       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);
                }
+
        }
        
        /**