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 Christian Perkonig - remote Debug
12 **********************************************************************/
13 package net.sourceforge.phpdt.internal.launching;
15 import java.util.Iterator;
17 import org.eclipse.core.resources.IProject;
18 import org.eclipse.debug.core.ILaunch;
19 import org.eclipse.debug.core.model.IProcess;
20 import org.eclipse.core.runtime.IPath;
21 import org.eclipse.core.runtime.Path;
22 import net.sourceforge.phpdt.internal.debug.core.model.PHPDebugTarget;
23 import net.sourceforge.phpdt.internal.debug.core.Environment;
24 import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy;
25 import net.sourceforge.phpeclipse.resourcesview.PHPProject;
27 public class DebuggerRunner extends InterpreterRunner {
29 public IProcess run(InterpreterRunnerConfiguration configuration, ILaunch launch) {
32 PHPDBGProxy newPHPDBGProxy= new PHPDBGProxy(configuration.useRemoteDebugger(),
33 configuration.getRemoteSourcePath());
37 IProcess process =null;
38 PHPDebugTarget debugTarget = new PHPDebugTarget(launch, process);
39 newPHPDBGProxy.setDebugTarget(debugTarget);
40 newPHPDBGProxy.start();
41 if (configuration.useRemoteDebugger())
43 // listener for remote debuger is started
48 env= setEnvironmentVariables(newPHPDBGProxy.getPort(), configuration.getAbsoluteFileName(), configuration.getInterpreter().getCommand());
49 for(int i= 0; i < env.length; i++) {
50 pos= env[i].indexOf("=");
52 name= env[i].substring(0, pos);
53 value= env[i].substring(pos + 1);
58 Environment.setenv(name, value);
60 // now enviroment settings is made with Environment class
61 // because if new parameters are passed by array, doesn't inherit system vars
62 process = super.run(configuration, launch, null);
63 debugTarget.setProcess(process);
65 launch.addDebugTarget(debugTarget);
70 protected String[] setEnvironmentVariables(int listenPort, String AbsoluteFileName, String interpreter) {
71 IPath FilePath= new Path(AbsoluteFileName);
72 String OSFilePath= FilePath.toOSString();
74 String env[]= new String[18];
76 DBGSessID = "DBGSESSID=0753972710000018@clienthost:" + listenPort;
78 env[0]= "HTTP_COOKIE=" + DBGSessID;
79 env[1]= "REDIRECT_QUERY_STRING=";
80 env[2]= "REDIRECT_STATUS=200";
81 env[3]= "REDIRECT_URL=" + OSFilePath;
82 env[4]= "SERVER_SOFTWARE=DBG / 2.1";
83 env[5]= "SERVER_NAME=localhost";
84 env[6]= "SERVER_ADDR=127.0.0.1";
85 env[7]= "SERVER_PORT=80";
86 env[8]= "REMOTE_ADDR=127.0.0.1";
87 env[9]= "SCRIPT_FILENAME=" + interpreter;
88 env[10]= "GATEWAY_INTERFACE=CGI / 1.1";
89 env[11]= "SERVER_PROTOCOL=HTTP / 1.1";
90 env[12]= "REQUEST_METHOD=GET";
91 env[13]= "QUERY_STRING=";
92 env[14]= "REQUEST_URI=" + OSFilePath;
93 env[15]= "PATH_INFO=" + OSFilePath;
94 env[16]= "PATH_TRANSLATED=" + OSFilePath;
95 env[17]= "SystemRoot=" + Environment.getenv("SystemRoot");
100 protected String getDebugCommandLineArgument() {
104 protected String renderLoadPath(InterpreterRunnerConfiguration configuration) {
105 StringBuffer loadPath = new StringBuffer();
107 PHPProject project = configuration.getProject();
108 addToLoadPath(loadPath, project.getProject());
110 Iterator referencedProjects = project.getReferencedProjects().iterator();
111 while (referencedProjects.hasNext())
112 addToLoadPath(loadPath, (IProject) referencedProjects.next());
114 return loadPath.toString();