Author: j...@google.com Date: Fri Feb 6 14:54:00 2009 New Revision: 4664 Modified: trunk/dev/oophm/overlay/com/google/gwt/dev/GWTShell.java trunk/dev/oophm/overlay/com/google/gwt/dev/shell/PlatformSpecific.java trunk/dev/oophm/overlay/com/google/gwt/dev/shell/ShellMainWindow.java
Log: Fixes OOPHM build breakage. Patch by: jgw, jat Review by: jat (Desk check) Modified: trunk/dev/oophm/overlay/com/google/gwt/dev/GWTShell.java ============================================================================== --- trunk/dev/oophm/overlay/com/google/gwt/dev/GWTShell.java (original) +++ trunk/dev/oophm/overlay/com/google/gwt/dev/GWTShell.java Fri Feb 6 14:54:00 2009 @@ -441,6 +441,10 @@ return false; } + public WebServerRestart hasWebServer() { + return WebServerRestart.NONE; + } + /** * Launch the arguments as Urls in separate windows. */ @@ -491,6 +495,10 @@ throw new UnableToCompleteException(); } + public void restartServer(TreeLogger logger) throws UnableToCompleteException { + // Unimplemented. + } + @Override protected void compile(TreeLogger logger) throws UnableToCompleteException { throw new UnsupportedOperationException(); @@ -612,8 +620,7 @@ ImageIcon gwtIcon = loadImageIcon("icon24.png"); frame = new JFrame("GWT Hosted Mode"); tabs = new JTabbedPane(); - boolean checkForUpdates = doShouldCheckForUpdates(); - mainWnd = new ShellMainWindow(this, checkForUpdates, options.getLogLevel()); + mainWnd = new ShellMainWindow(this, options.getLogLevel()); tabs.addTab("Hosted Mode", gwtIcon, mainWnd, "GWT Hosted-mode"); if (!options.isNoServer()) { ImageIcon tomcatIcon = loadImageIcon("tomcat24.png"); Modified: trunk/dev/oophm/overlay/com/google/gwt/dev/shell/PlatformSpecific.java ============================================================================== --- trunk/dev/oophm/overlay/com/google/gwt/dev/shell/PlatformSpecific.java (original) +++ trunk/dev/oophm/overlay/com/google/gwt/dev/shell/PlatformSpecific.java Fri Feb 6 14:54:00 2009 @@ -16,6 +16,16 @@ package com.google.gwt.dev.shell; import java.lang.reflect.Constructor; +import java.net.URL; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.FutureTask; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import com.google.gwt.core.ext.TreeLogger; +import com.google.gwt.core.ext.TreeLogger.HelpInfo; +import com.google.gwt.dev.shell.CheckForUpdates.UpdateResult; /** * Performs platform-specific class selection. @@ -23,31 +33,106 @@ public class PlatformSpecific { /** - * All of these classes must extend CheckForUpdates. + * All of these classes must extend CheckForUpdates. Note that currently only + * IE has a custom implementation (to handle proxies) and that CheckForUpdates + * must be the last one in the list. */ private static final String[] updaterClassNames = new String[] { - // "com.google.gwt.dev.shell.ie.CheckForUpdatesIE6", - // "com.google.gwt.dev.shell.moz.CheckForUpdatesMoz", - // "com.google.gwt.dev.shell.mac.CheckForUpdatesSaf" - }; - - @SuppressWarnings("unchecked") - // Class.forName - public static CheckForUpdates createUpdateChecker() { + "com.google.gwt.dev.shell.ie.CheckForUpdatesIE6", + "com.google.gwt.dev.shell.CheckForUpdates"}; + + public static FutureTask<UpdateResult> checkForUpdatesInBackgroundThread( + final TreeLogger logger, final long minCheckMillis) { + final String entryPoint = PlatformSpecific.computeEntryPoint(); + FutureTask<UpdateResult> task = new FutureTask<UpdateResult>( + new Callable<UpdateResult>() { + public UpdateResult call() throws Exception { + final CheckForUpdates updateChecker = createUpdateChecker(logger, + entryPoint); + return updateChecker == null ? null + : updateChecker.check(minCheckMillis); + } + }); + Thread checkerThread = new Thread(task, "GWT Update Checker"); + checkerThread.setDaemon(true); + checkerThread.start(); + return task; + } + + /** + * Find the first method named "main" on the call stack and use its class as + * the entry point. + */ + public static String computeEntryPoint() { + Throwable t = new Throwable(); + for (StackTraceElement stackTrace : t.getStackTrace()) { + if (stackTrace.getMethodName().equals("main")) { + // Strip package name from main's class + String className = stackTrace.getClassName(); + int i = className.lastIndexOf('.'); + if (i >= 0) { + return className.substring(i + 1); + } + return className; + } + } + return null; + } + + public static CheckForUpdates createUpdateChecker(TreeLogger logger) { + return createUpdateChecker(logger, computeEntryPoint()); + } + + public static CheckForUpdates createUpdateChecker(TreeLogger logger, + String entryPoint) { try { for (int i = 0; i < updaterClassNames.length; i++) { try { - Class<CheckForUpdates> clazz = (Class<CheckForUpdates>) Class.forName(updaterClassNames[i]); - Constructor<CheckForUpdates> ctor = clazz.getDeclaredConstructor(new Class[] {}); - CheckForUpdates checker = ctor.newInstance(new Object[] {}); + Class<? extends CheckForUpdates> clazz = Class.forName( + updaterClassNames[i]).asSubclass(CheckForUpdates.class); + Constructor<? extends CheckForUpdates> ctor = clazz.getDeclaredConstructor(new Class[] { + TreeLogger.class, String.class}); + CheckForUpdates checker = ctor.newInstance(new Object[] { + logger, entryPoint}); return checker; - } catch (ClassNotFoundException e) { - // keep trying + } catch (Exception e) { + // Other exceptions can occur besides ClassNotFoundException, + // so ignore them all so we can find a functional updater. } } } catch (Throwable e) { // silently ignore any errors } return null; + } + + public static void logUpdateAvailable(TreeLogger logger, + FutureTask<UpdateResult> updater) { + if (updater != null && updater.isDone()) { + UpdateResult result = null; + try { + result = updater.get(0, TimeUnit.MILLISECONDS); + } catch (InterruptedException e) { + // Silently ignore exception + } catch (ExecutionException e) { + // Silently ignore exception + } catch (TimeoutException e) { + // Silently ignore exception + } + logUpdateAvailable(logger, result); + } + } + + public static void logUpdateAvailable(TreeLogger logger, UpdateResult result) { + if (result != null) { + final URL url = result.getURL(); + logger.log(TreeLogger.WARN, "A new version of GWT (" + + result.getNewVersion() + ") is available", null, new HelpInfo() { + @Override + public URL getURL() { + return url; + } + }); + } } } Modified: trunk/dev/oophm/overlay/com/google/gwt/dev/shell/ShellMainWindow.java ============================================================================== --- trunk/dev/oophm/overlay/com/google/gwt/dev/shell/ShellMainWindow.java (original) +++ trunk/dev/oophm/overlay/com/google/gwt/dev/shell/ShellMainWindow.java Fri Feb 6 14:54:00 2009 @@ -34,9 +34,7 @@ private SwingLoggerPanel logWindow; - public ShellMainWindow(GWTShell shell, boolean checkForUpdates, - TreeLogger.Type maxLevel) { - // TODO(jat): implement update check + public ShellMainWindow(GWTShell shell, TreeLogger.Type maxLevel) { super(new BorderLayout()); JPanel panel = new JPanel(new GridLayout(2, 1)); JPanel optionPanel = new JPanel(); --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---