*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / actions / PHPStartApacheAction.java
index 8a6b5e2..b1f00bd 100644 (file)
@@ -17,18 +17,12 @@ import java.text.MessageFormat;
 
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.views.PHPConsole;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
+
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import sun.security.krb5.internal.crypto.e;
 
 public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
   protected IWorkbenchWindow activeWindow = null;
@@ -43,35 +37,89 @@ public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
     execute(form.format(arguments), "Start Apache: ");
   }
 
-  public void execute(String command, String consoleMessage) {
-    //         MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
+//  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.write(consoleMessage+command+"\n");
+      PHPConsole console = PHPConsole.getInstance();
+      console.write(consoleMessage + command + "\n");
       Runtime runtime = Runtime.getRuntime();
 
-          // runs the command
+      // runs the command
       Process p = runtime.exec(command);
 
       // gets the input stream to have the post-compile-time information
       InputStream stream = p.getInputStream();
 
-      // and get the string from it
-      String compilerOutput = PHPConsole.getStringFromStream(stream);
+      // get the string from Stream
+      String consoleOutput = PHPConsole.getStringFromStream(stream);
 
       // prints out the information
-      PHPConsole.write(compilerOutput);
+      console.write(consoleOutput);
+      return consoleOutput;
 
-      // parse the buffer to find the errors and create markers
-    //  createMarkers(compilerOutput, fileToCompile);
+    } 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();
+      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) {
-      // @todo should throw the exception again
+
       System.err.println("Problem");
       e.printStackTrace();
-//    } catch (CoreException e) {
-//      e.printStackTrace();
-//      // @todo do something here !
+
     }
+    return "";
   }
 
   public void selectionChanged(IAction action, ISelection selection) {
@@ -85,4 +133,35 @@ public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
   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 {
+//
+//      }
+//    }
+//  }
+
 }