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.IOException;
 
  15 import java.io.InputStream;
 
  16 import java.text.MessageFormat;
 
  18 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
  19 import net.sourceforge.phpeclipse.views.PHPConsole;
 
  20 import org.eclipse.core.runtime.CoreException;
 
  21 import org.eclipse.core.runtime.IStatus;
 
  22 import org.eclipse.core.runtime.Status;
 
  23 import org.eclipse.jface.action.IAction;
 
  24 import org.eclipse.jface.preference.IPreferenceStore;
 
  25 import org.eclipse.jface.viewers.ISelection;
 
  26 import org.eclipse.ui.IWorkbenchPage;
 
  27 import org.eclipse.ui.IWorkbenchWindow;
 
  28 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
 
  29 import org.eclipse.ui.PartInitException;
 
  30 import org.eclipse.ui.PlatformUI;
 
  31 import sun.security.krb5.internal.crypto.e;
 
  33 public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
 
  34   protected IWorkbenchWindow activeWindow = null;
 
  36   public void run(IAction action) {
 
  37     final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
 
  38     String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF);
 
  39     // replace backslash with slash in the DocumentRoot under Windows
 
  40     documentRoot = documentRoot.replace('\\', '/');
 
  41     String[] arguments = { documentRoot };
 
  42     MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.APACHE_START_PREF));
 
  43     execute(form.format(arguments), "Start Apache: ");
 
  46   public void execute(String command, String consoleMessage) {
 
  47     //          MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
 
  49       PHPConsole.write(consoleMessage+command+"\n");
 
  50       Runtime runtime = Runtime.getRuntime();
 
  53       Process p = runtime.exec(command);
 
  55       // gets the input stream to have the post-compile-time information
 
  56       InputStream stream = p.getInputStream();
 
  58       // and get the string from it
 
  59       String compilerOutput = PHPConsole.getStringFromStream(stream);
 
  61       // prints out the information
 
  62       PHPConsole.write(compilerOutput);
 
  64       // parse the buffer to find the errors and create markers
 
  65     //  createMarkers(compilerOutput, fileToCompile);
 
  67     } catch (IOException e) {
 
  68       // @todo should throw the exception again
 
  69       System.err.println("Problem");
 
  71 //    } catch (CoreException e) {
 
  72 //      e.printStackTrace();
 
  73 //      // @todo do something here !
 
  77   public void selectionChanged(IAction action, ISelection selection) {
 
  81   public void init(IWorkbenchWindow window) {
 
  82     this.activeWindow = window;
 
  85   public void dispose() {