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 void execute(String command, String consoleMessage) {
41 // // MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
43 // PHPConsole console = PHPConsole.getInstance();
44 // console.write(consoleMessage + command + "\n");
45 // Runtime runtime = Runtime.getRuntime();
47 // // runs the command
48 // Process p = runtime.exec(command);
50 // if (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) {
52 // OutputThread out = new OutputThread(p.getInputStream(), console);
53 // OutputThread err = new OutputThread(p.getErrorStream(), console);
59 // } catch (IOException e) {
61 // System.err.println("Problem");
62 // e.printStackTrace();
68 public static String execute(String command, String consoleMessage) {
69 // MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
71 PHPConsole console = PHPConsole.getInstance();
72 console.write(consoleMessage + command + "\n");
73 Runtime runtime = Runtime.getRuntime();
76 Process p = runtime.exec(command);
78 // gets the input stream to have the post-compile-time information
79 InputStream stream = p.getInputStream();
81 // get the string from Stream
82 String consoleOutput = PHPConsole.getStringFromStream(stream);
84 // prints out the information
85 console.write(consoleOutput);
88 } catch (IOException e) {
90 System.err.println("Problem");
96 public static String getParserOutput(String command, String consoleMessage) {
97 // MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
99 PHPConsole console = PHPConsole.getInstance();
100 console.write(consoleMessage + command + "\n");
101 Runtime runtime = Runtime.getRuntime();
104 Process p = runtime.exec(command);
106 // gets the input stream to have the post-compile-time information
107 InputStream stream = p.getInputStream();
109 // get the string from Stream
110 String consoleOutput = PHPConsole.getStringFromStream(stream);
112 // prints out the information
113 console.write(consoleOutput);
114 return consoleOutput;
116 } catch (IOException e) {
118 System.err.println("Problem");
125 public void selectionChanged(IAction action, ISelection selection) {
129 public void init(IWorkbenchWindow window) {
130 this.activeWindow = window;
133 public void dispose() {
137 // static class OutputThread extends Thread {
138 // InputStream fInputStream;
139 // PHPConsole console;
141 // OutputThread(InputStream inputStream, PHPConsole console) {
142 // this.fInputStream = inputStream;
143 // this.console = console;
146 // public void run() {
148 // BufferedReader bin = new BufferedReader(new InputStreamReader(fInputStream));
151 // while ((bufferRow = bin.readLine()) != null) {
153 // // prints out the information
154 // console.write( bufferRow );
159 // } catch (IOException e) {
160 // MessageDialog.openError(null, "Error in output", e.toString());