Skip to content

Instantly share code, notes, and snippets.

@confile
Last active February 5, 2016 10:01
Show Gist options
  • Save confile/44d17779b890e2ca7e89 to your computer and use it in GitHub Desktop.
Save confile/44d17779b890e2ca7e89 to your computer and use it in GitHub Desktop.
GwtSuperDevModeLoggingServlet for Putnami GWT Gradle Plugin
package remoteLogging;
import java.io.File;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import com.google.gwt.logging.server.RemoteLoggingServiceImpl;
import com.google.gwt.user.client.rpc.SerializationException;
/**
* See: https://code.google.com/archive/p/google-web-toolkit/issues/7693 See:
* https://github.com/gwtproject/gwt/issues/7690
*
*/
public class GwtSuperDevModeLoggingServlet extends RemoteLoggingServiceImpl {
// Change constants below, based on your GWT SuperDevMode build messages, like below:
// Compiling module com.ajaxdatabase.ajaxwind.Main
// Compiling 1 permutation
// Compiling permutation 0...
// Source Maps Enabled
// Compile of permutations succeeded
// Linking into
// C:\Users\Administrator\AppData\Local\Temp\gwt-codeserver-9190081658547331755.tmp\com.ajaxdatabase.ajaxwind.Main\compile-2\war\com.ajaxdatabase.ajaxwind.Main;
// Writing extras to
// C:\Users\ADMINI~1\AppData\Local\Temp\gwt-codeserver-9190081658547331755.tmp\com.ajaxdatabase.ajaxwind.Main\compile-2\extras\com.ajaxdatabase.ajaxwind.Main
// Link succeeded
// Compilation succeeded -- 12.644s
// Compile completed in 12845 ms
// private final String TEMP_DIR = "C:\\Users\\Administrator\\AppData\\Local\\Temp\\";
// private final String MODULE_NAME = "com.ajaxdatabase.ajaxwind.Main";
private final String TEMP_DIR = "/Users/mg/Documents/Grails/GWT/test-gwt/build/putnami/work/";
private final String MODULE_NAME = "test.dashboard.Dashboard";
private String path = null;
private final String symbolMapsPath = "/extras/test_dashboard/symbolMaps/";
private final String productionFolder = "/WEB-INF/dashboard/symbolMaps";
private static Logger logger = Logger.getLogger(GwtSuperDevModeLoggingServlet.class.getName());
@Override
public void init() throws ServletException {
super.init();
logger.info("GwtSuperDevModeLoggingServlet - init()");
}
@Override
public String processCall(String payload) throws SerializationException {
reconfigureMapsDir();
logger.info("GwtSuperDevModeLoggingServlet - processCall(): path: " + path);
logger.info("GwtSuperDevModeLoggingServlet - processCall(): payload: " + payload);
return super.processCall(payload);
}
private void reconfigureMapsDir() {
File last = null;
File lastcompile = null;
logger.info("GwtSuperDevModeLoggingServlet - reconfigureMapsDir(): " + new File(TEMP_DIR));
// find the MODULE_NAME directory
for (File f : new File(TEMP_DIR).listFiles()) {
if (f.getName().startsWith(MODULE_NAME) && (last == null || f.lastModified() > last.lastModified())) {
last = f;
break;
}
}
logger.info("GwtSuperDevModeLoggingServlet - reconfigureMapsDir() last: " + last);
// if (last != null) {
// for (File f : new File(last.getPath(), MODULE_NAME).listFiles()) {
// logger.info("GwtSuperDevModeLoggingServlet - reconfigureMapsDir() f2: " + f);
// if (f.getName().startsWith("compile-")
// && (lastcompile == null || f.lastModified() > lastcompile.lastModified())) {
// lastcompile = f;
// }
// }
// }
if (last != null) {
// for SuperDevMode
// find the last compile version
for (File f : new File(last.getPath()).listFiles()) {
logger.info("GwtSuperDevModeLoggingServlet - reconfigureMapsDir() f2: " + f);
if (f.getName().startsWith("compile-") && (lastcompile == null || f.lastModified() > lastcompile.lastModified())) {
lastcompile = f;
}
}
// find the last SuperDevMode compile folder which has SymbolMaps
String lastCompileVersionString = lastcompile.getName().replaceFirst("compile-", "");
int lastCompileVersion = 0;
lastCompileVersion = Integer.parseInt(lastCompileVersionString);
logger.info("GwtSuperDevModeLoggingServlet - lastCompileVersion: "+lastCompileVersion);
String lastPath = lastcompile.getPath().replaceFirst("compile-.*", "compile-");
for(int i=lastCompileVersion; i >= 0; i--) {
File f = new File(lastPath + i + symbolMapsPath);
logger.info("GwtSuperDevModeLoggingServlet - reconfigureMapsDir() find last:: "+f);
if (f.exists()) {
logger.info("GwtSuperDevModeLoggingServlet - reconfigureMapsDir() find last SymbolMaps: "+f);
lastcompile = f;
break;
}
}
}
else {
// use a default directory on the server for production
logger.info("GwtSuperDevModeLoggingServlet - reconfigureMapsDir(): use SymbolMaps in "+productionFolder);
setSymbolMapsDirectory(getServletContext().getRealPath(productionFolder));
}
logger.info("GwtSuperDevModeLoggingServlet - reconfigureMapsDir() lastcompile: " + lastcompile);
logger.info("done! \n\n");
if (lastcompile != null) {
String dirpath = lastcompile.getPath();
logger.info("GwtSuperDevModeLoggingServlet - reconfigureMapsDir() dirpath: " + dirpath);
if (!dirpath.equals(path)) {
path = dirpath;
logger.info("GwtSuperDevModeLoggingServlet - reconfigureMapsDir() setSymbolMapsDirectory: " + path);
setSymbolMapsDirectory(path);
}
else {
logger.info("GwtSuperDevModeLoggingServlet - did not change SymbolMaps path nothing changed!");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment