Changes for new environment-tab
authorcperkonig <cperkonig>
Mon, 19 Jul 2004 07:09:22 +0000 (07:09 +0000)
committercperkonig <cperkonig>
Mon, 19 Jul 2004 07:09:22 +0000 (07:09 +0000)
net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/DebuggerRunner.java
net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/InterpreterRunner.java
net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/InterpreterRunnerConfiguration.java
net.sourceforge.phpeclipse.launching/src/net/sourceforge/phpdt/internal/launching/PHPLaunchConfigurationDelegate.java

index 6003721..461bf7b 100644 (file)
@@ -15,13 +15,10 @@ package net.sourceforge.phpdt.internal.launching;
 import java.util.Iterator;
 
 import net.sourceforge.phpdt.internal.core.JavaProject;
-import net.sourceforge.phpdt.internal.debug.core.Environment;
 import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy;
 import net.sourceforge.phpdt.internal.debug.core.model.PHPDebugTarget;
 
 import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
 import org.eclipse.debug.core.ILaunch;
 import org.eclipse.debug.core.model.IProcess;
 //import net.sourceforge.phpeclipse.resourcesview.PHPProject;
@@ -46,22 +43,9 @@ public class DebuggerRunner extends InterpreterRunner {
                }
                else
                {
-               
-                       env= setEnvironmentVariables(newPHPDBGProxy.getPort(), configuration.getAbsoluteFileName(), configuration.getInterpreter().getCommand());
-                       for(int i= 0; i < env.length; i++) {
-                               pos= env[i].indexOf("=");
-                               if(pos > -1) {
-                                       name= env[i].substring(0, pos);
-                                       value= env[i].substring(pos + 1);
-                               } else {
-                                       name= env[i];
-                                       value= "";
-                               }
-                               Environment.setenv(name, value);
-                       }
-                       // now enviroment settings is made with Environment class
-                       // because if new parameters are passed by array, doesn't inherit system vars
-                        process = super.run(configuration, launch, null);
+                       setEnvironmentVariables(configuration,newPHPDBGProxy.getPort());
+//                     env=configuration.getEnvironment();
+                       process = super.run(configuration, launch);
                        debugTarget.setProcess(process);
                }       
                launch.addDebugTarget(debugTarget);
@@ -69,14 +53,22 @@ public class DebuggerRunner extends InterpreterRunner {
                return process;
        }
        
-       protected String[] setEnvironmentVariables(int listenPort, String AbsoluteFileName, String interpreter) {
-               IPath FilePath= new Path(AbsoluteFileName);
-               String OSFilePath= FilePath.toOSString();
+       protected void setEnvironmentVariables(InterpreterRunnerConfiguration configuration,int listenPort) {
                String DBGSessID;
                String env[]= new String[18];
+               long id = Math.round(Math.random()*100000);
+               
 
-               DBGSessID = "DBGSESSID=0753972710000018@clienthost:" + listenPort;
-
+               DBGSessID = "DBGSESSID="+id+"@clienthost:" + listenPort;
+               configuration.addEnvironmentValue("HTTP_COOKIE",DBGSessID,false);
+/*             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",interpreter,true);
+               configuration.addEnvironmentValue("SERVER_PROTOCOL","HTTP / 1.1",true);
+*/
+/*             
                env[0]= "HTTP_COOKIE=" + DBGSessID;
                env[1]= "REDIRECT_QUERY_STRING=";
                env[2]= "REDIRECT_STATUS=200";
@@ -90,13 +82,13 @@ public class DebuggerRunner extends InterpreterRunner {
                env[10]= "GATEWAY_INTERFACE=CGI / 1.1";
                env[11]= "SERVER_PROTOCOL=HTTP / 1.1";
                env[12]= "REQUEST_METHOD=GET";
-               env[13]= "QUERY_STRING=";
+               env[13]= "QUERY_STRING=test=1";
                env[14]= "REQUEST_URI=" + OSFilePath;
                env[15]= "PATH_INFO=" + OSFilePath;
                env[16]= "PATH_TRANSLATED=" + OSFilePath;
                env[17]= "SystemRoot=" + Environment.getenv("SystemRoot");
-
-               return env;
+*/
+       //      return env;
        }
 
        protected String getDebugCommandLineArgument() {
index cae1655..a3be7fa 100644 (file)
@@ -3,10 +3,13 @@ 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 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;
@@ -17,10 +20,12 @@ public class InterpreterRunner {
        public InterpreterRunner() {
        }
 
-       public IProcess run(InterpreterRunnerConfiguration configuration, ILaunch launch, String[] env) {               
+       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, env);
@@ -59,6 +64,33 @@ 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();
index 8d45c41..d33e69e 100644 (file)
@@ -1,6 +1,11 @@
 package net.sourceforge.phpdt.internal.launching;
 
 import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
 import net.sourceforge.phpdt.internal.core.JavaProject;
 
@@ -9,12 +14,16 @@ import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.internal.ui.launchConfigurations.EnvironmentVariable;
+
 
 public class InterpreterRunnerConfiguration {
        protected ILaunchConfiguration configuration;
+       private HashMap fEnvironment;
 
        public InterpreterRunnerConfiguration(ILaunchConfiguration aConfiguration) {
                configuration = aConfiguration;
+               fEnvironment= new HashMap();
        }
        
        public String getAbsoluteFileName() {
@@ -94,6 +103,47 @@ public class InterpreterRunnerConfiguration {
                return false;
        }
        
+       public void setEnvironment(String[] envp)
+       {
+               if (envp== null)
+                       return;
+               for (int i = 0; i<envp.length; i++ ) {
+                       addEnvironmentValue(envp[i],true);
+               }
+       }
+       
+       public void addEnvironmentValue(String env,boolean replace)
+       {
+               String value = env.substring(env.indexOf('=')+1);
+               String key = env.substring(0,env.indexOf('='));
+               addEnvironmentValue(key,value,replace);
+       }
+       
+       public void addEnvironmentValue(String key, String value,boolean replace)
+       {
+               if (!replace && fEnvironment.containsKey(key)) {
+                       EnvironmentVariable ev = (EnvironmentVariable) fEnvironment.get(key);
+                       ev.setValue(ev.getValue()+";"+value);
+                       fEnvironment.put(key,ev);
+               } else
+                       this.fEnvironment.put(key, new EnvironmentVariable(key, value));
+       }
+       
+       public String[] getEnvironment()
+       {
+
+               Iterator iter= fEnvironment.entrySet().iterator();
+               List strings= new ArrayList(fEnvironment.size());
+               while (iter.hasNext()) {
+                       Map.Entry entry = (Map.Entry) iter.next();
+                       StringBuffer buffer= new StringBuffer((String) entry.getKey());
+                       buffer.append('=').append(((EnvironmentVariable) entry.getValue()).getValue());
+                       strings.add(buffer.toString());
+               }
+               return (String[]) strings.toArray(new String[strings.size()]);
+
+       }       
+       
        public String getRemoteSourcePath() {
                
                IProject project = getProject().getProject();
index cfa568e..483229d 100644 (file)
@@ -18,6 +18,7 @@ import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
 import org.eclipse.debug.core.ILaunch;
 import org.eclipse.debug.core.ILaunchConfiguration;
 import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
@@ -38,11 +39,13 @@ public class PHPLaunchConfigurationDelegate extends LaunchConfigurationDelegate
        public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
                if (PHPRuntime.getDefault().getSelectedInterpreter() == null)
                        throw new CoreException(new Status(IStatus.ERROR, PHPLaunchingPlugin.PLUGIN_ID, IStatus.OK, "You must define an interpreter before running PHP.", null));
-
+               
+               InterpreterRunnerConfiguration conf=new InterpreterRunnerConfiguration(configuration);
+               conf.setEnvironment(DebugPlugin.getDefault().getLaunchManager().getEnvironment(configuration));
                if (mode.equals("debug")) {
-                       debuggerRunner.run(new InterpreterRunnerConfiguration(configuration), launch);
+                       debuggerRunner.run(conf, launch);
                } else {
-                       interpreterRunner.run(new InterpreterRunnerConfiguration(configuration), launch, null);
+                       interpreterRunner.run(conf, launch);
                }               
        }
 }