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
6 * Contributors: IBM Corporation - Initial implementation Vicente Fernando - www.alfersoft.com.ar Christian Perkonig - remote Debug
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.launching;
10 import java.util.Iterator;
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;
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;
23 // import net.sourceforge.phpeclipse.resourcesview.PHPProject;
25 public class DebuggerRunner extends InterpreterRunner {
27 public IProcess run(InterpreterRunnerConfiguration configuration,
31 PHPDBGProxy newPHPDBGProxy = new PHPDBGProxy(configuration
32 .useRemoteDebugger(), configuration.getRemoteSourcePath(),
33 configuration.usePathTranslation(), configuration.getPathMap());
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
47 setEnvironmentVariables(configuration, newPHPDBGProxy.getPort());
48 // env=configuration.getEnvironment();
49 process = super.run(configuration, launch);
50 debugTarget.setProcess(process);
52 launch.addDebugTarget(debugTarget);
58 * Open the browser in the UI thread with the current debugger URL
60 * @param configuration
63 protected static void activateDBGSESSIDPreview(
64 final InterpreterRunnerConfiguration configuration, final int port) {
65 Display.getDefault().asyncExec(new Runnable() {
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);
75 BrowserUtil.showPreview(file, true,
76 "?DBGSESSID=1@clienthost:" + port);
82 protected void setEnvironmentVariables(
83 InterpreterRunnerConfiguration configuration, int listenPort) {
85 String env[] = new String[18];
86 long id = Math.round(Math.random() * 100000);
88 DBGSessID = "DBGSESSID=" + id + "@clienthost:" + listenPort;
89 configuration.addEnvironmentValue("HTTP_COOKIE", DBGSessID, false);
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 /
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");
114 protected String getDebugCommandLineArgument() {
118 protected String renderLoadPath(InterpreterRunnerConfiguration configuration) {
119 StringBuffer loadPath = new StringBuffer();
121 JavaProject project = configuration.getProject();
122 addToLoadPath(loadPath, project.getProject());
124 Iterator referencedProjects = project.getReferencedProjects()
126 while (referencedProjects.hasNext())
127 addToLoadPath(loadPath, (IProject) referencedProjects.next());
129 return loadPath.toString();