1 /**********************************************************************
 
   2 Copyright (c) 2000, 2002 IBM Corp. and others.
 
   3 All rights reserved. This program and the accompanying materials
 
   4 are made available under the terms of the Common Public License v1.0
 
   5 which accompanies this distribution, and is available at
 
   6 http://www.eclipse.org/legal/cpl-v10.html
 
   9     IBM Corporation - Initial implementation
 
  10     Klaus Hartlage - www.eclipseproject.de
 
  11 **********************************************************************/
 
  12 package net.sourceforge.phpeclipse.actions;
 
  14 import java.io.BufferedReader;
 
  15 import java.io.IOException;
 
  16 import java.io.InputStream;
 
  17 import java.io.InputStreamReader;
 
  18 import java.text.MessageFormat;
 
  20 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
  21 import net.sourceforge.phpeclipse.views.PHPConsole;
 
  22 import org.eclipse.core.runtime.IStatus;
 
  23 import org.eclipse.core.runtime.Status;
 
  24 import org.eclipse.jface.action.IAction;
 
  25 import org.eclipse.jface.dialogs.MessageDialog;
 
  26 import org.eclipse.jface.preference.IPreferenceStore;
 
  27 import org.eclipse.jface.viewers.ISelection;
 
  28 import org.eclipse.ui.IWorkbenchPage;
 
  29 import org.eclipse.ui.IWorkbenchWindow;
 
  30 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
 
  31 import org.eclipse.ui.PartInitException;
 
  32 import org.eclipse.ui.PlatformUI;
 
  34 public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
 
  35   protected IWorkbenchWindow activeWindow = null;
 
  37   public void run(IAction action) {
 
  38     final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
 
  39     String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF);
 
  40     // replace backslash with slash in the DocumentRoot under Windows
 
  41     documentRoot = documentRoot.replace('\\', '/');
 
  42     String[] arguments = { documentRoot };
 
  43     MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.APACHE_START_PREF));
 
  44     execute(form.format(arguments), "Start Apache: ");
 
  47 //  public static void execute(String command, String consoleMessage) {
 
  48 //    //                MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
 
  50 //      PHPConsole console = PHPConsole.getInstance();
 
  51 //      console.write(consoleMessage + command + "\n");
 
  52 //      Runtime runtime = Runtime.getRuntime(); 
 
  54 //      // runs the command
 
  55 //      Process p = runtime.exec(command);
 
  57 //      if (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) {
 
  59 //          OutputThread out = new OutputThread(p.getInputStream(), console);
 
  60 //          OutputThread err = new OutputThread(p.getErrorStream(), console);
 
  66 //    } catch (IOException e) {
 
  68 //      System.err.println("Problem");
 
  69 //      e.printStackTrace();
 
  75   public static String execute(String command, String consoleMessage) {
 
  76     //    MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
 
  78       PHPConsole console = PHPConsole.getInstance();
 
  79       console.write(consoleMessage + command + "\n");
 
  80       Runtime runtime = Runtime.getRuntime();
 
  83       Process p = runtime.exec(command);
 
  85       // gets the input stream to have the post-compile-time information
 
  86       InputStream stream = p.getInputStream();
 
  88       // get the string from Stream
 
  89       String consoleOutput = PHPConsole.getStringFromStream(stream);
 
  91       // prints out the information
 
  92       console.write(consoleOutput);
 
  95     } catch (IOException e) {
 
  97       System.err.println("Problem");
 
 103   public static String getParserOutput(String command, String consoleMessage) {
 
 104     //    MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
 
 106       PHPConsole console = PHPConsole.getInstance();
 
 107       console.write(consoleMessage + command + "\n");
 
 108       Runtime runtime = Runtime.getRuntime();
 
 111       Process p = runtime.exec(command);
 
 113       // gets the input stream to have the post-compile-time information
 
 114       InputStream stream = p.getInputStream();
 
 116       // get the string from Stream
 
 117       String consoleOutput = PHPConsole.getStringFromStream(stream);
 
 119       // prints out the information
 
 120       console.write(consoleOutput);
 
 121       return consoleOutput;
 
 123     } catch (IOException e) {
 
 125       System.err.println("Problem");
 
 132   public void selectionChanged(IAction action, ISelection selection) {
 
 136   public void init(IWorkbenchWindow window) {
 
 137     this.activeWindow = window;
 
 140   public void dispose() {
 
 144 //  static class OutputThread extends Thread {
 
 145 //    InputStream fInputStream;
 
 146 //    PHPConsole console;
 
 148 //    OutputThread(InputStream inputStream, PHPConsole console) {
 
 149 //      this.fInputStream = inputStream;
 
 150 //      this.console = console;
 
 153 //    public void run() {
 
 155 //        BufferedReader bin = new BufferedReader(new InputStreamReader(fInputStream));
 
 158 //        while ((bufferRow = bin.readLine()) != null) {
 
 160 //          // prints out the information
 
 161 //          console.write( bufferRow );
 
 166 //      } catch (IOException e) {
 
 167 //        MessageDialog.openError(null, "Error in output", e.toString());