1 package net.sourceforge.phpeclipse.externaltools;
3 /**********************************************************************
4 Copyright (c) 2002 IBM Corp. and others. All rights reserved.
5 This file is made available under the terms of the Common Public License v1.0
6 which accompanies this distribution, and is available at
7 http://www.eclipse.org/legal/cpl-v10.html
10 **********************************************************************/
12 import java.io.InputStream;
13 import java.net.MalformedURLException;
15 import java.util.Enumeration;
16 import java.util.PropertyResourceBundle;
18 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsImages;
19 import net.sourceforge.phpdt.externaltools.internal.model.IPreferenceConstants;
20 import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager;
21 import net.sourceforge.phpdt.externaltools.internal.registry.ArgumentVariableRegistry;
22 import net.sourceforge.phpdt.externaltools.internal.registry.PathLocationVariableRegistry;
23 import net.sourceforge.phpdt.externaltools.internal.registry.RefreshScopeVariableRegistry;
24 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
26 import org.eclipse.core.runtime.CoreException;
27 import org.eclipse.core.runtime.IStatus;
28 import org.eclipse.core.runtime.Path;
29 import org.eclipse.core.runtime.Platform;
30 import org.eclipse.core.runtime.Status;
31 import org.eclipse.jface.preference.IPreferenceStore;
32 import org.eclipse.jface.preference.PreferenceConverter;
33 import org.eclipse.jface.resource.ImageDescriptor;
34 import org.eclipse.jface.resource.ImageRegistry;
35 import org.eclipse.swt.graphics.RGB;
36 import org.eclipse.swt.widgets.Display;
37 import org.eclipse.ui.IWorkbenchWindow;
38 import org.eclipse.ui.plugin.AbstractUIPlugin;
39 import org.osgi.framework.Bundle;
40 import org.osgi.framework.BundleContext;
43 * External tools plug-in class
45 public final class ExternalToolsPlugin extends AbstractUIPlugin {
46 public static final String XAMPP_START_PREF = "_xampp_start_pref";
48 public static final String XAMPP_STOP_PREF = "_xampp_stop_pref";
50 public static final String MYSQL_RUN_PREF = "_mysql_run_pref";
52 public static final String MYSQL_START_BACKGROUND = "_mysql_start_background";
54 public static final String MYSQL_PREF = "__mysql_start";
56 public static final String APACHE_RUN_PREF = "_apache_run_pref";
58 public static final String APACHE_START_BACKGROUND = "_apache_start_background";
60 public static final String APACHE_START_PREF = "__apache_start";
62 public static final String APACHE_STOP_BACKGROUND = "_apache_stop_background";
64 public static final String APACHE_STOP_PREF = "__apache_stop";
66 public static final String APACHE_RESTART_BACKGROUND = "_apache_restart_background";
68 public static final String APACHE_RESTART_PREF = "__apache_restart";
70 public static final String HTTPD_CONF_PATH_PREF = "__httpd_conf_path";
72 public static final String ETC_HOSTS_PATH_PREF = "__etc_hosts_path";
73 // public static final String SHOW_OUTPUT_IN_CONSOLE = "_show_output_in_console";
75 public static final String PHP_RUN_PREF = "_php_run_pref";
77 public static final String EXTERNAL_PARSER_PREF = "_external_parser";
80 * Status representing no problems encountered during operation.
82 public static final IStatus OK_STATUS = new Status(IStatus.OK, IExternalToolConstants.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
84 private static ExternalToolsPlugin plugin;
86 private RefreshScopeVariableRegistry refreshVarRegistry;
88 private PathLocationVariableRegistry fileLocVarRegistry;
90 private PathLocationVariableRegistry dirLocVarRegistry;
92 private ArgumentVariableRegistry argumentVarRegistry;
96 * This version is recommended for eclipse3.0 and above
98 public ExternalToolsPlugin() {
104 * Returns the default instance of the receiver. This represents the runtime plugin.
106 public static ExternalToolsPlugin getDefault() {
111 * Returns a new <code>IStatus</code> for this plug-in
113 public static IStatus newErrorStatus(String message, Throwable exception) {
114 return new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception);
118 * Returns a new <code>CoreException</code> for this plug-in
120 public static CoreException newError(String message, Throwable exception) {
121 return new CoreException(new Status(Status.ERROR, IExternalToolConstants.PLUGIN_ID, 0, message, exception));
125 * Returns the registry of refresh scope variables.
127 public ArgumentVariableRegistry getArgumentVariableRegistry() {
128 if (argumentVarRegistry == null)
129 argumentVarRegistry = new ArgumentVariableRegistry();
130 return argumentVarRegistry;
134 * Returns the registry of directory location variables.
136 public PathLocationVariableRegistry getDirectoryLocationVariableRegistry() {
137 if (dirLocVarRegistry == null)
138 dirLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_DIRECTORY_VARIABLES);
139 return dirLocVarRegistry;
143 * Returns the registry of file location variables.
145 public PathLocationVariableRegistry getFileLocationVariableRegistry() {
146 if (fileLocVarRegistry == null)
147 fileLocVarRegistry = new PathLocationVariableRegistry(IExternalToolConstants.EXTENSION_POINT_FILE_VARIABLES);
148 return fileLocVarRegistry;
152 * Returns the registry of refresh scope variables.
154 public RefreshScopeVariableRegistry getRefreshVariableRegistry() {
155 if (refreshVarRegistry == null)
156 refreshVarRegistry = new RefreshScopeVariableRegistry();
157 return refreshVarRegistry;
161 * Writes the message to the plug-in's log
164 * the text to write to the log
166 public void log(String message, Throwable exception) {
167 IStatus status = newErrorStatus(message, exception);
168 // getLog().log(status);
169 ExternalToolsPlugin.log(status);
172 public static void log(IStatus status) {
173 getDefault().getLog().log(status);
177 * Returns the ImageDescriptor for the icon with the given path
179 * @return the ImageDescriptor object
181 public ImageDescriptor getImageDescriptor(String path) {
183 Bundle bundle = ExternalToolsPlugin.getDefault().getBundle();
184 URL installURL = bundle.getEntry("/"); //$NON-NLS-1$
185 URL url = new URL(installURL, path);
186 return ImageDescriptor.createFromURL(url);
187 } catch (MalformedURLException e) {
193 * (non-Javadoc) Method declared in AbstractUIPlugin.
196 protected void initializeDefaultPreferences(IPreferenceStore store) {
197 String operatingSystem = Platform.getOS();
198 // maxosx, linux, solaris, win32,...
200 InputStream is = getDefault().openStream(new Path("prefs/default_" + operatingSystem + ".properties"));
201 PropertyResourceBundle resourceBundle = new PropertyResourceBundle(is);
202 Enumeration e = resourceBundle.getKeys();
204 while (e.hasMoreElements()) {
205 key = (String) e.nextElement();
206 store.setDefault(key, resourceBundle.getString(key));
208 } catch (Exception e) {
209 // no default properties found
210 if (operatingSystem.equals(Platform.OS_WIN32)) {
211 store.setDefault(PHP_RUN_PREF, "c:\\apache\\php\\php.exe");
212 store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}");
213 store.setDefault(MYSQL_RUN_PREF, "c:\\apache\\mysql\\bin\\mysqld-nt.exe");
214 store.setDefault(APACHE_RUN_PREF, "c:\\apache\\apache.exe");
215 store.setDefault(XAMPP_START_PREF, "c:\\xampp\\xampp_start.exe");
216 store.setDefault(XAMPP_STOP_PREF, "c:\\xampp\\xampp_stop.exe");
217 store.setDefault(ETC_HOSTS_PATH_PREF, "c:\\windows\\system32\\drivers\\etc\\hosts");
219 store.setDefault(PHP_RUN_PREF, "/apache/php/php");
220 store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}");
221 store.setDefault(MYSQL_RUN_PREF, "/apache/mysql/bin/mysqld");
222 store.setDefault(APACHE_RUN_PREF, "/apache/apache");
223 store.setDefault(XAMPP_START_PREF, "xamp/xampp_start");
224 store.setDefault(XAMPP_STOP_PREF, "xampp/xampp_stop");
226 store.setDefault(MYSQL_PREF, "--standalone");
227 store.setDefault(APACHE_START_PREF, "-c \"DocumentRoot \"{0}\"\"");
228 store.setDefault(APACHE_STOP_PREF, "-k shutdown");
229 store.setDefault(APACHE_RESTART_PREF, "-k restart");
230 store.setDefault(MYSQL_START_BACKGROUND, "true");
231 store.setDefault(APACHE_START_BACKGROUND, "true");
232 store.setDefault(APACHE_STOP_BACKGROUND, "true");
233 store.setDefault(APACHE_RESTART_BACKGROUND, "true");
236 // store.setDefault(SHOW_OUTPUT_IN_CONSOLE, "true");
238 store.setDefault(IPreferenceConstants.PROMPT_FOR_MIGRATION, true);
240 PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_ERROR_RGB, new RGB(255, 0, 0)); // red - exactly the same as
242 PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_WARNING_RGB, new RGB(255, 100, 0)); // orange
243 PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_INFO_RGB, new RGB(0, 0, 255)); // blue
244 PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_VERBOSE_RGB, new RGB(0, 200, 125)); // green
245 PreferenceConverter.setDefault(store, IPreferenceConstants.CONSOLE_DEBUG_RGB, new RGB(0, 0, 0)); // black
248 public static IWorkbenchWindow getActiveWorkbenchWindow() {
249 return ExternalToolsPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow();
253 * Returns the standard display to be used. The method first checks, if the thread calling this method has an associated display.
254 * If so, this display is returned. Otherwise the method returns the default display.
256 public static Display getStandardDisplay() {
257 Display display = Display.getCurrent();
258 if (display == null) {
259 display = Display.getDefault();
265 * @see org.eclipse.ui.plugin.AbstractUIPlugin#createImageRegistry()
267 protected ImageRegistry createImageRegistry() {
268 return ExternalToolsImages.initializeImageRegistry();
273 * @see org.eclipse.core.runtime.Plugin#start(BundleContext context)
275 public void start(BundleContext context) throws Exception {
276 super.start(context);
277 getStandardDisplay().asyncExec(new Runnable() {
279 //initialize the variable context manager
280 VariableContextManager.getDefault();