Added mapped path field
[phpeclipse.git] / net.sourceforge.phpeclipse.launching / src / net / sourceforge / phpdt / internal / launching / DebuggerRunner.java
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
7
8 Contributors:
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;
14
15 import java.util.Iterator;
16
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;
26
27 public class DebuggerRunner extends InterpreterRunner {
28
29         public IProcess run(InterpreterRunnerConfiguration configuration, ILaunch launch) {
30                 String[] env;
31                 String name, value;
32                 PHPDBGProxy newPHPDBGProxy= new PHPDBGProxy(configuration.useRemoteDebugger(),
33                                                             configuration.getRemoteSourcePath());
34                 int pos;
35
36
37                 IProcess process =null;
38                 PHPDebugTarget debugTarget = new PHPDebugTarget(launch, process);
39                 newPHPDBGProxy.setDebugTarget(debugTarget);             
40                 newPHPDBGProxy.start();                         
41                 if (configuration.useRemoteDebugger())
42                 {
43                         // listener for remote debuger is started 
44                 }
45                 else
46                 {
47                 
48                         env= setEnvironmentVariables(newPHPDBGProxy.getPort(), configuration.getAbsoluteFileName(), configuration.getInterpreter().getCommand());
49                         for(int i= 0; i < env.length; i++) {
50                                 pos= env[i].indexOf("=");
51                                 if(pos > -1) {
52                                         name= env[i].substring(0, pos);
53                                         value= env[i].substring(pos + 1);
54                                 } else {
55                                         name= env[i];
56                                         value= "";
57                                 }
58                                 Environment.setenv(name, value);
59                         }
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);
64                 }       
65                 launch.addDebugTarget(debugTarget);
66
67                 return process;
68         }
69         
70         protected String[] setEnvironmentVariables(int listenPort, String AbsoluteFileName, String interpreter) {
71                 IPath FilePath= new Path(AbsoluteFileName);
72                 String OSFilePath= FilePath.toOSString();
73                 String DBGSessID;
74                 String env[]= new String[18];
75
76                 DBGSessID = "DBGSESSID=0753972710000018@clienthost:" + listenPort;
77
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");
96
97                 return env;
98         }
99
100         protected String getDebugCommandLineArgument() {
101                 return "";
102         }
103
104         protected String renderLoadPath(InterpreterRunnerConfiguration configuration) {
105                 StringBuffer loadPath = new StringBuffer();
106
107                 PHPProject project = configuration.getProject();
108                 addToLoadPath(loadPath, project.getProject());
109
110                 Iterator referencedProjects = project.getReferencedProjects().iterator();
111                 while (referencedProjects.hasNext())
112                         addToLoadPath(loadPath, (IProject) referencedProjects.next());
113
114                 return loadPath.toString();
115         }
116 }