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();
101 console.write(consoleMessage + command + "\n");
103 Runtime runtime = Runtime.getRuntime();
106 Process p = runtime.exec(command);
108 // gets the input stream to have the post-compile-time information
109 InputStream stream = p.getInputStream();
111 // get the string from Stream
112 String consoleOutput = PHPConsole.getStringFromStream(stream);
114 // prints out the information
116 console.write(consoleOutput);
118 return consoleOutput;
120 } catch (IOException e) {
122 System.err.println("Problem");
129 public void selectionChanged(IAction action, ISelection selection) {
133 public void init(IWorkbenchWindow window) {
134 this.activeWindow = window;
137 public void dispose() {
141 // static class OutputThread extends Thread {
142 // InputStream fInputStream;
143 // PHPConsole console;
145 // OutputThread(InputStream inputStream, PHPConsole console) {
146 // this.fInputStream = inputStream;
147 // this.console = console;
150 // public void run() {
152 // BufferedReader bin = new BufferedReader(new InputStreamReader(fInputStream));
155 // while ((bufferRow = bin.readLine()) != null) {
157 // // prints out the information
158 // console.write( bufferRow );
163 // } catch (IOException e) {
164 // MessageDialog.openError(null, "Error in output", e.toString());