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