1 package net.sourceforge.phpdt.internal.launching;
4 import java.util.ArrayList;
5 import java.util.HashMap;
6 import java.util.Iterator;
10 import net.sourceforge.phpdt.internal.core.JavaProject;
12 import org.eclipse.core.resources.IProject;
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IPath;
15 import org.eclipse.core.runtime.Path;
16 import org.eclipse.debug.core.ILaunchConfiguration;
17 import org.eclipse.debug.internal.ui.launchConfigurations.EnvironmentVariable;
19 public class InterpreterRunnerConfiguration {
20 protected ILaunchConfiguration configuration;
22 private HashMap fEnvironment;
24 public InterpreterRunnerConfiguration(ILaunchConfiguration aConfiguration) {
25 configuration = aConfiguration;
26 fEnvironment = new HashMap();
29 public String getAbsoluteFileName() {
30 IPath path = new Path(getFileName());
31 IProject project = getProject().getProject();
33 return project.getLocation().toOSString() + "/" + getFileName();
36 public String getFileName() {
40 fileName = configuration.getAttribute(
41 PHPLaunchConfigurationAttribute.FILE_NAME,
42 "No file specified in configuration");
43 } catch (CoreException e) {
46 return fileName.replace('\\', '/');
49 public JavaProject getProject() {
50 String projectName = "";
53 projectName = configuration.getAttribute(
54 PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
55 } catch (CoreException e) {
56 PHPLaunchingPlugin.log(e);
59 IProject project = PHPLaunchingPlugin.getWorkspace().getRoot()
60 .getProject(projectName);
62 JavaProject phpProject = new JavaProject();
63 phpProject.setProject(project);
67 public File getAbsoluteWorkingDirectory() {
70 file = configuration.getAttribute(
71 PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
72 } catch (CoreException e) {
73 PHPLaunchingPlugin.log(e);
75 return new File(file);
78 public String getInterpreterArguments() {
80 return configuration.getAttribute(
81 PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS, "");
82 } catch (CoreException e) {
88 public String getProgramArguments() {
90 return configuration.getAttribute(
91 PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS, "");
92 } catch (CoreException e) {
98 public PHPInterpreter getInterpreter() {
99 String selectedInterpreter = null;
101 selectedInterpreter = configuration.getAttribute(
102 PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
103 } catch (CoreException e) {
106 return PHPRuntime.getDefault().getInterpreter(selectedInterpreter);
109 public boolean useRemoteDebugger() {
111 return configuration.getAttribute(
112 PHPLaunchConfigurationAttribute.REMOTE_DEBUG, false);
113 } catch (CoreException e) {
114 PHPLaunchingPlugin.log(e);
119 public boolean usePathTranslation() {
121 return configuration.getAttribute(
122 PHPLaunchConfigurationAttribute.REMOTE_DEBUG_TRANSLATE,
124 } catch (CoreException e) {
125 PHPLaunchingPlugin.log(e);
130 public Map getPathMap() {
132 return configuration.getAttribute(
133 PHPLaunchConfigurationAttribute.FILE_MAP, (Map) null);
134 } catch (CoreException e) {
135 PHPLaunchingPlugin.log(e);
140 public boolean useDBGSessionInBrowser() {
142 return configuration.getAttribute(
143 PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_BROWSER,
145 } catch (CoreException e) {
146 PHPLaunchingPlugin.log(e);
151 public void setEnvironment(String[] envp) {
154 for (int i = 0; i < envp.length; i++) {
155 addEnvironmentValue(envp[i], true);
159 public void addEnvironmentValue(String env, boolean replace) {
160 String value = env.substring(env.indexOf('=') + 1);
161 String key = env.substring(0, env.indexOf('='));
162 addEnvironmentValue(key, value, replace);
165 public void addEnvironmentValue(String key, String value, boolean replace) {
166 if (!replace && fEnvironment.containsKey(key)) {
167 EnvironmentVariable ev = (EnvironmentVariable) fEnvironment
169 ev.setValue(ev.getValue() + ";" + value);
170 fEnvironment.put(key, ev);
172 this.fEnvironment.put(key, new EnvironmentVariable(key, value));
175 public String[] getEnvironment() {
177 Iterator iter = fEnvironment.entrySet().iterator();
178 List strings = new ArrayList(fEnvironment.size());
179 while (iter.hasNext()) {
180 Map.Entry entry = (Map.Entry) iter.next();
181 StringBuffer buffer = new StringBuffer((String) entry.getKey());
182 buffer.append('=').append(
183 ((EnvironmentVariable) entry.getValue()).getValue());
184 strings.add(buffer.toString());
186 return (String[]) strings.toArray(new String[strings.size()]);
190 public String getRemoteSourcePath() {
192 IProject project = getProject().getProject();
193 if (!useRemoteDebugger())
194 return project.getLocation().toOSString();
197 return configuration.getAttribute(
198 PHPLaunchConfigurationAttribute.REMOTE_PATH, "");
199 } catch (CoreException e) {
200 PHPLaunchingPlugin.log(e);