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 = PHPeclipsePlugin.getDefault().getPreferenceStore();
33 String documentRoot = store.getString(PHPeclipsePlugin.DOCUMENTROOT_PREF);
34 // replace backslash with slash in the DocumentRoot under Windows
35 documentRoot = documentRoot.replace('\\', '/');
36 String[] arguments = { documentRoot };
37 MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.APACHE_START_PREF));
40 store.getString(PHPeclipsePlugin.APACHE_RUN_PREF),
41 form.format(arguments),
42 store.getBoolean(PHPeclipsePlugin.APACHE_START_BACKGROUND));
45 // public static void execute(String command, String consoleMessage) {
46 // // MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
48 // PHPConsole console = PHPConsole.getInstance();
49 // console.write(consoleMessage + command + "\n");
50 // Runtime runtime = Runtime.getRuntime();
52 // // runs the command
53 // Process p = runtime.exec(command);
55 // if (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) {
57 // OutputThread out = new OutputThread(p.getInputStream(), console);
58 // OutputThread err = new OutputThread(p.getErrorStream(), console);
64 // } catch (IOException e) {
66 // System.err.println("Problem");
67 // e.printStackTrace();
74 * Executes an external progam and saves the LaunchConfiguration under external tools
75 * @param command external tools command name
76 * @param executable executable path i.e.c:\apache\apache.exe
77 * @param arguments arguments for this configuration
78 * @param background run this configuration in background mode
80 public static void execute(String command, String executable, String arguments, boolean background) {
81 PHPConsole console = PHPConsole.getInstance();
82 String consoleMessage;
84 consoleMessage = "run in background mode-" + command + ": " + executable + " " + arguments;
86 consoleMessage = "run in foreground mode-" + command + ": " + executable + " " + arguments;
88 console.write(consoleMessage + "\n");
90 ExternalToolsUtil.execute(command, executable, arguments, background);
91 // MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
93 // PHPConsole console = PHPConsole.getInstance();
94 // console.write(consoleMessage + command + "\n");
96 // ExternalToolsUtil.execute()
97 // Runtime runtime = Runtime.getRuntime();
99 // // runs the command
100 // Process p = runtime.exec(command);
102 // // gets the input stream to have the post-compile-time information
103 // InputStream stream = p.getInputStream();
105 // // get the string from Stream
106 // String consoleOutput = PHPConsole.getStringFromStream(stream);
108 // // prints out the information
109 // console.write(consoleOutput);
110 // return consoleOutput;
112 // } catch (IOException e) {
114 // System.err.println("Problem");
115 // e.printStackTrace();
120 public static String getParserOutput(String command, String consoleMessage) {
121 // MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command);
123 PHPConsole console = PHPConsole.getInstance();
124 if (console != null) {
125 console.write(consoleMessage + command + "\n");
128 Runtime runtime = Runtime.getRuntime();
131 Process p = runtime.exec(command);
133 // gets the input stream to have the post-compile-time information
134 InputStream stream = p.getInputStream();
136 // get the string from Stream
137 String consoleOutput = PHPConsole.getStringFromStream(stream);
139 // prints out the information
140 if (console != null) {
141 console.write(consoleOutput);
143 return consoleOutput;
145 } catch (IOException e) {
147 System.err.println("Problem");
154 public void selectionChanged(IAction action, ISelection selection) {
158 public void init(IWorkbenchWindow window) {
159 this.activeWindow = window;
162 public void dispose() {
166 // static class OutputThread extends Thread {
167 // InputStream fInputStream;
168 // PHPConsole console;
170 // OutputThread(InputStream inputStream, PHPConsole console) {
171 // this.fInputStream = inputStream;
172 // this.console = console;
175 // public void run() {
177 // BufferedReader bin = new BufferedReader(new InputStreamReader(fInputStream));
180 // while ((bufferRow = bin.readLine()) != null) {
182 // // prints out the information
183 // console.write( bufferRow );
188 // } catch (IOException e) {
189 // MessageDialog.openError(null, "Error in output", e.toString());