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