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.useRemoteDebugger(),
32 configuration.getRemoteSourcePath(),
33 configuration.usePathTranslation(),
34 configuration.getPathMap(),
35 configuration.useRelaunchOnScriptTermination());
38 IProcess process = null;
39 PHPDebugTarget debugTarget = new PHPDebugTarget(launch, process);
40 newPHPDBGProxy.setDebugTarget(debugTarget);
41 newPHPDBGProxy.start();
42 if (configuration.useRemoteDebugger()) {
43 // listener for remote debuger is started
44 if (configuration.useDBGSessionInBrowser()) {
45 activateDBGSESSIDPreview(configuration, newPHPDBGProxy
49 setEnvironmentVariables(configuration, newPHPDBGProxy.getPort());
50 // env=configuration.getEnvironment();
51 process = super.run(configuration, launch);
52 debugTarget.setProcess(process);
54 launch.addDebugTarget(debugTarget);
60 * Open the browser in the UI thread with the current debugger URL
62 * @param configuration
65 protected static void activateDBGSESSIDPreview(
66 final InterpreterRunnerConfiguration configuration, final int port) {
67 Display.getDefault().asyncExec(new Runnable() {
69 String fileName = configuration.getFileName();
70 JavaProject jproject = configuration.getProject();
71 IProject project = jproject.getProject();
72 IFile file = project.getFile(fileName);
73 if (configuration.useDBGSessionInExternalBrowser()) {
74 BrowserUtil.showBrowserAsExternal(file,
75 "?DBGSESSID=1@clienthost:" + port);
77 BrowserUtil.showPreview(file, true,
78 "?DBGSESSID=1@clienthost:" + port);
84 protected void setEnvironmentVariables(
85 InterpreterRunnerConfiguration configuration, int listenPort) {
87 //String env[] = new String[18];
88 long id = Math.round(Math.random() * 100000);
90 DBGSessID = "DBGSESSID=" + id + "@clienthost:" + listenPort;
91 configuration.addEnvironmentValue("HTTP_COOKIE", DBGSessID, false);
93 * configuration.addEnvironmentValue("REDIRECT_URL",OSFilePath,true);
94 * configuration.addEnvironmentValue("REQUEST_URI",OSFilePath,true);
95 * configuration.addEnvironmentValue("PATH_INFO",OSFilePath,true);
96 * configuration.addEnvironmentValue("PATH_TRANSLATED",OSFilePath,true);
97 * configuration.addEnvironmentValue("SCRIPT_FILENAME",interpreter,true);
98 * configuration.addEnvironmentValue("SERVER_PROTOCOL","HTTP /
102 * env[0]= "HTTP_COOKIE=" + DBGSessID; env[1]= "REDIRECT_QUERY_STRING=";
103 * env[2]= "REDIRECT_STATUS=200"; env[3]= "REDIRECT_URL=" + OSFilePath;
104 * env[4]= "SERVER_SOFTWARE=DBG / 2.1"; env[5]= "SERVER_NAME=localhost";
105 * env[6]= "SERVER_ADDR=127.0.0.1"; env[7]= "SERVER_PORT=80"; env[8]=
106 * "REMOTE_ADDR=127.0.0.1"; env[9]= "SCRIPT_FILENAME=" + interpreter;
107 * env[10]= "GATEWAY_INTERFACE=CGI / 1.1"; env[11]=
108 * "SERVER_PROTOCOL=HTTP / 1.1"; env[12]= "REQUEST_METHOD=GET"; env[13]=
109 * "QUERY_STRING=test=1"; env[14]= "REQUEST_URI=" + OSFilePath; env[15]=
110 * "PATH_INFO=" + OSFilePath; env[16]= "PATH_TRANSLATED=" + OSFilePath;
111 * env[17]= "SystemRoot=" + Environment.getenv("SystemRoot");
116 protected String getDebugCommandLineArgument() {
120 protected String renderLoadPath(InterpreterRunnerConfiguration configuration) {
121 StringBuffer loadPath = new StringBuffer();
123 JavaProject project = configuration.getProject();
124 addToLoadPath(loadPath, project.getProject());
126 Iterator referencedProjects = project.getReferencedProjects()
128 while (referencedProjects.hasNext())
129 addToLoadPath(loadPath, (IProject) referencedProjects.next());
131 return loadPath.toString();