aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwgalanciak2013-11-07 05:20:49 (EST)
committerGerrit Code Review @ Eclipse.org2013-11-12 12:47:25 (EST)
commit034edb0e4d6730afa62660ea15a48931679f0f12 (patch)
tree2358c6ea9264ff43d91ff2f1de0a086b8d9fdbe0
parent94b33cc94525675aecdea8e1749ea9c60f0fc15c (diff)
downloadorg.eclipse.pdt-034edb0e4d6730afa62660ea15a48931679f0f12.zip
org.eclipse.pdt-034edb0e4d6730afa62660ea15a48931679f0f12.tar.gz
org.eclipse.pdt-034edb0e4d6730afa62660ea15a48931679f0f12.tar.bz2
Bug 397180 - Check if debugger (xdebug) can be bound to specified portrefs/changes/66/18166/2
Add validation of a port availability in XDebug Configuration dialog. Show error message dialog if port is not available when debugging. Change-Id: Ie0ec6a61ab3a536b3970c1fe9289071bf064cc2a Signed-off-by: wgalanciak <wojciech.galanciak@gmail.com>
-rw-r--r--plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/PHPDebugCoreMessages.java2
-rw-r--r--plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/PHPDebugCoreMessages.properties4
-rw-r--r--plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/launching/PHPLaunchUtilities.java31
-rw-r--r--plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/launching/XDebugWebLaunchConfigurationDelegate.java13
-rw-r--r--plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/xdebug/dbgp/XDebugConfigurationDialog.java15
5 files changed, 58 insertions, 7 deletions
diff --git a/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/PHPDebugCoreMessages.java b/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/PHPDebugCoreMessages.java
index 919b90b..e5ce0e5 100644
--- a/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/PHPDebugCoreMessages.java
+++ b/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/PHPDebugCoreMessages.java
@@ -110,6 +110,7 @@ public class PHPDebugCoreMessages extends NLS {
public static String XDebugConfigurationDialog_remoteSessionOption_localhost;
public static String XDebugConfigurationDialog_remoteSessionOption_any;
public static String XDebugConfigurationDialog_remoteSessionOption_prompt;
+ public static String XDebugConfigurationDialog_PortInUse;
// capture output
public static String XDebugConfigurationDialog_captureStdout;
@@ -152,6 +153,7 @@ public class PHPDebugCoreMessages extends NLS {
public static String XDebug_WebLaunchConfigurationDelegate_2;
public static String XDebug_WebLaunchConfigurationDelegate_3;
public static String XDebug_WebLaunchConfigurationDelegate_4;
+ public static String XDebug_WebLaunchConfigurationDelegate_PortInUse;
public static String XDebug_DBGpTarget_0;
public static String XDebug_DBGpTarget_1;
diff --git a/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/PHPDebugCoreMessages.properties b/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/PHPDebugCoreMessages.properties
index 4a0ce33..9e29fba 100644
--- a/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/PHPDebugCoreMessages.properties
+++ b/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/PHPDebugCoreMessages.properties
@@ -85,6 +85,7 @@ XDebugConfigurationDialog_useProxy=Use Proxy
XDebugConfigurationDialog_idekey=IDE Key
XDebugConfigurationDialog_MaxData=Max data
XDebugConfigurationDialog_proxy=Proxy Address (host:port)
+XDebugConfigurationDialog_PortInUse=Port Number is already in use. Please select a different port.
XDebugMessage_debugError=Debugger Error
XDebugMessage_unexpectedTermination=Unexpected termination of script, debugging ended.
XDebugMessage_remoteSessionTitle=Remote session
@@ -103,6 +104,7 @@ XDebug_WebLaunchConfigurationDelegate_1=Could not launch.\nInvalid server config
XDebug_WebLaunchConfigurationDelegate_2=Unable to connect to proxy\n
XDebug_WebLaunchConfigurationDelegate_3=Launching browser
XDebug_WebLaunchConfigurationDelegate_4=waiting for XDebug session
+XDebug_WebLaunchConfigurationDelegate_PortInUse=The debug port {0} is in use. Please select a different port for XDebug (open Preferences -> PHP -> Debug -> Installed Debuggers -> Configure XDebug).
XDebug_DBGpTarget_0=No appropriate file located or no file selected. Debug Terminated
XDebug_DBGpTarget_1=Remote Launch
XDebug_DBGpTarget_2=Unknown PHP Program
@@ -114,4 +116,4 @@ XDebug_DBGpThread_0=PHP Thread
XDebug_DBGpVariable_0=setValue called, but verifyValue failed
XDebug_DBGpVariable_1=program under debug rejected value change
XDebug_IDBGpModelConstants_0=<Invalid>
-XDebug_IDBGpModelConstants_1=<Uninitialized> \ No newline at end of file
+XDebug_IDBGpModelConstants_1=<Uninitialized>
diff --git a/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/launching/PHPLaunchUtilities.java b/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/launching/PHPLaunchUtilities.java
index 813ae54..7008761 100644
--- a/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/launching/PHPLaunchUtilities.java
+++ b/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/launching/PHPLaunchUtilities.java
@@ -13,10 +13,9 @@
package org.eclipse.php.internal.debug.core.launching;
import java.io.File;
+import java.io.IOException;
import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLEncoder;
+import java.net.*;
import java.util.*;
import org.eclipse.core.resources.IProject;
@@ -1191,4 +1190,30 @@ public class PHPLaunchUtilities {
.node(IPHPDebugConstants.SSH_TUNNEL_SECURE_PREF_NODE + hostPath);
return node;
}
+
+ public static boolean isPortAvailable(int port) {
+ ServerSocket ss = null;
+ DatagramSocket ds = null;
+ try {
+ ss = new ServerSocket(port);
+ ss.setReuseAddress(true);
+ ds = new DatagramSocket(port);
+ ds.setReuseAddress(true);
+ return true;
+ } catch (IOException e) {
+ } finally {
+ if (ds != null) {
+ ds.close();
+ }
+ if (ss != null) {
+ try {
+ ss.close();
+ } catch (IOException e) {
+ /* should not be thrown */
+ }
+ }
+ }
+ return false;
+ }
+
}
diff --git a/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/launching/XDebugWebLaunchConfigurationDelegate.java b/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/launching/XDebugWebLaunchConfigurationDelegate.java
index ea05b61..ca7b1c3 100644
--- a/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/launching/XDebugWebLaunchConfigurationDelegate.java
+++ b/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/launching/XDebugWebLaunchConfigurationDelegate.java
@@ -19,10 +19,12 @@ import org.eclipse.core.runtime.*;
import org.eclipse.debug.core.*;
import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.php.debug.core.debugger.parameters.IDebugParametersKeys;
import org.eclipse.php.internal.debug.core.IPHPDebugConstants;
import org.eclipse.php.internal.debug.core.Logger;
import org.eclipse.php.internal.debug.core.PHPDebugCoreMessages;
+import org.eclipse.php.internal.debug.core.PHPDebugPlugin;
import org.eclipse.php.internal.debug.core.pathmapper.PathMapperRegistry;
import org.eclipse.php.internal.debug.core.preferences.PHPProjectPreferences;
import org.eclipse.php.internal.debug.core.xdebug.IDELayerFactory;
@@ -53,8 +55,15 @@ public class XDebugWebLaunchConfigurationDelegate extends
public void launch(ILaunchConfiguration configuration, String mode,
ILaunch launch, IProgressMonitor monitor) throws CoreException {
- if (!DaemonPlugin.getDefault().validateCommunicationDaemons(
- XDebugCommunicationDaemon.XDEBUG_DEBUGGER_ID)) {
+ String debuggerId = XDebugCommunicationDaemon.XDEBUG_DEBUGGER_ID;
+ if (!DaemonPlugin.getDefault().validateCommunicationDaemons(debuggerId)) {
+ int port = PHPDebugPlugin.getDebugPort(debuggerId);
+ if (!PHPLaunchUtilities.isPortAvailable(port)) {
+ PHPLaunchUtilities
+ .showLaunchErrorMessage(NLS
+ .bind(PHPDebugCoreMessages.XDebug_WebLaunchConfigurationDelegate_PortInUse,
+ port));
+ }
monitor.setCanceled(true);
monitor.done();
DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
diff --git a/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/xdebug/dbgp/XDebugConfigurationDialog.java b/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/xdebug/dbgp/XDebugConfigurationDialog.java
index 9d65889..aa150be 100644
--- a/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/xdebug/dbgp/XDebugConfigurationDialog.java
+++ b/plugins/org.eclipse.php.debug.core/src/org/eclipse/php/internal/debug/core/xdebug/dbgp/XDebugConfigurationDialog.java
@@ -11,12 +11,18 @@
*******************************************************************************/
package org.eclipse.php.internal.debug.core.xdebug.dbgp;
+import java.io.IOException;
+import java.net.DatagramSocket;
+import java.net.ServerSocket;
+
import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.php.internal.debug.core.PHPDebugCoreMessages;
import org.eclipse.php.internal.debug.core.PHPDebugPlugin;
+import org.eclipse.php.internal.debug.core.launching.PHPLaunchUtilities;
import org.eclipse.php.internal.debug.core.preferences.AbstractDebuggerConfigurationDialog;
import org.eclipse.php.internal.debug.core.xdebug.XDebugPreferenceMgr;
+import org.eclipse.php.internal.debug.core.xdebug.communication.XDebugCommunicationDaemon;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
@@ -410,11 +416,18 @@ public class XDebugConfigurationDialog extends
Integer iValue = new Integer(value);
int i = iValue.intValue();
if (!timeoutField) {
-
if (i <= 0 || i > 65535) {
valid = false;
errorMessage = PHPDebugCoreMessages.XDebugConfigurationDialog_invalidPortRange;
}
+ if (valid) {
+ if (iValue != PHPDebugPlugin
+ .getDebugPort(XDebugCommunicationDaemon.XDEBUG_DEBUGGER_ID)
+ && !PHPLaunchUtilities.isPortAvailable(iValue)) {
+ valid = false;
+ errorMessage = PHPDebugCoreMessages.XDebugConfigurationDialog_PortInUse;
+ }
+ }
} else {
if (i < 10 || i > 100000) {
valid = false;