updating SQL plugin with latest Quantum code
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / actions / PHPStartApacheAction.java
index 69b0b2d..5883fbe 100644 (file)
@@ -6,8 +6,8 @@ which accompanies this distribution, and is available at
 http://www.eclipse.org/legal/cpl-v10.html
 
 Contributors:
-    IBM Corporation - Initial implementation
-    Klaus Hartlage - www.eclipseproject.de
+               IBM Corporation - Initial implementation
+               Klaus Hartlage - www.eclipseproject.de
 **********************************************************************/
 package net.sourceforge.phpeclipse.actions;
 
@@ -15,6 +15,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.text.MessageFormat;
 
+import net.sourceforge.phpdt.externaltools.launchConfigurations.ExternalToolsUtil;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.views.PHPConsole;
 
@@ -34,73 +35,96 @@ public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
     documentRoot = documentRoot.replace('\\', '/');
     String[] arguments = { documentRoot };
     MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.APACHE_START_PREF));
-    execute(form.format(arguments), "Start Apache: ");
+    execute(
+      "apache_start",
+      store.getString(PHPeclipsePlugin.APACHE_RUN_PREF),
+      form.format(arguments),
+      store.getBoolean(PHPeclipsePlugin.APACHE_START_BACKGROUND));
   }
 
-//  public static void execute(String command, String consoleMessage) {
-//    //               MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
-//    try {
-//      PHPConsole console = PHPConsole.getInstance();
-//      console.write(consoleMessage + command + "\n");
-//      Runtime runtime = Runtime.getRuntime(); 
-//
-//      // runs the command
-//      Process p = runtime.exec(command);
-//
-//      if (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) {
-//
-//          OutputThread out = new OutputThread(p.getInputStream(), console);
-//          OutputThread err = new OutputThread(p.getErrorStream(), console);
-//          out.start();
-//          err.start();
-//        
-//      }
-//
-//    } catch (IOException e) {
-//
-//      System.err.println("Problem");
-//      e.printStackTrace();
-//
-//    }
-//
-//  }
-
-  public static String execute(String command, String consoleMessage) {
-    //    MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
-    try {
-      PHPConsole console = PHPConsole.getInstance();
-      console.write(consoleMessage + command + "\n");
-      Runtime runtime = Runtime.getRuntime();
-
-      // runs the command
-      Process p = runtime.exec(command);
-
-      // gets the input stream to have the post-compile-time information
-      InputStream stream = p.getInputStream();
-
-      // get the string from Stream
-      String consoleOutput = PHPConsole.getStringFromStream(stream);
-
-      // prints out the information
-      console.write(consoleOutput);
-      return consoleOutput;
-
-    } catch (IOException e) {
-
-      System.err.println("Problem");
-      e.printStackTrace();
-
+  //   public static void execute(String command, String consoleMessage) {
+  //           //              MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
+  //           try {
+  //                   PHPConsole console = PHPConsole.getInstance();
+  //                   console.write(consoleMessage + command + "\n");
+  //                   Runtime runtime = Runtime.getRuntime(); 
+  //
+  //                   // runs the command
+  //                   Process p = runtime.exec(command);
+  //
+  //                   if (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) {
+  //
+  //                                   OutputThread out = new OutputThread(p.getInputStream(), console);
+  //                                   OutputThread err = new OutputThread(p.getErrorStream(), console);
+  //                                   out.start();
+  //                                   err.start();
+  //        
+  //                   }
+  //
+  //           } catch (IOException e) {
+  //
+  //                   System.err.println("Problem");
+  //                   e.printStackTrace();
+  //
+  //           }
+  //
+  //   }
+
+  /**
+        * Executes an external progam and saves the LaunchConfiguration under external tools 
+        * @param command external tools command name
+        * @param executable executable path i.e.c:\apache\apache.exe
+        * @param arguments arguments for this configuration
+        * @param background run this configuration in background mode
+        */
+  public static void execute(String command, String executable, String arguments, boolean background) {
+    PHPConsole console = PHPConsole.getInstance();
+    String consoleMessage;
+    if (background) {
+      consoleMessage = "run in background mode-" + command + ": " + executable + " " + arguments;
+    } else {
+      consoleMessage = "run in foreground mode-" + command + ": " + executable + " " + arguments;
     }
-    return "";
+    console.write(consoleMessage + "\n");
+
+    ExternalToolsUtil.execute(command, executable, arguments, background);
+    //    MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
+    //         try {
+    //                 PHPConsole console = PHPConsole.getInstance();
+    //                 console.write(consoleMessage + command + "\n");
+    //                 
+    //                 ExternalToolsUtil.execute()
+    //                 Runtime runtime = Runtime.getRuntime();
+    //
+    //                 // runs the command
+    //                 Process p = runtime.exec(command);
+    //
+    //                 // gets the input stream to have the post-compile-time information
+    //                 InputStream stream = p.getInputStream();
+    //
+    //                 // get the string from Stream
+    //                 String consoleOutput = PHPConsole.getStringFromStream(stream);
+    //
+    //                 // prints out the information
+    //                 console.write(consoleOutput);
+    //                 return consoleOutput;
+    //
+    //         } catch (IOException e) {
+    //
+    //                 System.err.println("Problem");
+    //                 e.printStackTrace();
+    //
+    //         }
+    //         return "";
   }
   public static String getParserOutput(String command, String consoleMessage) {
     //    MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
     try {
       PHPConsole console = PHPConsole.getInstance();
-      if (console!=null) {
+      if (console != null) {
         console.write(consoleMessage + command + "\n");
       }
-      
+
       Runtime runtime = Runtime.getRuntime();
 
       // runs the command
@@ -113,9 +137,9 @@ public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
       String consoleOutput = PHPConsole.getStringFromStream(stream);
 
       // prints out the information
-         if (console!=null) {
+      if (console != null) {
         console.write(consoleOutput);
-         }
+      }
       return consoleOutput;
 
     } catch (IOException e) {
@@ -139,34 +163,34 @@ public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
 
   }
 
-//  static class OutputThread extends Thread {
-//    InputStream fInputStream;
-//    PHPConsole console;
-//
-//    OutputThread(InputStream inputStream, PHPConsole console) {
-//      this.fInputStream = inputStream;
-//      this.console = console;
-//    }
-//
-//    public void run() {
-//      try {
-//        BufferedReader bin = new BufferedReader(new InputStreamReader(fInputStream));
-//
-//        String bufferRow;
-//        while ((bufferRow = bin.readLine()) != null) {
-//
-//          // prints out the information
-//          console.write( bufferRow );
-//
-//        }
-//        bin.close();
-//
-//      } catch (IOException e) {
-//        MessageDialog.openError(null, "Error in output", e.toString());
-//      } finally {
-//
-//      }
-//    }
-//  }
+  //   static class OutputThread extends Thread {
+  //           InputStream fInputStream;
+  //           PHPConsole console;
+  //
+  //           OutputThread(InputStream inputStream, PHPConsole console) {
+  //                   this.fInputStream = inputStream;
+  //                   this.console = console;
+  //           }
+  //
+  //           public void run() {
+  //                   try {
+  //                           BufferedReader bin = new BufferedReader(new InputStreamReader(fInputStream));
+  //
+  //                           String bufferRow;
+  //                           while ((bufferRow = bin.readLine()) != null) {
+  //
+  //                                   // prints out the information
+  //                                   console.write( bufferRow );
+  //
+  //                           }
+  //                           bin.close();
+  //
+  //                   } catch (IOException e) {
+  //                           MessageDialog.openError(null, "Error in output", e.toString());
+  //                   } finally {
+  //
+  //                   }
+  //           }
+  //   }
 
 }