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;
20 public class InterpreterRunnerConfiguration {
21 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(PHPLaunchConfigurationAttribute.FILE_NAME, "No file specified in configuration");
41 } catch(CoreException e) {}
43 return fileName.replace('\\', '/');
46 public JavaProject getProject() {
47 String projectName = "";
50 projectName = configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
51 } catch(CoreException e) {
52 PHPLaunchingPlugin.log(e);
55 IProject project = PHPLaunchingPlugin.getWorkspace().getRoot().getProject(projectName);
57 JavaProject phpProject = new JavaProject();
58 phpProject.setProject(project);
62 public File getAbsoluteWorkingDirectory() {
65 file = configuration.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
66 } catch(CoreException e) {
67 PHPLaunchingPlugin.log(e);
69 return new File(file);
72 public String getInterpreterArguments() {
74 return configuration.getAttribute(PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS, "");
75 } catch(CoreException e) {}
80 public String getProgramArguments() {
82 return configuration.getAttribute(PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS, "");
83 } catch (CoreException e) {}
88 public PHPInterpreter getInterpreter() {
89 String selectedInterpreter = null;
91 selectedInterpreter = configuration.getAttribute(PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
92 } catch(CoreException e) {}
94 return PHPRuntime.getDefault().getInterpreter(selectedInterpreter);
97 public boolean useRemoteDebugger() {
99 return configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_DEBUG, false);
100 } catch(CoreException e) {
101 PHPLaunchingPlugin.log(e);
106 public boolean useDBGSessionInBrowser() {
108 return configuration.getAttribute(PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_BROWSER, true);
109 } catch(CoreException e) {
110 PHPLaunchingPlugin.log(e);
115 public void setEnvironment(String[] envp)
119 for (int i = 0; i<envp.length; i++ ) {
120 addEnvironmentValue(envp[i],true);
124 public void addEnvironmentValue(String env,boolean replace)
126 String value = env.substring(env.indexOf('=')+1);
127 String key = env.substring(0,env.indexOf('='));
128 addEnvironmentValue(key,value,replace);
131 public void addEnvironmentValue(String key, String value,boolean replace)
133 if (!replace && fEnvironment.containsKey(key)) {
134 EnvironmentVariable ev = (EnvironmentVariable) fEnvironment.get(key);
135 ev.setValue(ev.getValue()+";"+value);
136 fEnvironment.put(key,ev);
138 this.fEnvironment.put(key, new EnvironmentVariable(key, value));
141 public String[] getEnvironment()
144 Iterator iter= fEnvironment.entrySet().iterator();
145 List strings= new ArrayList(fEnvironment.size());
146 while (iter.hasNext()) {
147 Map.Entry entry = (Map.Entry) iter.next();
148 StringBuffer buffer= new StringBuffer((String) entry.getKey());
149 buffer.append('=').append(((EnvironmentVariable) entry.getValue()).getValue());
150 strings.add(buffer.toString());
152 return (String[]) strings.toArray(new String[strings.size()]);
156 public String getRemoteSourcePath() {
158 IProject project = getProject().getProject();
159 if (useRemoteDebugger())
160 return project.getLocation().toOSString();
164 return configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, "");
165 } catch(CoreException e) {
166 PHPLaunchingPlugin.log(e);