Refactor SCLs to live in the core.ext package.

Review by: jgw (TBR)

git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/1.6@4353 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/shell/ServletContainer.java b/dev/core/src/com/google/gwt/core/ext/ServletContainer.java
similarity index 67%
rename from dev/core/src/com/google/gwt/dev/shell/ServletContainer.java
rename to dev/core/src/com/google/gwt/core/ext/ServletContainer.java
index 732998a..acd2a25 100644
--- a/dev/core/src/com/google/gwt/dev/shell/ServletContainer.java
+++ b/dev/core/src/com/google/gwt/core/ext/ServletContainer.java
@@ -13,23 +13,28 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.google.gwt.dev.shell;
-
-import com.google.gwt.core.ext.UnableToCompleteException;
+package com.google.gwt.core.ext;
 
 /**
  * An instance of a servlet container that can be used by the shell. It is
- * assumed that this servlet container serves a web app from the root directory
- * specified by a call to
- * {@link ServletContainerLauncher#setAppRootDir(java.io.File)}.
+ * assumed that this servlet container serves a web app from the directory
+ * specified when this servlet container was created.
  */
-public interface ServletContainer {
+public abstract class ServletContainer {
 
   /**
-   * Provides the port on which the server is actually running, which can be
-   * useful when automatic port selection was requested.
+   * Returns the host on which the servlet container is running. Defaults to
+   * "localhost". Used to construct a URL to reach the servlet container.
    */
-  int getPort();
+  public String getHost() {
+    return "localhost";
+  }
+
+  /**
+   * Returns the port on which the server is running.Used to construct a URL to
+   * reach the servlet container.
+   */
+  public abstract int getPort();
 
   /**
    * Causes the web app to pick up changes made within the app root dir while
@@ -42,12 +47,12 @@
    * 
    * @throws UnableToCompleteException
    */
-  void refresh() throws UnableToCompleteException;
+  public abstract void refresh() throws UnableToCompleteException;
 
   /**
    * Stops the running servlet container. It cannot be restarted after this.
    * 
    * @throws UnableToCompleteException
    */
-  void stop() throws UnableToCompleteException;
+  public abstract void stop() throws UnableToCompleteException;
 }
diff --git a/dev/core/src/com/google/gwt/dev/shell/ServletContainerLauncher.java b/dev/core/src/com/google/gwt/core/ext/ServletContainerLauncher.java
similarity index 68%
rename from dev/core/src/com/google/gwt/dev/shell/ServletContainerLauncher.java
rename to dev/core/src/com/google/gwt/core/ext/ServletContainerLauncher.java
index ffec980..0785fb1 100644
--- a/dev/core/src/com/google/gwt/dev/shell/ServletContainerLauncher.java
+++ b/dev/core/src/com/google/gwt/core/ext/ServletContainerLauncher.java
@@ -13,29 +13,28 @@
  * License for the specific language governing permissions and limitations under
  * the License.
  */
-package com.google.gwt.dev.shell;
-
-import com.google.gwt.core.ext.TreeLogger;
+package com.google.gwt.core.ext;
 
 import java.io.File;
 import java.net.BindException;
 
 /**
  * Defines the service provider interface for launching servlet containers that
- * can be used by the shell.
+ * can be used by the GWT hosted mode.
  */
-public interface ServletContainerLauncher {
+public abstract class ServletContainerLauncher {
 
   /**
-   * Start an embedded HTTP server.
+   * Start an embedded HTTP servlet container.
    * 
    * @param logger the server logger
-   * @param port the TCP port to serve on
+   * @param port the TCP port to serve on; if 0 is requested, a port should be
+   *          automatically selected
    * @param appRootDir the base WAR directory
-   * @return the launch servlet contained
+   * @return the launched servlet container
    * @throws BindException if the requested port is already in use
    * @throws Exception if the server fails to start for any other reason
    */
-  ServletContainer start(TreeLogger logger, int port, File appRootDir)
-      throws BindException, Exception;
+  public abstract ServletContainer start(TreeLogger logger, int port,
+      File appRootDir) throws BindException, Exception;
 }
diff --git a/dev/core/src/com/google/gwt/dev/HostedMode.java b/dev/core/src/com/google/gwt/dev/HostedMode.java
index ac4a599..cebda22 100644
--- a/dev/core/src/com/google/gwt/dev/HostedMode.java
+++ b/dev/core/src/com/google/gwt/dev/HostedMode.java
@@ -15,6 +15,8 @@
  */
 package com.google.gwt.dev;
 
+import com.google.gwt.core.ext.ServletContainer;
+import com.google.gwt.core.ext.ServletContainerLauncher;
 import com.google.gwt.core.ext.TreeLogger;
 import com.google.gwt.core.ext.UnableToCompleteException;
 import com.google.gwt.core.ext.linker.ArtifactSet;
@@ -22,8 +24,6 @@
 import com.google.gwt.dev.Compiler.CompilerOptionsImpl;
 import com.google.gwt.dev.cfg.ModuleDef;
 import com.google.gwt.dev.shell.ArtifactAcceptor;
-import com.google.gwt.dev.shell.ServletContainer;
-import com.google.gwt.dev.shell.ServletContainerLauncher;
 import com.google.gwt.dev.shell.jetty.JettyLauncher;
 import com.google.gwt.dev.util.Util;
 import com.google.gwt.dev.util.arg.ArgHandlerExtraDir;
@@ -376,6 +376,14 @@
   }
 
   @Override
+  protected String getHost() {
+    if (server != null) {
+      return server.getHost();
+    }
+    return super.getHost();
+  }
+
+  @Override
   protected boolean initModule(String moduleName) {
     ModuleDef module = modulesByName.get(moduleName);
     if (module == null) {
diff --git a/dev/core/src/com/google/gwt/dev/HostedModeBase.java b/dev/core/src/com/google/gwt/dev/HostedModeBase.java
index 331297a..58bfe76 100644
--- a/dev/core/src/com/google/gwt/dev/HostedModeBase.java
+++ b/dev/core/src/com/google/gwt/dev/HostedModeBase.java
@@ -445,19 +445,19 @@
     }
 
     // Assume it's a trailing url path.
-    //
     if (unknownUrlText.length() > 0 && unknownUrlText.charAt(0) == '/') {
       unknownUrlText = unknownUrlText.substring(1);
     }
 
-    int prt = getPort();
-    if (prt != 80 && prt != 0) {
+    int port = getPort();
+    String host = getHost();
+    if (port != 80) {
       // CHECKSTYLE_OFF: Not really an assembled error message, so no space
       // after ':'.
-      return "http://localhost:" + prt + "/" + unknownUrlText;
+      return "http://" + host + ":" + port + "/" + unknownUrlText;
       // CHECKSTYLE_ON
     } else {
-      return "http://localhost/" + unknownUrlText;
+      return "http://" + host + "/" + unknownUrlText;
     }
   }
 
@@ -592,6 +592,10 @@
     return browserHost;
   }
 
+  protected String getHost() {
+    return "localhost";
+  }
+
   protected void initializeLogger() {
     final AbstractTreeLogger logger = mainWnd.getLogger();
     logger.setMaxDetail(options.getLogLevel());
diff --git a/dev/core/src/com/google/gwt/dev/shell/jetty/JettyLauncher.java b/dev/core/src/com/google/gwt/dev/shell/jetty/JettyLauncher.java
index d88f483..58ed521 100644
--- a/dev/core/src/com/google/gwt/dev/shell/jetty/JettyLauncher.java
+++ b/dev/core/src/com/google/gwt/dev/shell/jetty/JettyLauncher.java
@@ -15,11 +15,11 @@
  */
 package com.google.gwt.dev.shell.jetty;
 
+import com.google.gwt.core.ext.ServletContainer;
+import com.google.gwt.core.ext.ServletContainerLauncher;
 import com.google.gwt.core.ext.TreeLogger;
 import com.google.gwt.core.ext.UnableToCompleteException;
 import com.google.gwt.core.ext.TreeLogger.Type;
-import com.google.gwt.dev.shell.ServletContainer;
-import com.google.gwt.dev.shell.ServletContainerLauncher;
 
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.nio.SelectChannelConnector;
@@ -32,7 +32,7 @@
 /**
  * A launcher for an embedded Jetty server.
  */
-public class JettyLauncher implements ServletContainerLauncher {
+public class JettyLauncher extends ServletContainerLauncher {
 
   /**
    * An adapter for the Jetty logging system to GWT's TreeLogger. This
@@ -132,7 +132,7 @@
     }
   }
 
-  private static class JettyServletContainer implements ServletContainer {
+  private static class JettyServletContainer extends ServletContainer {
 
     private final int actualPort;
     private final File appRootDir;
diff --git a/dev/core/test/com/google/gwt/dev/HostedModeTest.java b/dev/core/test/com/google/gwt/dev/HostedModeTest.java
index 0258737..015e943 100644
--- a/dev/core/test/com/google/gwt/dev/HostedModeTest.java
+++ b/dev/core/test/com/google/gwt/dev/HostedModeTest.java
@@ -1,11 +1,11 @@
 package com.google.gwt.dev;
 
+import com.google.gwt.core.ext.ServletContainer;
+import com.google.gwt.core.ext.ServletContainerLauncher;
 import com.google.gwt.core.ext.TreeLogger;
 import com.google.gwt.dev.HostedMode.HostedModeOptionsImpl;
 import com.google.gwt.dev.jjs.JsOutputOption;
 import com.google.gwt.dev.shell.BrowserWidgetHostChecker;
-import com.google.gwt.dev.shell.ServletContainer;
-import com.google.gwt.dev.shell.ServletContainerLauncher;
 
 import java.io.File;
 import java.net.BindException;
@@ -15,7 +15,7 @@
  */
 public class HostedModeTest extends ArgProcessorTestBase {
 
-  public static class MySCL implements ServletContainerLauncher {
+  public static class MySCL extends ServletContainerLauncher {
     public ServletContainer start(TreeLogger logger, int port, File appRootDir)
         throws BindException, Exception {
       throw new UnsupportedOperationException();