fix from durel_b:
[phpeclipse.git] / net.sourceforge.phpeclipse.launching / src / net / sourceforge / phpdt / internal / launching / PHPInterpreter.java
1 package net.sourceforge.phpdt.internal.launching;
2
3 import java.io.File;
4 import java.io.IOException;
5
6 import org.eclipse.core.runtime.IPath;
7
8 public class PHPInterpreter {
9         //public final String endOfOptionsDelimeter = " -- ";
10
11         protected IPath installLocation;
12         protected String name;
13
14         public PHPInterpreter(String aName, IPath validInstallLocation) {
15                 name = aName;
16                 installLocation = validInstallLocation;
17         }
18
19         public IPath getInstallLocation() {
20                 return installLocation;
21         }
22
23         public void setInstallLocation(IPath validInstallLocation) {
24                 installLocation = validInstallLocation;
25         }
26         
27         public String getName() {
28                 return name;
29         }
30         
31         public void setName(String newName) {
32                 name = newName;
33         }
34         
35         public String getCommand() {
36                 String directory = installLocation.toOSString() + File.separator;
37                 if (new File(directory + "php.exe").isFile())
38                         return directory + "php.exe";
39
40                 if (new File(directory, "php").isFile())
41                         return directory + "php";
42                         
43                 return null;
44         }
45         
46         public Process exec(String arguments, File workingDirectory, String[] env) throws IOException {
47                 return Runtime.getRuntime().exec(this.getCommand() + " " +  arguments, env, workingDirectory);
48         }
49         
50         public boolean equals(Object other) {
51                 if (other instanceof PHPInterpreter) {
52                         PHPInterpreter otherInterpreter = (PHPInterpreter) other;
53                         if (name.equals(otherInterpreter.getName()))
54                                 return installLocation.equals(otherInterpreter.getInstallLocation());
55                 }
56                 
57                 return false;
58         }
59 }