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;
21 import org.eclipse.jface.action.IAction;
22 import org.eclipse.jface.preference.IPreferenceStore;
23 import org.eclipse.jface.viewers.ISelection;
24 import org.eclipse.ui.IWorkbenchWindow;
25 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
27 public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
28 protected IWorkbenchWindow activeWindow = null;
30 public void run(IAction action) {
31 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
32 String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF);
33 // replace backslash with slash in the DocumentRoot under Windows
34 documentRoot = documentRoot.replace('\\', '/');
35 String[] arguments = { documentRoot };
36 MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.APACHE_START_PREF));
37 execute(form.format(arguments), "Start Apache: ");
40 public static String execute(String command, String consoleMessage) {
41 // MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
43 PHPConsole.write(consoleMessage+command+"\n");
44 Runtime runtime = Runtime.getRuntime();
47 Process p = runtime.exec(command);
49 // gets the input stream to have the post-compile-time information
50 InputStream stream = p.getInputStream();
52 // get the string from Stream
53 String consoleOutput = PHPConsole.getStringFromStream(stream);
55 // prints out the information
56 PHPConsole.write(consoleOutput);
59 } catch (IOException e) {
61 System.err.println("Problem");
68 public void selectionChanged(IAction action, ISelection selection) {
72 public void init(IWorkbenchWindow window) {
73 this.activeWindow = window;
76 public void dispose() {