bug 1365831, error for creating new file with empty new PHP file template
[phpeclipse.git] / net.sourceforge.phpeclipse.launching / src / net / sourceforge / phpdt / internal / launching / PHPInterpreter.java
index 2e342b9..acbbf91 100644 (file)
@@ -1,60 +1,98 @@
 package net.sourceforge.phpdt.internal.launching;
 
 import java.io.File;
+import java.io.FileWriter;
 import java.io.IOException;
+import java.util.ArrayList;
 
-import org.eclipse.core.internal.resources.OS;
-import org.eclipse.core.runtime.IPath;
+import net.sourceforge.phpdt.internal.ui.phpdocexport.JavadocExportMessages;
+import net.sourceforge.phpdt.internal.ui.util.ExceptionHandler;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.IDebugEventSetListener;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.Launch;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.ui.IDebugUIConstants;
 
 public class PHPInterpreter {
-       //public final String endOfOptionsDelimeter = " -- ";
-
-       protected IPath installLocation;
-       protected String name;
-
-       public PHPInterpreter(String aName, IPath validInstallLocation) {
-               name = aName;
-               installLocation = validInstallLocation;
-       }
-
-       public IPath getInstallLocation() {
-               return installLocation;
-       }
-
-       public void setInstallLocation(IPath validInstallLocation) {
-               installLocation = validInstallLocation;
-       }
-       
-       public String getName() {
-               return name;
-       }
-       
-       public void setName(String newName) {
-               name = newName;
-       }
-       
-       public String getCommand() {
-               String directory = installLocation.toOSString() + File.separator;
-               if (new File(directory + "php.exe").isFile())
-                       return directory + "php.exe";
-
-               if (new File(directory, "php").isFile())
-                       return directory + "php";
-                       
-               return null;
-       }
-       
-       public Process exec(String arguments, File workingDirectory) throws IOException {
-               return Runtime.getRuntime().exec(this.getCommand() + " " +  arguments, null, workingDirectory);
-       }
-       
-       public boolean equals(Object other) {
-               if (other instanceof PHPInterpreter) {
-                       PHPInterpreter otherInterpreter = (PHPInterpreter) other;
-                       if (name.equals(otherInterpreter.getName()))
-                               return installLocation.equals(otherInterpreter.getInstallLocation());
-               }
-               
-               return false;
-       }
-}
+
+  protected File installLocation;
+
+  public PHPInterpreter(File interpreter) {
+    installLocation = interpreter;
+  }
+
+  public File getInstallLocation() {
+    return installLocation;
+  }
+
+  public void setInstallLocation(File interpreter) {
+    installLocation = interpreter;
+  }
+
+  public String getCommand() {
+    return installLocation.toString();
+  }
+
+//  private boolean executePHPProcess(String arguments, File workingDirectory, String[] env) {
+//    Process process = null;
+//    try {
+//      StringBuffer buf = new StringBuffer();
+//      buf.append(getCommand() + " " + arguments);
+//      process = Runtime.getRuntime().exec(buf.toString(), env, workingDirectory);
+//      if (process != null) {
+//        // construct a formatted command line for the process properties
+//
+//        //                   for (int i= 0; i < args.length; i++) {
+//        //                           buf.append(args[i]);
+//        //                           buf.append(' ');
+//        //                   }
+//
+//        ILaunchConfigurationWorkingCopy wc = null;
+//        try {
+//          ILaunchConfigurationType lcType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(
+//              PHPLaunchConfigurationAttribute.PHP_LAUNCH_CONFIGURATION_TYPE);
+//          String name = "PHP Launcher"; //$NON-NLS-1$
+//          wc = lcType.newInstance(null, name);
+//          wc.setAttribute(IDebugUIConstants.ATTR_FAVORITE_GROUPS, true);
+//
+//          ILaunch newLaunch = new Launch(wc, ILaunchManager.RUN_MODE, null);
+//          IProcess iprocess = DebugPlugin.newProcess(newLaunch, process, "PHP Process"); //$NON-NLS-1$
+//          iprocess.setAttribute(IProcess.ATTR_CMDLINE, buf.toString());
+//          iprocess.setAttribute(IProcess.ATTR_PROCESS_TYPE, PHPLaunchConfigurationAttribute.PHP_LAUNCH_PROCESS_TYPE);
+//
+//          DebugPlugin.getDefault().getLaunchManager().addLaunch(newLaunch);
+//
+//        } catch (CoreException e) {
+//        }
+//
+//        return true;
+//
+//      }
+//    } catch (IOException e) {
+//      return false;
+//    }
+//    return false;
+//
+//  }
+
+  public Process exec(String arguments, File workingDirectory, String[] env) throws IOException {
+    return Runtime.getRuntime().exec(getCommand() + " " + arguments, env, workingDirectory);
+    //    executePHPProcess(arguments, workingDirectory, env);
+  }
+
+  public boolean equals(Object other) {
+    if (other instanceof PHPInterpreter) {
+      PHPInterpreter otherInterpreter = (PHPInterpreter) other;
+      return installLocation.equals(otherInterpreter.getInstallLocation());
+    }
+    return false;
+  }
+}
\ No newline at end of file