summaryrefslogtreecommitdiffstats
path: root/eclipse-phpeclipse-httpd-integration.patch
blob: da54e57c20eac0a74e2aea0ba1488d32d7369b7b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
Index: ./plugins/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java
===================================================================
--- ./plugins/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java	(revision 1625)
+++ ./plugins/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java	(working copy)
@@ -52,6 +52,7 @@
 import net.sourceforge.phpeclipse.builder.ExternalStorageDocumentProvider;
 import net.sourceforge.phpeclipse.builder.FileStorage;
 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
+import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin;
 import net.sourceforge.phpeclipse.phpeditor.CustomBufferFactory;
 import net.sourceforge.phpeclipse.phpeditor.DocumentAdapter;
 import net.sourceforge.phpeclipse.phpeditor.ICompilationUnitDocumentProvider;
@@ -989,6 +990,8 @@
 
 			// RefactoringCore.getUndoManager().shutdown();
 		} finally {
+			if(ExternalToolsPlugin.getDefault() != null) 
+				ExternalToolsPlugin.getDefault().stopHttpd();
 			super.stop(context);
 		}
 	}
Index: ./plugins/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/WebUI.java
===================================================================
--- ./plugins/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/WebUI.java	(revision 1625)
+++ ./plugins/net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/WebUI.java	(working copy)
@@ -15,16 +15,19 @@
 
 import java.io.IOException;
 import java.net.URL;
+import java.net.ServerSocket;
 
 import net.sourceforge.phpeclipse.ui.templates.template.HTMLContextType;
 import net.sourceforge.phpeclipse.ui.templates.template.JSContextType;
 import net.sourceforge.phpeclipse.ui.templates.template.SmartyContextType;
 import net.sourceforge.phpeclipse.ui.templates.template.XMLContextType;
 
+import org.eclipse.core.internal.utils.FileUtil;
 import org.eclipse.core.resources.IWorkspace;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.Platform;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.resource.ImageRegistry;
@@ -56,6 +59,7 @@
 
 	/** The shared instance. */
 	private static WebUI plugin;
+	private int port = 0;
 
 	public static IWorkbenchPage getActivePage() {
 		return getDefault().internalGetActivePage();
@@ -165,10 +169,42 @@
 		return fStore;
 	}
 
+	public int getHttpdPort() {
+		if (port == 0) {
+			port = findFreePort();
+		}
+		return port;
+	}
+
+	private int findFreePort() {
+		ServerSocket socket = null;
+		try {
+			socket = new ServerSocket(0);
+			socket.setReuseAddress(true);
+			return socket.getLocalPort();
+		} catch(IOException e) {
+			IStatus status = new Status(IStatus.ERROR, "net.sourceforge.phpeclipse.ui", IStatus.OK, "Error finding free port.", e);
+			plugin.getLog().log(status);
+		} finally {
+			if(socket != null) {
+				try {
+					socket.close();
+				} catch(IOException e) {
+					IStatus status = new Status(IStatus.ERROR, "net.sourceforge.phpeclipse.ui", IStatus.OK, "Error finding free port.", e);
+					plugin.getLog().log(status);
+				}
+			}
+		}
+		return -1;
+	}
+
 	protected void initializeDefaultPreferences(IPreferenceStore store) {
-		store.setDefault(PHP_LOCALHOST_PREF, "http://localhost");
-		store.setDefault(PHP_DOCUMENTROOT_PREF, getWorkspace().getRoot()
-				.getFullPath().toString());
+		if (port ==  0) {
+			port = findFreePort();
+		}
+		store.setDefault(PHP_LOCALHOST_PREF, "http://localhost" + ":" + port);
+		store.setDefault(PHP_DOCUMENTROOT_PREF,
+				FileUtil.canonicalPath(Platform.getLocation()).removeTrailingSeparator().toOSString());
 		// store.setDefault(PHP_BOOKMARK_DEFAULT, "");
 
 		store.setDefault(PHP_AUTO_PREVIEW_DEFAULT, "false");
Index: ./plugins/net.sourceforge.phpeclipse.externaltools/prefs/default_linux.properties
===================================================================
--- ./plugins/net.sourceforge.phpeclipse.externaltools/prefs/default_linux.properties	(revision 1625)
+++ ./plugins/net.sourceforge.phpeclipse.externaltools/prefs/default_linux.properties	(working copy)
@@ -1,13 +1,13 @@
-_php_run_pref=/opt/lamp/php/php
-_external_parser=/opt/lamp/php/php -l -f {0}
-_mysql_run_pref=/opt/lampp/lampp startmysql
-_apache_run_pref=/opt/lampp/lampp
-_xampp_start_pref=/opt/lampp/lampp start
-_xampp_stop_pref=/opt/lampp/lampp stop
-__mysql_start=startmysql
-__apache_start=startapache -c \"DocumentRoot {0}\"
-__apache_stop=stop
-__apache_restart=restart
+_php_run_pref=/usr/bin/php
+_external_parser=/usr/bin/php -l -f {0}
+_mysql_run_pref=
+_apache_run_pref=/usr/sbin/httpd
+_xampp_start_pref=
+_xampp_stop_pref=
+__mysql_start=
+__apache_start=-f /usr/share/eclipse/dropins/phpeclipse/eclipse/plugins/net.sourceforge.phpeclipse.externaltools_1.2.3.200910091456PRD/conf/httpd.conf -c "ErrorLog {0}/.metadata/phpeclipse-httpd-error_log" -c "DocumentRoot {0}" -c "PidFile {0}/.metadata/phpeclipse-httpd.pid" -c "Listen {1}"
+__apache_stop=-f /usr/share/eclipse/dropins/phpeclipse/eclipse/plugins/net.sourceforge.phpeclipse.externaltools_1.2.3.200910091456PRD/conf/httpd.conf -c "ErrorLog {0}/.metadata/phpeclipse-httpd-error_log" -c "DocumentRoot {0}" -c "PidFile {0}/.metadata/phpeclipse-httpd.pid" -c "Listen {1}" -k stop
+__apache_restart=-f /usr/share/eclipse/dropins/phpeclipse/eclipse/plugins/net.sourceforge.phpeclipse.externaltools_1.2.3.200910091456PRD/conf/httpd.conf -c "ErrorLog {0}/.metadata/phpeclipse-httpd-error_log" -c "DocumentRoot {0}" -c "PidFile {0}/.metadata/phpeclipse-httpd.pid" -c "Listen {1}" -k restart
 _mysql_start_background=true
 _apache_start_background=true
 _apache_stop_background=true
Index: ./plugins/net.sourceforge.phpeclipse.externaltools/conf/httpd.conf
===================================================================
--- ./plugins/net.sourceforge.phpeclipse.externaltools/conf/httpd.conf	(revision 0)
+++ ./plugins/net.sourceforge.phpeclipse.externaltools/conf/httpd.conf	(revision 0)
@@ -0,0 +1,23 @@
+# minimal httpd conf file for use with PHPEclipse
+StartServers 1
+MinSpareServers 1
+MaxSpareServers 1
+MaxClients 3
+
+# modules
+LoadModule mime_module modules/mod_mime.so
+LoadModule dir_module modules/mod_dir.so
+LoadModule autoindex_module modules/mod_autoindex.so
+
+TypesConfig /etc/mime.types
+DirectoryIndex index.html index.php default.html default.php
+DirectorySlash On
+
+IndexOptions FoldersFirst VersionSort IgnoreCase NameWidth=* HTMLTable
+IndexIgnore RECYCLER .??* *~ *# HEADER* README* RCS CVS *,v *,t
+HeaderName HEADER.html
+ReadmeName README.html
+
+# PHP settings
+LoadModule php5_module modules/libphp5.so
+AddHandler php5-script .php
Index: ./plugins/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartApacheAction.java
===================================================================
--- ./plugins/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartApacheAction.java	(revision 1625)
+++ ./plugins/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStartApacheAction.java	(working copy)
@@ -32,7 +32,7 @@
 
 		// replace backslash with slash in the DocumentRoot under Windows
 		documentRoot = documentRoot.replace('\\', '/');
-		String[] arguments = { documentRoot };
+		String[] arguments = { documentRoot, new Integer(WebUI.getDefault().getHttpdPort()).toString() };
 		MessageFormat form = new MessageFormat(store
 				.getString(ExternalToolsPlugin.APACHE_START_PREF));
 		execute("apache_start", store
Index: ./plugins/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPRestartApacheAction.java
===================================================================
--- ./plugins/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPRestartApacheAction.java	(revision 1625)
+++ ./plugins/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPRestartApacheAction.java	(working copy)
@@ -11,20 +11,31 @@
  **********************************************************************/
 package net.sourceforge.phpdt.externaltools.actions;
 
+import java.text.MessageFormat;
+
 import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin;
+import net.sourceforge.phpeclipse.ui.WebUI;
 
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.preference.IPreferenceStore;
 
 public class PHPRestartApacheAction extends PHPStartApacheAction {
 	public void run(IAction action) {
+		final IPreferenceStore webUIStore = WebUI.getDefault()
+		.getPreferenceStore();
+
+		String documentRoot = webUIStore.getString(WebUI.PHP_DOCUMENTROOT_PREF);
 		final IPreferenceStore store = ExternalToolsPlugin.getDefault()
 				.getPreferenceStore();
-		// execute(store.getString(PHPeclipsePlugin.APACHE_RESTART_PREF),
-		// "Restart Apache: ");
+
+		// replace backslash with slash in the DocumentRoot under Windows
+		documentRoot = documentRoot.replace('\\', '/');
+		String[] arguments = { documentRoot, new Integer(WebUI.getDefault().getHttpdPort()).toString() };
+		MessageFormat form = new MessageFormat(store
+				.getString(ExternalToolsPlugin.APACHE_RESTART_PREF));
 		execute("apache_restart", store
-				.getString(ExternalToolsPlugin.APACHE_RUN_PREF), store
-				.getString(ExternalToolsPlugin.APACHE_RESTART_PREF), store
+				.getString(ExternalToolsPlugin.APACHE_RUN_PREF), form
+				.format(arguments), store
 				.getBoolean(ExternalToolsPlugin.APACHE_RESTART_BACKGROUND));
 	}
 }
Index: ./plugins/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStopApacheAction.java
===================================================================
--- ./plugins/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStopApacheAction.java	(revision 1625)
+++ ./plugins/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpdt/externaltools/actions/PHPStopApacheAction.java	(working copy)
@@ -11,20 +11,31 @@
  **********************************************************************/
 package net.sourceforge.phpdt.externaltools.actions;
 
+import java.text.MessageFormat;
+
 import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin;
+import net.sourceforge.phpeclipse.ui.WebUI;
 
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.preference.IPreferenceStore;
 
 public class PHPStopApacheAction extends PHPStartApacheAction {
 	public void run(IAction action) {
+		final IPreferenceStore webUIStore = WebUI.getDefault()
+		.getPreferenceStore();
+
+		String documentRoot = webUIStore.getString(WebUI.PHP_DOCUMENTROOT_PREF);
 		final IPreferenceStore store = ExternalToolsPlugin.getDefault()
 				.getPreferenceStore();
-		// execute(store.getString(PHPeclipsePlugin.APACHE_STOP_PREF), "Stop
-		// Apache: ");
+
+		// replace backslash with slash in the DocumentRoot under Windows
+		documentRoot = documentRoot.replace('\\', '/');
+		String[] arguments = { documentRoot, new Integer(WebUI.getDefault().getHttpdPort()).toString() };
+		MessageFormat form = new MessageFormat(store
+				.getString(ExternalToolsPlugin.APACHE_STOP_PREF));
 		execute("apache_stop", store
-				.getString(ExternalToolsPlugin.APACHE_RUN_PREF), store
-				.getString(ExternalToolsPlugin.APACHE_STOP_PREF), store
+				.getString(ExternalToolsPlugin.APACHE_RUN_PREF), form
+				.format(arguments), store
 				.getBoolean(ExternalToolsPlugin.APACHE_STOP_BACKGROUND));
 	}
 }
Index: ./plugins/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpeclipse/externaltools/ExternalToolsPlugin.java
===================================================================
--- ./plugins/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpeclipse/externaltools/ExternalToolsPlugin.java	(revision 1625)
+++ ./plugins/net.sourceforge.phpeclipse.externaltools/src/net/sourceforge/phpeclipse/externaltools/ExternalToolsPlugin.java	(working copy)
@@ -15,6 +15,7 @@
 import java.util.Enumeration;
 import java.util.PropertyResourceBundle;
 
+import net.sourceforge.phpdt.externaltools.actions.PHPStopApacheAction;
 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsImages;
 import net.sourceforge.phpdt.externaltools.internal.model.IPreferenceConstants;
 import net.sourceforge.phpdt.externaltools.internal.model.VariableContextManager;
@@ -28,6 +29,7 @@
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Platform;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.action.Action;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.preference.PreferenceConverter;
 import org.eclipse.jface.resource.ImageDescriptor;
@@ -310,4 +312,17 @@
 			}
 		});
 	}
+
+	/**
+	 * @throws Exception
+	 * @see org.eclipse.core.runtime.Plugin#stop(BundleContext context)
+	 */
+	public void stop(BundleContext context) throws Exception {
+		super.stop(context);
+	}
+
+	public void stopHttpd() {
+		// stop httpd 
+		new PHPStopApacheAction().run(new Action(){});
+	}
 }
\ No newline at end of file
Index: ./plugins/net.sourceforge.phpeclipse.externaltools/build.properties
===================================================================
--- ./plugins/net.sourceforge.phpeclipse.externaltools/build.properties	(revision 1625)
+++ ./plugins/net.sourceforge.phpeclipse.externaltools/build.properties	(working copy)
@@ -5,6 +5,7 @@
                icons/,\
                META-INF/,\
                plugin.properties,\
+               conf/,\
                prefs/
 src.includes = src/,\
                build.properties,\
@@ -15,4 +16,9 @@
                .cvsignore,\
                .project,\
                META-INF/,\
+               conf/,\
                prefs/
+bin.excludes = prefs/default_macosx.properties,\
+               prefs/default_win32.properties
+src.excludes = prefs/default_macosx.properties,\
+               prefs/default_win32.properties
Index: ./plugins/net.sourceforge.phpeclipse.externaltools/plugin.xml
===================================================================
--- ./plugins/net.sourceforge.phpeclipse.externaltools/plugin.xml	(revision 1643)
+++ ./plugins/net.sourceforge.phpeclipse.externaltools/plugin.xml	(working copy)
@@ -192,11 +192,6 @@
 	  </page>
 	  <page
 			category="net.sourceforge.phpdt.externaltools.preferences"
-			class="net.sourceforge.phpdt.externaltools.preferences.XamppPrefencePage"
-			id="net.sourceforge.phpeclipse.externaltools.xampp.preferences"
-			name="XAMPP"/>
-	  <page
-			category="net.sourceforge.phpdt.externaltools.preferences"
 			class="net.sourceforge.phpdt.externaltools.preferences.MySQLPreferencePage"
 			id="net.sourceforge.phpeclipse.externaltools.mysql.preferences"
 			name="MySQL"/>
@@ -213,10 +208,6 @@
 			targetID="net.sourceforge.phpeclipse.PHPPerspective">
 		 <actionSet id="net.sourceforge.phpeclipse.PHPActionSet"/>
 	  </perspectiveExtension>
-	  <perspectiveExtension
-		   targetID="net.sourceforge.phpeclipse.PHPPerspective">
-			  <actionSet id="net.sf.eclipsetidy.ActionSet"/>
-		  </perspectiveExtension>
    </extension>
 
    <extension
@@ -268,24 +259,6 @@
 			   toolbarPath="Normal"
 			   id="net.sourceforge.phpdt.externaltools.actions.PHPStartMySQLAction">
 		 </action>
-		 <action
-			   label="Stop XAMPP"
-			   icon="icons/obj16/xampp_stop.gif"
-			   tooltip="Stop XAMPP"
-			   class="net.sourceforge.phpdt.externaltools.actions.PHPStopXAMPPAction"
-			   menubarPath="net.sourceforge.phpeclipse.PHPMenu/phpeclipse"
-			   toolbarPath="Normal"
-			   id="net.sourceforge.phpdt.externaltools.actions.PHPStopXAMPPAction">
-		 </action>
-		 <action
-			   label="Start XAMPP"
-			   icon="icons/obj16/xampp_start.gif"
-			   tooltip="Start XAMPP"
-			   class="net.sourceforge.phpdt.externaltools.actions.PHPStartXAMPPAction"
-			   menubarPath="net.sourceforge.phpeclipse.PHPMenu/phpeclipse"
-			   toolbarPath="Normal"
-			   id="net.sourceforge.phpdt.externaltools.actions.PHPStartXAMPPAction">
-		 </action>
 	  </actionSet>
 	</extension>