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.resources.IResource;
 
  14 import org.eclipse.core.runtime.CoreException;
 
  15 import org.eclipse.core.runtime.IPath;
 
  16 import org.eclipse.core.runtime.Path;
 
  17 import org.eclipse.debug.core.ILaunchConfiguration;
 
  18 import org.eclipse.debug.internal.ui.launchConfigurations.EnvironmentVariable;
 
  20 public class InterpreterRunnerConfiguration {
 
  21         protected ILaunchConfiguration configuration;
 
  23         private HashMap fEnvironment;
 
  25         public InterpreterRunnerConfiguration(ILaunchConfiguration aConfiguration) {
 
  26                 configuration = aConfiguration;
 
  27                 fEnvironment = new HashMap();
 
  30         public String getAbsoluteFileName() {
 
  31                 IPath path = new Path(getFileName());
 
  32                 IProject project = getProject().getProject();
 
  34                 //return project.getLocation().toOSString() + "/" + getFileName();
 
  35                 IResource file = project.findMember(path);
 
  36                 return file.getLocation().toOSString();
 
  39         public String getFileName() {
 
  43                         fileName = configuration.getAttribute(
 
  44                                         PHPLaunchConfigurationAttribute.FILE_NAME,
 
  45                                         "No file specified in configuration");
 
  46                 } catch (CoreException e) {
 
  49                 return fileName.replace('\\', '/');
 
  52         public JavaProject getProject() {
 
  53                 String projectName = "";
 
  56                         projectName = configuration.getAttribute(
 
  57                                         PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
 
  58                 } catch (CoreException e) {
 
  59                         PHPLaunchingPlugin.log(e);
 
  62                 IProject project = PHPLaunchingPlugin.getWorkspace().getRoot()
 
  63                                 .getProject(projectName);
 
  65                 JavaProject phpProject = new JavaProject();
 
  66                 phpProject.setProject(project);
 
  70         public File getAbsoluteWorkingDirectory() {
 
  73                         file = configuration.getAttribute(
 
  74                                         PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
 
  75                 } catch (CoreException e) {
 
  76                         PHPLaunchingPlugin.log(e);
 
  78                 return new File(file);
 
  81         public String getInterpreterArguments() {
 
  83                         return configuration.getAttribute(
 
  84                                         PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS, "");
 
  85                 } catch (CoreException e) {
 
  91         public String getProgramArguments() {
 
  93                         return configuration.getAttribute(
 
  94                                         PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS, "");
 
  95                 } catch (CoreException e) {
 
 101         public PHPInterpreter getInterpreter() {
 
 102                 String selectedInterpreter = null;
 
 104                         selectedInterpreter = configuration.getAttribute(
 
 105                                         PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
 
 106                 } catch (CoreException e) {
 
 109                 return PHPRuntime.getDefault().getInterpreter(selectedInterpreter);
 
 112         public boolean useRemoteDebugger() {
 
 114                         return configuration.getAttribute(
 
 115                                         PHPLaunchConfigurationAttribute.REMOTE_DEBUG, false);
 
 116                 } catch (CoreException e) {
 
 117                         PHPLaunchingPlugin.log(e);
 
 122         public boolean usePathTranslation() {
 
 124                         return configuration.getAttribute(
 
 125                                         PHPLaunchConfigurationAttribute.REMOTE_DEBUG_TRANSLATE,
 
 127                 } catch (CoreException e) {
 
 128                         PHPLaunchingPlugin.log(e);
 
 133         public Map getPathMap() {
 
 135                         return configuration.getAttribute(
 
 136                                         PHPLaunchConfigurationAttribute.FILE_MAP, (Map) null);
 
 137                 } catch (CoreException e) {
 
 138                         PHPLaunchingPlugin.log(e);
 
 143         public boolean useDBGSessionInBrowser() {
 
 145                         return configuration.getAttribute(
 
 146                                         PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_BROWSER,
 
 148                 } catch (CoreException e) {
 
 149                         PHPLaunchingPlugin.log(e);
 
 154         public void setEnvironment(String[] envp) {
 
 157                 for (int i = 0; i < envp.length; i++) {
 
 158                         addEnvironmentValue(envp[i], true);
 
 162         public void addEnvironmentValue(String env, boolean replace) {
 
 163                 String value = env.substring(env.indexOf('=') + 1);
 
 164                 String key = env.substring(0, env.indexOf('='));
 
 165                 addEnvironmentValue(key, value, replace);
 
 168         public void addEnvironmentValue(String key, String value, boolean replace) {
 
 169                 if (!replace && fEnvironment.containsKey(key)) {
 
 170                         EnvironmentVariable ev = (EnvironmentVariable) fEnvironment
 
 172                         ev.setValue(ev.getValue() + ";" + value);
 
 173                         fEnvironment.put(key, ev);
 
 175                         this.fEnvironment.put(key, new EnvironmentVariable(key, value));
 
 178         public String[] getEnvironment() {
 
 180                 Iterator iter = fEnvironment.entrySet().iterator();
 
 181                 List strings = new ArrayList(fEnvironment.size());
 
 182                 while (iter.hasNext()) {
 
 183                         Map.Entry entry = (Map.Entry) iter.next();
 
 184                         StringBuffer buffer = new StringBuffer((String) entry.getKey());
 
 185                         buffer.append('=').append(
 
 186                                         ((EnvironmentVariable) entry.getValue()).getValue());
 
 187                         strings.add(buffer.toString());
 
 189                 return (String[]) strings.toArray(new String[strings.size()]);
 
 193         public String getRemoteSourcePath() {
 
 195                 IProject project = getProject().getProject();
 
 196                 if (!useRemoteDebugger())
 
 197                         return project.getLocation().toOSString();
 
 200                                 return configuration.getAttribute(
 
 201                                                 PHPLaunchConfigurationAttribute.REMOTE_PATH, "");
 
 202                         } catch (CoreException e) {
 
 203                                 PHPLaunchingPlugin.log(e);
 
 210         public boolean useDBGSessionInExternalBrowser() {
 
 214                                                         PHPLaunchConfigurationAttribute.OPEN_DBGSESSION_IN_EXTERNAL_BROWSER,
 
 216                 } catch (CoreException e) {
 
 217                         PHPLaunchingPlugin.log(e);