.
[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.FileWriter;
5 import java.io.IOException;
6 import java.util.ArrayList;
7
8 import net.sourceforge.phpdt.internal.ui.phpdocexport.JavadocExportMessages;
9 import net.sourceforge.phpdt.internal.ui.util.ExceptionHandler;
10
11 import org.eclipse.core.runtime.CoreException;
12 import org.eclipse.core.runtime.IStatus;
13 import org.eclipse.core.runtime.Status;
14 import org.eclipse.debug.core.DebugPlugin;
15 import org.eclipse.debug.core.IDebugEventSetListener;
16 import org.eclipse.debug.core.ILaunch;
17 import org.eclipse.debug.core.ILaunchConfigurationType;
18 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
19 import org.eclipse.debug.core.ILaunchManager;
20 import org.eclipse.debug.core.Launch;
21 import org.eclipse.debug.core.model.IProcess;
22 import org.eclipse.debug.ui.IDebugUIConstants;
23
24 public class PHPInterpreter {
25
26   protected File installLocation;
27
28   public PHPInterpreter(File interpreter) {
29     installLocation = interpreter;
30   }
31
32   public File getInstallLocation() {
33     return installLocation;
34   }
35
36   public void setInstallLocation(File interpreter) {
37     installLocation = interpreter;
38   }
39
40   public String getCommand() {
41     return installLocation.toString();
42   }
43
44 //  private boolean executePHPProcess(String arguments, File workingDirectory, String[] env) {
45 //    Process process = null;
46 //    try {
47 //      StringBuffer buf = new StringBuffer();
48 //      buf.append(getCommand() + " " + arguments);
49 //      process = Runtime.getRuntime().exec(buf.toString(), env, workingDirectory);
50 //      if (process != null) {
51 //        // construct a formatted command line for the process properties
52 //
53 //        //                    for (int i= 0; i < args.length; i++) {
54 //        //                            buf.append(args[i]);
55 //        //                            buf.append(' ');
56 //        //                    }
57 //
58 //        ILaunchConfigurationWorkingCopy wc = null;
59 //        try {
60 //          ILaunchConfigurationType lcType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(
61 //              PHPLaunchConfigurationAttribute.PHP_LAUNCH_CONFIGURATION_TYPE);
62 //          String name = "PHP Launcher"; //$NON-NLS-1$
63 //          wc = lcType.newInstance(null, name);
64 //          wc.setAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, true);
65 //
66 //          ILaunch newLaunch = new Launch(wc, ILaunchManager.RUN_MODE, null);
67 //          IProcess iprocess = DebugPlugin.newProcess(newLaunch, process, "PHP Process"); //$NON-NLS-1$
68 //          iprocess.setAttribute(IProcess.ATTR_CMDLINE, buf.toString());
69 //          iprocess.setAttribute(IProcess.ATTR_PROCESS_TYPE, PHPLaunchConfigurationAttribute.PHP_LAUNCH_PROCESS_TYPE);
70 //
71 //          DebugPlugin.getDefault().getLaunchManager().addLaunch(newLaunch);
72 //
73 //        } catch (CoreException e) {
74 //        }
75 //
76 //        return true;
77 //
78 //      }
79 //    } catch (IOException e) {
80 //      return false;
81 //    }
82 //    return false;
83 //
84 //  }
85
86   public Process exec(String arguments, File workingDirectory, String[] env) throws IOException {
87     return Runtime.getRuntime().exec(getCommand() + " " + arguments, env, workingDirectory);
88     //    executePHPProcess(arguments, workingDirectory, env);
89   }
90
91   public boolean equals(Object other) {
92     if (other instanceof PHPInterpreter) {
93       PHPInterpreter otherInterpreter = (PHPInterpreter) other;
94       return installLocation.equals(otherInterpreter.getInstallLocation());
95     }
96     return false;
97   }
98 }