deleted unnecessary "folder.addPlaceholder(IPageLayout.ID_RES_NAV);"
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / actions / PHPStartApacheAction.java
index 7f69883..4082d14 100644 (file)
@@ -11,52 +11,161 @@ Contributors:
 **********************************************************************/
 package net.sourceforge.phpeclipse.actions;
 
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStreamReader;
+import java.io.InputStream;
 import java.text.MessageFormat;
 
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.views.PHPConsole;
+
 import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
 
 public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
-       protected IWorkbenchWindow activeWindow = null;
-
-       public void run(IAction action) {
-               final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
-               String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF);
-               // replace backslash with slash in the DocumentRoot under Windows
-               documentRoot = documentRoot.replace('\\', '/');
-               String[] arguments = { documentRoot };
-               MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.APACHE_START_PREF));
-               execute(form.format(arguments));
-       }
-
-       public void execute(String command) {
-//             MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
-               try {
-                       Runtime runtime = Runtime.getRuntime();
-                       //      Process process = runtime.exec(new String[] { "c:\\apache\\apache.exe" });
-                       Process process = runtime.exec(command);
-               } catch (IOException e) {
-                       MessageDialog.openInformation(activeWindow.getShell(), "IOException: ", e.getMessage());
-               }
-       }
-
-       public void selectionChanged(IAction action, ISelection selection) {
-
-       }
-
-       public void init(IWorkbenchWindow window) {
-               this.activeWindow = window;
-       }
-
-       public void dispose() {
-
-       }
+  protected IWorkbenchWindow activeWindow = null;
+
+  public void run(IAction action) {
+    final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
+    String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF);
+    // replace backslash with slash in the DocumentRoot under Windows
+    documentRoot = documentRoot.replace('\\', '/');
+    String[] arguments = { documentRoot };
+    MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.APACHE_START_PREF));
+    execute(form.format(arguments), "Start Apache: ");
+  }
+
+//  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();
+
+    }
+    return "";
+  }
+  public static String getParserOutput(String command, String consoleMessage) {
+    //    MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
+    try {
+      PHPConsole console = PHPConsole.getInstance();
+      if (console!=null) {
+        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
+         if (console!=null) {
+        console.write(consoleOutput);
+         }
+      return consoleOutput;
+
+    } catch (IOException e) {
+
+      System.err.println("Problem");
+      e.printStackTrace();
+
+    }
+    return "";
+  }
+
+  public void selectionChanged(IAction action, ISelection selection) {
+
+  }
+
+  public void init(IWorkbenchWindow window) {
+    this.activeWindow = window;
+  }
+
+  public void dispose() {
+
+  }
+
+//  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 {
+//
+//      }
+//    }
+//  }
+
 }