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.phpdt.externaltools.launchConfigurations.ExternalToolsUtil;
19 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
20 import net.sourceforge.phpeclipse.views.PHPConsole;
22 import org.eclipse.jface.action.IAction;
23 import org.eclipse.jface.preference.IPreferenceStore;
24 import org.eclipse.jface.viewers.ISelection;
25 import org.eclipse.ui.IWorkbenchWindow;
26 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
28 public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate {
29 protected IWorkbenchWindow activeWindow = null;
31 public void run(IAction action) {
32 final IPreferenceStore store =
33 PHPeclipsePlugin.getDefault().getPreferenceStore();
34 String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF);
35 // replace backslash with slash in the DocumentRoot under Windows
36 documentRoot = documentRoot.replace('\\', '/');
37 String[] arguments = { documentRoot };
39 new MessageFormat(store.getString(PHPeclipsePlugin.APACHE_START_PREF));
42 store.getString(PHPeclipsePlugin.APACHE_RUN_PREF),
43 form.format(arguments),
44 store.getBoolean(PHPeclipsePlugin.APACHE_START_BACKGROUND));
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();
76 * Executes an external progam and saves the LaunchConfiguration under external tools
77 * @param command external tools command name
78 * @param executable executable path i.e.c:\apache\apache.exe
79 * @param arguments arguments for this configuration
80 * @param background run this configuration in background mode
82 public static void execute(
87 PHPConsole console = PHPConsole.getInstance();
88 String consoleMessage;
91 "run in background mode-"
99 "run in foreground mode-"
106 console.write(consoleMessage + "\n");
108 ExternalToolsUtil.execute(command, executable, arguments, background);
109 // MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
111 // PHPConsole console = PHPConsole.getInstance();
112 // console.write(consoleMessage + command + "\n");
114 // ExternalToolsUtil.execute()
115 // Runtime runtime = Runtime.getRuntime();
117 // // runs the command
118 // Process p = runtime.exec(command);
120 // // gets the input stream to have the post-compile-time information
121 // InputStream stream = p.getInputStream();
123 // // get the string from Stream
124 // String consoleOutput = PHPConsole.getStringFromStream(stream);
126 // // prints out the information
127 // console.write(consoleOutput);
128 // return consoleOutput;
130 // } catch (IOException e) {
132 // System.err.println("Problem");
133 // e.printStackTrace();
138 public static String getParserOutput(String command, String consoleMessage) {
139 // MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
141 PHPConsole console = null;
143 console = PHPConsole.getInstance();
144 if (console != null) {
145 console.write(consoleMessage + command + "\n");
147 } catch (Throwable th) {
151 Runtime runtime = Runtime.getRuntime();
154 Process p = runtime.exec(command);
156 // gets the input stream to have the post-compile-time information
157 InputStream stream = p.getInputStream();
159 // get the string from Stream
160 String consoleOutput = PHPConsole.getStringFromStream(stream);
162 // prints out the information
163 if (console != null) {
164 console.write(consoleOutput);
166 return consoleOutput;
168 } catch (IOException e) {
170 System.err.println("Problem");
177 public void selectionChanged(IAction action, ISelection selection) {
181 public void init(IWorkbenchWindow window) {
182 this.activeWindow = window;
185 public void dispose() {
189 // static class OutputThread extends Thread {
190 // InputStream fInputStream;
191 // PHPConsole console;
193 // OutputThread(InputStream inputStream, PHPConsole console) {
194 // this.fInputStream = inputStream;
195 // this.console = console;
198 // public void run() {
200 // BufferedReader bin = new BufferedReader(new InputStreamReader(fInputStream));
203 // while ((bufferRow = bin.readLine()) != null) {
205 // // prints out the information
206 // console.write( bufferRow );
211 // } catch (IOException e) {
212 // MessageDialog.openError(null, "Error in output", e.toString());