Fix #1371992: Error with switch when last case block omits break or return
[phpeclipse.git] / net.sourceforge.phpeclipse.launching / src / net / sourceforge / phpdt / internal / launching / InterpreterRunner.java
index 5e76ed5..ee56530 100644 (file)
@@ -3,12 +3,18 @@ package net.sourceforge.phpdt.internal.launching;
 import java.io.File;
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.Map;
+
+import net.sourceforge.phpdt.internal.core.JavaProject;
 
-import net.sourceforge.phpeclipse.resourcesview.PHPProject;
-import org.eclipse.core.boot.BootLoader;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
 import org.eclipse.debug.core.DebugPlugin;
 import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.Launch;
 import org.eclipse.debug.core.model.IProcess;
 
 public class InterpreterRunner {
@@ -16,19 +22,23 @@ public class InterpreterRunner {
        public InterpreterRunner() {
        }
 
-       public IProcess run(InterpreterRunnerConfiguration configuration, ILaunch launch) {
-               String commandLine = renderCommandLine(configuration);
+       public IProcess run(InterpreterRunnerConfiguration configuration, ILaunch launch) {             
+               String commandLine = renderCommandLine(configuration);          
                File workingDirectory = configuration.getAbsoluteWorkingDirectory();
-
+               
+               setEnvironmentVariables(configuration);
+               String[] env = configuration.getEnvironment();
                Process nativePHPProcess = null;
                try {
-                       nativePHPProcess = configuration.getInterpreter().exec(commandLine, workingDirectory);
+                       nativePHPProcess = configuration.getInterpreter().exec(commandLine, workingDirectory, env);
                } catch (IOException e) {
                        throw new RuntimeException("Unable to execute interpreter: " + commandLine + workingDirectory);
                }
 
-               IProcess process = DebugPlugin.getDefault().newProcess(launch, nativePHPProcess, renderLabel(configuration));
+               IProcess process = DebugPlugin.newProcess(launch, nativePHPProcess, renderLabel(configuration));
                process.setAttribute(PHPLaunchingPlugin.PLUGIN_ID + ".launcher.cmdline", commandLine);
+        process.setAttribute(IProcess.ATTR_PROCESS_TYPE, PHPLaunchConfigurationAttribute.PHP_LAUNCH_PROCESS_TYPE);
+        
                return process ;
        }
 
@@ -57,27 +67,53 @@ public class InterpreterRunner {
 
                return buffer.toString();
        }
+       
+       protected void setEnvironmentVariables(InterpreterRunnerConfiguration configuration) {
+               IPath FilePath= new Path(configuration.getAbsoluteFileName());
+               String OSFilePath= FilePath.toOSString();
+               configuration.addEnvironmentValue("REDIRECT_URL",OSFilePath,true);
+               configuration.addEnvironmentValue("REQUEST_URI",OSFilePath,true);
+               configuration.addEnvironmentValue("PATH_INFO",OSFilePath,true);
+               configuration.addEnvironmentValue("PATH_TRANSLATED",OSFilePath,true);
+               configuration.addEnvironmentValue("SCRIPT_FILENAME",configuration.getInterpreter().getCommand(),true);
+               configuration.addEnvironmentValue("SERVER_PROTOCOL","HTTP / 1.1",true);
+
+               configuration.addEnvironmentValue("REDIRECT_QUERY_STRING","",true);
+               configuration.addEnvironmentValue("REDIRECT_STATUS","200",true);
+               configuration.addEnvironmentValue("SERVER_SOFTWARE","DBG / 2.1",true);
+               configuration.addEnvironmentValue("SERVER_NAME","localhost",true);
+               configuration.addEnvironmentValue("SERVER_ADDR","127.0.0.1",true);
+               configuration.addEnvironmentValue("SERVER_PORT","80",true);
+               configuration.addEnvironmentValue("REMOTE_ADDR","127.0.0.1",true);
+
+               configuration.addEnvironmentValue("GATEWAY_INTERFACE","CGI / 1.1",true);
+               configuration.addEnvironmentValue("REQUEST_METHOD","GET",true);
+               
+               Map stringVars = DebugPlugin.getDefault().getLaunchManager().getNativeEnvironment();
+               if (stringVars.containsKey("SYSTEMROOT"))
+                       configuration.addEnvironmentValue("SYSTEMROOT",(String) stringVars.get("SYSTEMROOT"),true);
+               
+       }
+
+       protected String renderLoadPath(InterpreterRunnerConfiguration configuration) {
+               StringBuffer loadPath = new StringBuffer();
+
+               JavaProject project = configuration.getProject();
+               addToLoadPath(loadPath, project.getProject());
+
+               Iterator referencedProjects = project.getReferencedProjects().iterator();
+               while (referencedProjects.hasNext())
+                       addToLoadPath(loadPath, (IProject) referencedProjects.next());
+
+               return loadPath.toString();
+       }
 
-//     protected String renderLoadPath(InterpreterRunnerConfiguration configuration) {
-//             StringBuffer loadPath = new StringBuffer();
-//
-//             PHPProject project = configuration.getProject();
-//             addToLoadPath(loadPath, project.getProject());
-//
-//             Iterator referencedProjects = project.getReferencedProjects().iterator();
-//             while (referencedProjects.hasNext())
-//                     addToLoadPath(loadPath, (IProject) referencedProjects.next());
-//
-//             return loadPath.toString();
-//     }
-
-//     protected void addToLoadPath(StringBuffer loadPath, IProject project) {
-//
-//             loadPath.append(" -I " + osDependentPath(project.getLocation().toOSString()));
-//     }
+       protected void addToLoadPath(StringBuffer loadPath, IProject project) {
+               loadPath.append(" -I " + osDependentPath(project.getLocation().toOSString()));
+       }
 
        protected String osDependentPath(String aPath) {
-               if (BootLoader.getOS().equals(BootLoader.OS_WIN32))
+               if (Platform.getOS().equals(Platform.OS_WIN32))
                        aPath = "\"" + aPath + "\"";
 
                return aPath;
@@ -85,6 +121,5 @@ public class InterpreterRunner {
        
        protected String getDebugCommandLineArgument() {
                return "" ;     
-       }
-       
+       }       
 }