Removing launching from plug-in list to remove build errors
[phpeclipse.git] / net.sourceforge.phpeclipse.launching / src / net / sourceforge / phpdt / internal / launching / DebuggerRunner.java
1 /***********************************************************************************************************************************
2  * Copyright (c) 2000, 2002 IBM Corp. and others. All rights reserved. This program and the accompanying materials are made
3  * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4  * http://www.eclipse.org/legal/cpl-v10.html
5  * 
6  * Contributors: IBM Corporation - Initial implementation Vicente Fernando - www.alfersoft.com.ar Christian Perkonig - remote Debug
7  **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.launching;
9
10 import java.util.Iterator;
11
12 import net.sourceforge.phpdt.internal.core.JavaProject;
13 import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy;
14 import net.sourceforge.phpdt.internal.debug.core.model.PHPDebugTarget;
15 import net.sourceforge.phpeclipse.ui.editor.BrowserUtil;
16
17 import org.eclipse.core.resources.IFile;
18 import org.eclipse.core.resources.IProject;
19 import org.eclipse.debug.core.ILaunch;
20 import org.eclipse.debug.core.model.IProcess;
21 import org.eclipse.swt.widgets.Display;
22
23 // import net.sourceforge.phpeclipse.resourcesview.PHPProject;
24
25 public class DebuggerRunner extends InterpreterRunner {
26
27         public IProcess run(InterpreterRunnerConfiguration configuration,
28                         ILaunch launch) {
29                 String[] env;
30                 String name, value;
31                 PHPDBGProxy newPHPDBGProxy = new PHPDBGProxy(configuration
32                                 .useRemoteDebugger(), configuration.getRemoteSourcePath(),
33                                 configuration.usePathTranslation(), configuration.getPathMap());
34                 int pos;
35
36                 IProcess process = null;
37                 PHPDebugTarget debugTarget = new PHPDebugTarget(launch, process);
38                 newPHPDBGProxy.setDebugTarget(debugTarget);
39                 newPHPDBGProxy.start();
40                 if (configuration.useRemoteDebugger()) {
41                         // listener for remote debuger is started
42                         if (configuration.useDBGSessionInBrowser()) {
43                                 activateDBGSESSIDPreview(configuration, newPHPDBGProxy
44                                                 .getPort());
45                         }
46                 } else {
47                         setEnvironmentVariables(configuration, newPHPDBGProxy.getPort());
48                         // env=configuration.getEnvironment();
49                         process = super.run(configuration, launch);
50                         debugTarget.setProcess(process);
51                 }
52                 launch.addDebugTarget(debugTarget);
53
54                 return process;
55         }
56
57         /**
58          * Open the browser in the UI thread with the current debugger URL
59          * 
60          * @param configuration
61          * @param port
62          */
63         protected static void activateDBGSESSIDPreview(
64                         final InterpreterRunnerConfiguration configuration, final int port) {
65                 Display.getDefault().asyncExec(new Runnable() {
66                         public void run() {
67                                 String fileName = configuration.getFileName();
68                                 JavaProject jproject = configuration.getProject();
69                                 IProject project = jproject.getProject();
70                                 IFile file = project.getFile(fileName);
71                                 if (configuration.useDBGSessionInExternalBrowser()) {
72                                         BrowserUtil.showBrowserAsExternal(file,
73                                                         "?DBGSESSID=1@clienthost:" + port);
74                                 } else {
75                                         BrowserUtil.showPreview(file, true,
76                                                         "?DBGSESSID=1@clienthost:" + port);
77                                 }
78                         }
79                 });
80         }
81
82         protected void setEnvironmentVariables(
83                         InterpreterRunnerConfiguration configuration, int listenPort) {
84                 String DBGSessID;
85                 String env[] = new String[18];
86                 long id = Math.round(Math.random() * 100000);
87
88                 DBGSessID = "DBGSESSID=" + id + "@clienthost:" + listenPort;
89                 configuration.addEnvironmentValue("HTTP_COOKIE", DBGSessID, false);
90                 /*
91                  * configuration.addEnvironmentValue("REDIRECT_URL",OSFilePath,true);
92                  * configuration.addEnvironmentValue("REQUEST_URI",OSFilePath,true);
93                  * configuration.addEnvironmentValue("PATH_INFO",OSFilePath,true);
94                  * configuration.addEnvironmentValue("PATH_TRANSLATED",OSFilePath,true);
95                  * configuration.addEnvironmentValue("SCRIPT_FILENAME",interpreter,true);
96                  * configuration.addEnvironmentValue("SERVER_PROTOCOL","HTTP /
97                  * 1.1",true);
98                  */
99                 /*
100                  * env[0]= "HTTP_COOKIE=" + DBGSessID; env[1]= "REDIRECT_QUERY_STRING=";
101                  * env[2]= "REDIRECT_STATUS=200"; env[3]= "REDIRECT_URL=" + OSFilePath;
102                  * env[4]= "SERVER_SOFTWARE=DBG / 2.1"; env[5]= "SERVER_NAME=localhost";
103                  * env[6]= "SERVER_ADDR=127.0.0.1"; env[7]= "SERVER_PORT=80"; env[8]=
104                  * "REMOTE_ADDR=127.0.0.1"; env[9]= "SCRIPT_FILENAME=" + interpreter;
105                  * env[10]= "GATEWAY_INTERFACE=CGI / 1.1"; env[11]=
106                  * "SERVER_PROTOCOL=HTTP / 1.1"; env[12]= "REQUEST_METHOD=GET"; env[13]=
107                  * "QUERY_STRING=test=1"; env[14]= "REQUEST_URI=" + OSFilePath; env[15]=
108                  * "PATH_INFO=" + OSFilePath; env[16]= "PATH_TRANSLATED=" + OSFilePath;
109                  * env[17]= "SystemRoot=" + Environment.getenv("SystemRoot");
110                  */
111                 // return env;
112         }
113
114         protected String getDebugCommandLineArgument() {
115                 return "";
116         }
117
118         protected String renderLoadPath(InterpreterRunnerConfiguration configuration) {
119                 StringBuffer loadPath = new StringBuffer();
120
121                 JavaProject project = configuration.getProject();
122                 addToLoadPath(loadPath, project.getProject());
123
124                 Iterator referencedProjects = project.getReferencedProjects()
125                                 .iterator();
126                 while (referencedProjects.hasNext())
127                         addToLoadPath(loadPath, (IProject) referencedProjects.next());
128
129                 return loadPath.toString();
130         }
131 }