Fix -bindAddress handling in JUnitShell. To preserve existing
behavior without rearchitecting JUnitShell and the RunStyles,
we disallow -bindAddress in JUnitShell and pretend it was always
as if -bindAddress 0.0.0.0 was given.
Patch by: jat
Review by: jlabanca
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@7454 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/junit/JUnitShell.java b/user/src/com/google/gwt/junit/JUnitShell.java
index 1418dca..229c076 100644
--- a/user/src/com/google/gwt/junit/JUnitShell.java
+++ b/user/src/com/google/gwt/junit/JUnitShell.java
@@ -56,6 +56,8 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
@@ -138,6 +140,27 @@
}
});
+ // Disable -bindAddress, fail if it is given
+ // TODO(jat): support -bindAddress in JUnitShell, which will probably
+ // require changes to the RunStyle API.
+ registerHandler(new ArgHandlerBindAddress(options) {
+ @Override
+ public String[] getDefaultArgs() {
+ return null;
+ }
+
+ @Override
+ public boolean isUndocumented() {
+ return true;
+ }
+
+ @Override
+ public boolean setString(String value) {
+ System.err.println("-bindAddress is not supported for JUnitShell");
+ return false;
+ }
+ });
+
// Override log level to set WARN by default..
registerHandler(new ArgHandlerLogLevel(options) {
@Override
@@ -623,6 +646,17 @@
if (!argProcessor.processArgs(args)) {
throw new JUnitFatalLaunchException("Error processing shell arguments");
}
+ // Always bind to the wildcard address and substitute the host address in
+ // URLs. Note that connectAddress isn't actually used here, as we
+ // override it from the runsStyle in getModuleUrl, but we set it to match
+ // what will actually be used anyway to avoid confusion.
+ unitTestShell.options.setBindAddress("0.0.0.0");
+ try {
+ unitTestShell.options.setConnectAddress(
+ InetAddress.getLocalHost().getHostAddress());
+ } catch (UnknownHostException e) {
+ throw new JUnitFatalLaunchException("Unable to resolve my address");
+ }
if (!unitTestShell.startUp()) {
throw new JUnitFatalLaunchException("Shell failed to start");
}
@@ -763,6 +797,7 @@
}
public String getModuleUrl(String moduleName) {
+ // TODO(jat): consider using DevModeBase.processUrl instead
String localhost = runStyle.getLocalHostName();
String url = "http://" + localhost + ":" + getPort() + "/" + moduleName
+ (standardsMode ? "/junit-standards.html" : "/junit.html");