Author: [email protected]
Date: Tue Mar 17 12:52:54 2009
New Revision: 5030

Removed:
    trunk/dev/core/src/com/google/gwt/dev/shell/PlatformSpecific.java
    trunk/dev/oophm/overlay/com/google/gwt/dev/shell/PlatformSpecific.java
Modified:
    trunk/dev/core/src/com/google/gwt/dev/Compiler.java
    trunk/dev/core/src/com/google/gwt/dev/GWTCompiler.java
    trunk/dev/core/src/com/google/gwt/dev/HostedModeBase.java
    trunk/dev/core/src/com/google/gwt/dev/Precompile.java
    trunk/dev/core/src/com/google/gwt/dev/SwtHostedModeBase.java
    trunk/dev/core/src/com/google/gwt/dev/shell/CheckForUpdates.java

Log:
Remove PlatformSpecific, moving the functionality into SwtHostedModeBase or
CheckForUpdates.  This means there is one less class that has to be shadowed
in OOPHM.

Patch by: jat
Review by: scottb


Modified: trunk/dev/core/src/com/google/gwt/dev/Compiler.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/dev/Compiler.java (original)
+++ trunk/dev/core/src/com/google/gwt/dev/Compiler.java Tue Mar 17 12:52:54  
2009
@@ -25,7 +25,6 @@
  import com.google.gwt.dev.cfg.ModuleDefLoader;
  import com.google.gwt.dev.jjs.JJSOptions;
  import com.google.gwt.dev.shell.CheckForUpdates;
-import com.google.gwt.dev.shell.PlatformSpecific;
  import com.google.gwt.dev.shell.CheckForUpdates.UpdateResult;
  import com.google.gwt.dev.util.FileBackedObject;
  import com.google.gwt.dev.util.PerfLogger;
@@ -132,12 +131,12 @@
          public boolean run(TreeLogger logger) throws  
UnableToCompleteException {
            FutureTask<UpdateResult> updater = null;
            if (!options.isUpdateCheckDisabled()) {
-            updater = PlatformSpecific.checkForUpdatesInBackgroundThread(
-                logger, CheckForUpdates.ONE_DAY);
+            updater =  
CheckForUpdates.checkForUpdatesInBackgroundThread(logger,
+                CheckForUpdates.ONE_DAY);
            }
            boolean success = new Compiler(options).run(logger);
            if (success) {
-            PlatformSpecific.logUpdateAvailable(logger, updater);
+            CheckForUpdates.logUpdateAvailable(logger, updater);
            }
            return success;
          }

Modified: trunk/dev/core/src/com/google/gwt/dev/GWTCompiler.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/dev/GWTCompiler.java      (original)
+++ trunk/dev/core/src/com/google/gwt/dev/GWTCompiler.java      Tue Mar 17  
12:52:54 2009
@@ -24,7 +24,6 @@
  import com.google.gwt.dev.cfg.ModuleDefLoader;
  import com.google.gwt.dev.jjs.JJSOptions;
  import com.google.gwt.dev.shell.CheckForUpdates;
-import com.google.gwt.dev.shell.PlatformSpecific;
  import com.google.gwt.dev.shell.CheckForUpdates.UpdateResult;
  import com.google.gwt.dev.util.FileBackedObject;
  import com.google.gwt.dev.util.PerfLogger;
@@ -119,12 +118,12 @@
          public boolean run(TreeLogger logger) throws  
UnableToCompleteException {
            FutureTask<UpdateResult> updater = null;
            if (!options.isUpdateCheckDisabled()) {
-            updater = PlatformSpecific.checkForUpdatesInBackgroundThread(
+            updater = CheckForUpdates.checkForUpdatesInBackgroundThread(
                  logger, CheckForUpdates.ONE_DAY);
            }
            boolean success = new GWTCompiler(options).run(logger);
            if (success) {
-            PlatformSpecific.logUpdateAvailable(logger, updater);
+            CheckForUpdates.logUpdateAvailable(logger, updater);
            }
            return success;
          }

Modified: trunk/dev/core/src/com/google/gwt/dev/HostedModeBase.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/dev/HostedModeBase.java   (original)
+++ trunk/dev/core/src/com/google/gwt/dev/HostedModeBase.java   Tue Mar 17  
12:52:54 2009
@@ -29,7 +29,6 @@
  import com.google.gwt.dev.shell.BrowserWindowController;
  import com.google.gwt.dev.shell.CheckForUpdates;
  import com.google.gwt.dev.shell.ModuleSpaceHost;
-import com.google.gwt.dev.shell.PlatformSpecific;
  import com.google.gwt.dev.shell.ShellModuleSpaceHost;
  import com.google.gwt.dev.util.Util;
  import com.google.gwt.dev.util.arg.ArgHandlerDisableAggressiveOptimization;
@@ -193,6 +192,7 @@
        HostedModeBase.this.compile(getLogger());
      }

+    @Deprecated
      public void compile(String[] moduleNames) throws  
UnableToCompleteException {
        if (!isLegacyMode()) {
          throw new UnsupportedOperationException();
@@ -431,6 +431,8 @@

    /**
     * Compiles all modules.
+   *
+   * @throws UnableToCompleteException
     */
    protected abstract void compile(TreeLogger logger)
        throws UnableToCompleteException;
@@ -481,12 +483,12 @@
      // Check for updates
      final TreeLogger logger = getTopLogger();
      final CheckForUpdates updateChecker
-        = PlatformSpecific.createUpdateChecker(logger);
+        = CheckForUpdates.createUpdateChecker(logger);
      if (updateChecker != null) {
        Thread checkerThread = new Thread("GWT Update Checker") {
          @Override
          public void run() {
-          PlatformSpecific.logUpdateAvailable(logger,
+          CheckForUpdates.logUpdateAvailable(logger,
                updateChecker.check(checkForUpdatesInterval()));
          }
        };

Modified: trunk/dev/core/src/com/google/gwt/dev/Precompile.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/dev/Precompile.java       (original)
+++ trunk/dev/core/src/com/google/gwt/dev/Precompile.java       Tue Mar 17  
12:52:54 2009
@@ -38,7 +38,6 @@
  import com.google.gwt.dev.jjs.UnifiedAst;
  import com.google.gwt.dev.jjs.impl.FragmentLoaderCreator;
  import com.google.gwt.dev.shell.CheckForUpdates;
-import com.google.gwt.dev.shell.PlatformSpecific;
  import com.google.gwt.dev.shell.StandardRebindOracle;
  import com.google.gwt.dev.shell.CheckForUpdates.UpdateResult;
  import com.google.gwt.dev.util.PerfLogger;
@@ -299,12 +298,12 @@
          public boolean run(TreeLogger logger) throws  
UnableToCompleteException {
            FutureTask<UpdateResult> updater = null;
            if (!options.isUpdateCheckDisabled()) {
-            updater = PlatformSpecific.checkForUpdatesInBackgroundThread(
-                logger, CheckForUpdates.ONE_DAY);
+            updater =  
CheckForUpdates.checkForUpdatesInBackgroundThread(logger,
+                CheckForUpdates.ONE_DAY);
            }
            boolean success = new Precompile(options).run(logger);
            if (success) {
-            PlatformSpecific.logUpdateAvailable(logger, updater);
+            CheckForUpdates.logUpdateAvailable(logger, updater);
            }
            return success;
          }

Modified: trunk/dev/core/src/com/google/gwt/dev/SwtHostedModeBase.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/dev/SwtHostedModeBase.java        
(original)
+++ trunk/dev/core/src/com/google/gwt/dev/SwtHostedModeBase.java        Tue Mar 
17  
12:52:54 2009
@@ -22,7 +22,6 @@
  import com.google.gwt.dev.shell.BrowserWidget;
  import com.google.gwt.dev.shell.BrowserWidgetHost;
  import com.google.gwt.dev.shell.ModuleSpaceHost;
-import com.google.gwt.dev.shell.PlatformSpecific;
  import com.google.gwt.dev.shell.ShellMainWindow;
  import com.google.gwt.dev.shell.ShellModuleSpaceHost;
  import com.google.gwt.dev.util.log.AbstractTreeLogger;
@@ -35,9 +34,12 @@
  import org.eclipse.swt.graphics.Rectangle;
  import org.eclipse.swt.internal.Library;
  import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
  import org.eclipse.swt.widgets.Display;
  import org.eclipse.swt.widgets.Shell;

+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
  import java.util.ArrayList;
  import java.util.List;

@@ -74,6 +76,16 @@
      }
    }

+  /**
+   * All of these classes must extend BrowserWidget. The first one that  
loads
+   * will be used, so it is important that only the correct one be on the
+   * classpath.
+   */
+  private static final String[] browserClassNames = new String[] {
+      "com.google.gwt.dev.shell.ie.BrowserWidgetIE6",
+      "com.google.gwt.dev.shell.moz.BrowserWidgetMoz",
+      "com.google.gwt.dev.shell.mac.BrowserWidgetSaf"};
+
    static {
      // Force ToolBase to clinit, which causes SWT stuff to happen.
      new ToolBase() {
@@ -82,6 +94,47 @@
      Display.setAppName("GWT");
    }

+  private static BrowserWidget createBrowserWidget(TreeLogger logger,
+      Composite parent, BrowserWidgetHost host)
+      throws UnableToCompleteException {
+    Throwable caught = null;
+    try {
+      for (int i = 0; i < browserClassNames.length; i++) {
+        Class<? extends BrowserWidget> clazz = null;
+        try {
+          clazz = Class.forName(browserClassNames[i]).asSubclass(
+              BrowserWidget.class);
+          Constructor<? extends BrowserWidget> ctor =  
clazz.getDeclaredConstructor(new Class[] {
+              Shell.class, BrowserWidgetHost.class});
+          BrowserWidget bw = ctor.newInstance(new Object[] {parent, host});
+          return bw;
+        } catch (ClassNotFoundException e) {
+          caught = e;
+        }
+      }
+      logger.log(TreeLogger.ERROR,
+          "No instantiable browser widget class could be found", caught);
+      throw new UnableToCompleteException();
+    } catch (SecurityException e) {
+      caught = e;
+    } catch (NoSuchMethodException e) {
+      caught = e;
+    } catch (IllegalArgumentException e) {
+      caught = e;
+    } catch (InstantiationException e) {
+      caught = e;
+    } catch (IllegalAccessException e) {
+      caught = e;
+    } catch (InvocationTargetException e) {
+      caught = e.getTargetException();
+    } catch (ClassCastException e) {
+      caught = e;
+    }
+    logger.log(TreeLogger.ERROR,
+        "The browser widget class could not be instantiated", caught);
+    throw new UnableToCompleteException();
+  }
+
    private BrowserWidgetHostImpl browserHost = new  
SwtBrowserWidgetHostImpl();

    private final List<Shell> browserShells = new ArrayList<Shell>();
@@ -147,8 +200,7 @@
      boolean succeeded = false;
      Shell s = createTrackedBrowserShell();
      try {
-      BrowserWidget bw =  
PlatformSpecific.createBrowserWidget(getTopLogger(),
-          s, browserHost);
+      BrowserWidget bw = createBrowserWidget(getTopLogger(), s,  
browserHost);

        if (mainWnd != null) {
          Rectangle r = mainWnd.getShell().getBounds();

Modified: trunk/dev/core/src/com/google/gwt/dev/shell/CheckForUpdates.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/dev/shell/CheckForUpdates.java     
(original)
+++ trunk/dev/core/src/com/google/gwt/dev/shell/CheckForUpdates.java    Tue  
Mar 17 12:52:54 2009
@@ -16,6 +16,7 @@
  package com.google.gwt.dev.shell;

  import com.google.gwt.core.ext.TreeLogger;
+import com.google.gwt.core.ext.TreeLogger.HelpInfo;
  import com.google.gwt.dev.About;

  import org.w3c.dom.Document;
@@ -33,10 +34,16 @@
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.PrintWriter;
+import java.lang.reflect.Constructor;
  import java.net.MalformedURLException;
  import java.net.URL;
  import java.net.URLConnection;
  import java.util.Date;
+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 java.util.prefs.Preferences;

  import javax.xml.parsers.DocumentBuilder;
@@ -182,6 +189,110 @@
    // The real URL that should be used.
    private static final String QUERY_URL  
= "http://tools.google.com/webtoolkit/currentversion.xml";;

+  /**
+   * 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.CheckForUpdates"};
+
+  public static FutureTask<UpdateResult> checkForUpdatesInBackgroundThread(
+      final TreeLogger logger, final long minCheckMillis) {
+    final String entryPoint = 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<? 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 (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;
+        }
+      });
+    }
+  }
+
    private static String getTextOfLastElementHavingTag(Document doc,
        String tagName) {
      NodeList nodeList = doc.getElementsByTagName(tagName);
@@ -201,7 +312,9 @@
    }

    private String entryPoint;
+
    private TreeLogger logger;
+
    private GwtVersion myVersion;

    /**

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to