Author: [email protected]
Date: Fri Mar 27 08:09:11 2009
New Revision: 5095
Modified:
trunk/dev/core/src/com/google/gwt/dev/GWTShell.java
trunk/dev/core/src/com/google/gwt/dev/shell/GWTShellServlet.java
trunk/dev/core/src/com/google/gwt/dev/shell/tomcat/EmbeddedTomcatServer.java
Log:
The rest of the implementation of -noserver hosted
mode test. r5094 was incomplete.
Review by: jat
Modified: trunk/dev/core/src/com/google/gwt/dev/GWTShell.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/dev/GWTShell.java (original)
+++ trunk/dev/core/src/com/google/gwt/dev/GWTShell.java Fri Mar 27 08:09:11
2009
@@ -234,7 +234,7 @@
protected int doStartUpServer() {
// TODO(bruce): make tomcat work in terms of the modular launcher
String whyFailed = EmbeddedTomcatServer.start(getTopLogger(),
getPort(),
- options);
+ options, shouldAutoGenerateResources());
// TODO(bruce): test that we can remove this old approach in favor of
// a better, logger-based error reporting
@@ -259,5 +259,15 @@
* magic?
*/
return false;
+ }
+
+ /**
+ * Whether this shell should auto-generate GWT resources when it
recognizes
+ * requests for them. By default this is true. Subclasses can disable
such
+ * auto-generation and make this servlet appear to be like any arbitrary
web
+ * server that knows nothing about GWT.
+ */
+ protected boolean shouldAutoGenerateResources() {
+ return true;
}
}
Modified: trunk/dev/core/src/com/google/gwt/dev/shell/GWTShellServlet.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/dev/shell/GWTShellServlet.java
(original)
+++ trunk/dev/core/src/com/google/gwt/dev/shell/GWTShellServlet.java Fri
Mar 27 08:09:11 2009
@@ -116,12 +116,12 @@
private int nextRequestId;
- private WorkDirs workDirs;
-
private final Object requestIdLock = new Object();
private TreeLogger topLogger;
+ private WorkDirs workDirs;
+
public GWTShellServlet() {
initMimeTypes();
}
@@ -409,9 +409,11 @@
logger = logger.branch(TreeLogger.TRACE, msg, null);
// Handle auto-generation of resources.
- if (autoGenerateResources(request, response, logger, partialPath,
- moduleName)) {
- return;
+ if (shouldAutoGenerateResources()) {
+ if (autoGenerateResources(request, response, logger, partialPath,
+ moduleName)) {
+ return;
+ }
}
URL foundResource = null;
@@ -419,20 +421,22 @@
// Look for the requested file on the public path.
//
ModuleDef moduleDef = getModuleDef(logger, moduleName);
- Resource publicResource = moduleDef.findPublicFile(partialPath);
- if (publicResource != null) {
- foundResource = publicResource.getURL();
- }
+ if (shouldAutoGenerateResources()) {
+ Resource publicResource = moduleDef.findPublicFile(partialPath);
+ if (publicResource != null) {
+ foundResource = publicResource.getURL();
+ }
- if (foundResource == null) {
- // Look for public generated files
- File shellDir = getShellWorkDirs().getShellPublicGenDir(moduleDef);
- File requestedFile = new File(shellDir, partialPath);
- if (requestedFile.exists()) {
- try {
- foundResource = requestedFile.toURI().toURL();
- } catch (MalformedURLException e) {
- // ignore since it was speculative anyway
+ if (foundResource == null) {
+ // Look for public generated files
+ File shellDir =
getShellWorkDirs().getShellPublicGenDir(moduleDef);
+ File requestedFile = new File(shellDir, partialPath);
+ if (requestedFile.exists()) {
+ try {
+ foundResource = requestedFile.toURI().toURL();
+ } catch (MalformedURLException e) {
+ // ignore since it was speculative anyway
+ }
}
}
}
@@ -884,6 +888,16 @@
HttpHeaders.CACHE_CONTROL_MAXAGE + cacheTime);
String expiresString = HttpHeaders.toInternetDateFormat(expires);
response.setHeader(HttpHeaders.EXPIRES, expiresString);
+ }
+
+ private boolean shouldAutoGenerateResources() {
+ ServletContext servletContext = getServletContext();
+ final String attr
= "com.google.gwt.dev.shell.shouldAutoGenerateResources";
+ Boolean attrValue = (Boolean) servletContext.getAttribute(attr);
+ if (attrValue == null) {
+ return true;
+ }
+ return attrValue;
}
private void streamOut(InputStream in, OutputStream out, int bufferSize)
Modified:
trunk/dev/core/src/com/google/gwt/dev/shell/tomcat/EmbeddedTomcatServer.java
==============================================================================
---
trunk/dev/core/src/com/google/gwt/dev/shell/tomcat/EmbeddedTomcatServer.java
(original)
+++
trunk/dev/core/src/com/google/gwt/dev/shell/tomcat/EmbeddedTomcatServer.java
Fri Mar 27 08:09:11 2009
@@ -60,14 +60,19 @@
return sTomcat.port;
}
+ public static String start(TreeLogger topLogger, int port, WorkDirs
workDirs) {
+ return start(topLogger, port, workDirs, true);
+ }
+
public static synchronized String start(TreeLogger topLogger, int port,
- WorkDirs workDirs) {
+ WorkDirs workDirs, boolean shouldAutoGenerateResources) {
if (sTomcat != null) {
throw new IllegalStateException("Embedded Tomcat is already
running");
}
try {
- new EmbeddedTomcatServer(topLogger, port, workDirs);
+ new EmbeddedTomcatServer(topLogger, port, workDirs,
+ shouldAutoGenerateResources);
return null;
} catch (LifecycleException e) {
String msg = e.getMessage();
@@ -146,7 +151,8 @@
private final TreeLogger startupBranchLogger;
private EmbeddedTomcatServer(final TreeLogger topLogger, int
listeningPort,
- final WorkDirs workDirs) throws LifecycleException {
+ final WorkDirs workDirs, final boolean shouldAutoGenerateResources)
+ throws LifecycleException {
if (topLogger == null) {
throw new NullPointerException("No logger specified");
}
@@ -233,6 +239,8 @@
StandardContext webapp = (StandardContext) event.getData();
publishShellLoggerAttribute(logger, topLogger, webapp);
publishShellWorkDirsAttribute(logger, workDirs, webapp);
+ publishShouldAutoGenerateResourcesAttribute(logger,
+ shouldAutoGenerateResources, webapp);
}
}
});
@@ -428,5 +436,15 @@
WorkDirs workDirs, StandardContext webapp) {
final String attr = "com.google.gwt.dev.shell.workdirs";
publishAttributeToWebApp(logger, webapp, attr, workDirs);
+ }
+
+ /**
+ * Publish to the web app whether it should automatically generate
resources.
+ */
+ private void publishShouldAutoGenerateResourcesAttribute(TreeLogger
logger,
+ boolean shouldAutoGenerateResources, StandardContext webapp) {
+ publishAttributeToWebApp(logger, webapp,
+ "com.google.gwt.dev.shell.shouldAutoGenerateResources",
+ shouldAutoGenerateResources);
}
}
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---