8cec3f2d9875daf67840849fc96dbb68d4e2a7fb
[phpeclipse.git] /
1 package net.sourceforge.phpdt.internal.launching;
2
3 import java.io.File;
4
5 import net.sourceforge.phpeclipse.resourcesview.PHPProject;
6
7 import org.eclipse.core.resources.IProject;
8 import org.eclipse.core.runtime.CoreException;
9 import org.eclipse.core.runtime.IPath;
10 import org.eclipse.core.runtime.Path;
11 import org.eclipse.debug.core.ILaunchConfiguration;
12
13 public class InterpreterRunnerConfiguration {
14         protected ILaunchConfiguration configuration;
15
16         public InterpreterRunnerConfiguration(ILaunchConfiguration aConfiguration) {
17                 configuration = aConfiguration;
18         }
19         
20         public String getAbsoluteFileName() {
21                 IPath path = new Path(getFileName());
22                 IProject project = getProject().getProject();
23
24                 return project.getLocation().toOSString() + "/" + getFileName();
25         }
26         
27         public String getFileName() {
28                 String fileName = "";
29
30                 try {
31                         fileName = configuration.getAttribute(PHPLaunchConfigurationAttribute.FILE_NAME, "No file specified in configuration");
32                 } catch(CoreException e) {}
33                 
34                 return fileName.replace('\\', '/');
35         }
36         
37         public PHPProject getProject() {
38                 String projectName = "";
39                 
40                 try {
41                         projectName = configuration.getAttribute(PHPLaunchConfigurationAttribute.PROJECT_NAME, "");
42                 } catch(CoreException e) {
43                         PHPLaunchingPlugin.log(e);
44                 }
45
46                 IProject project = PHPLaunchingPlugin.getWorkspace().getRoot().getProject(projectName);
47
48                 PHPProject phpProject = new PHPProject();
49                 phpProject.setProject(project);
50                 return phpProject;
51         }
52         
53         public File getAbsoluteWorkingDirectory() {
54                 String file = null;
55                 try {
56                         file = configuration.getAttribute(PHPLaunchConfigurationAttribute.WORKING_DIRECTORY, "");
57                 } catch(CoreException e) {
58                         PHPLaunchingPlugin.log(e);
59                 }
60                 return new File(file);
61         }
62         
63         public String getInterpreterArguments() {
64                 try {
65                         return configuration.getAttribute(PHPLaunchConfigurationAttribute.INTERPRETER_ARGUMENTS, "");
66                 } catch(CoreException e) {}
67                 
68                 return "";
69         }
70         
71         public String getProgramArguments() {
72                 try {
73                         return configuration.getAttribute(PHPLaunchConfigurationAttribute.PROGRAM_ARGUMENTS, "");
74                 } catch (CoreException e) {}
75                 
76                 return "";
77         }
78
79         public PHPInterpreter getInterpreter() {
80                 String selectedInterpreter = null;
81                 try {
82                         selectedInterpreter = configuration.getAttribute(PHPLaunchConfigurationAttribute.SELECTED_INTERPRETER, "");
83                 } catch(CoreException e) {}
84
85                 return PHPRuntime.getDefault().getInterpreter(selectedInterpreter);
86         }
87         
88         public boolean useRemoteDebugger() {
89                 try {
90                         return configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_DEBUG, false);
91                 } catch(CoreException e) {
92                         PHPLaunchingPlugin.log(e);
93                 }
94                 return false;
95         }
96         
97         public String getRemoteSourcePath() {
98                 
99                 IProject project = getProject().getProject();
100                 if (useRemoteDebugger())
101                         return project.getLocation().toOSString();
102                 else
103                 {               
104                         try {
105                                 return configuration.getAttribute(PHPLaunchConfigurationAttribute.REMOTE_PATH, "");
106                         } catch(CoreException e) {
107                                 PHPLaunchingPlugin.log(e);
108                         }
109                 }       
110
111                 return "";
112         }
113
114 }