Author: [email protected]
Date: Fri Jun  5 07:19:33 2009
New Revision: 5513

Added:
    trunk/dev/core/test/com/google/gwt/dev/AboutTest.java   (contents, props  
changed)
Modified:
    trunk/dev/core/src/com/google/gwt/core/linker/IFrameLinker.java
    trunk/dev/core/src/com/google/gwt/core/linker/SingleScriptLinker.java
    trunk/dev/core/src/com/google/gwt/core/linker/XSLinker.java
    trunk/dev/core/src/com/google/gwt/dev/About.java
    trunk/dev/core/src/com/google/gwt/dev/GWTMain.java
    trunk/dev/core/src/com/google/gwt/dev/SignatureDumper.java
    trunk/dev/core/src/com/google/gwt/dev/shell/CheckForUpdates.java
    trunk/dev/core/src/com/google/gwt/dev/shell/GWTBridgeImpl.java
    trunk/dev/core/src/com/google/gwt/util/tools/ToolBase.java
    trunk/user/src/com/google/gwt/junit/GWTDummyBridge.java
    trunk/user/src/com/google/gwt/user/tools/WebAppCreator.java

Log:
- Deprecates the constants in About.java that contain version information
in favor of getters in the same class.
- Migrates all internal references to these contants the new getters.
- Migrates version string parsing logic in CheckForUpdates to About.  A
new method to return the version as a 3 element array is available.

Review by: scottb,jat


Modified: trunk/dev/core/src/com/google/gwt/core/linker/IFrameLinker.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/core/linker/IFrameLinker.java      
(original)
+++ trunk/dev/core/src/com/google/gwt/core/linker/IFrameLinker.java     Fri  
Jun  5 07:19:33 2009
@@ -255,7 +255,7 @@
      // Setup the well-known variables.
      out.print("<head><script>");
      out.newlineOpt();
-    out.print("var $gwt_version = \"" + About.GWT_VERSION_NUM + "\";");
+    out.print("var $gwt_version = \"" + About.getGwtVersionNum() + "\";");
      out.newlineOpt();
      out.print("var $wnd = parent;");
      out.newlineOpt();

Modified:  
trunk/dev/core/src/com/google/gwt/core/linker/SingleScriptLinker.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/core/linker/SingleScriptLinker.java       
 
(original)
+++ trunk/dev/core/src/com/google/gwt/core/linker/SingleScriptLinker.java       
 
Fri Jun  5 07:19:33 2009
@@ -81,7 +81,7 @@
      // Emit the module's JS a closure.
      out.print("(function () {");
      out.newlineOpt();
-    out.print("var $gwt_version = \"" + About.GWT_VERSION_NUM + "\";");
+    out.print("var $gwt_version = \"" + About.getGwtVersionNum() + "\";");
      out.newlineOpt();
      out.print("var $wnd = window;");
      out.newlineOpt();

Modified: trunk/dev/core/src/com/google/gwt/core/linker/XSLinker.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/core/linker/XSLinker.java (original)
+++ trunk/dev/core/src/com/google/gwt/core/linker/XSLinker.java Fri Jun  5  
07:19:33 2009
@@ -67,7 +67,7 @@

      // Setup the well-known variables.
      //
-    out.print("var $gwt_version = \"" + About.GWT_VERSION_NUM + "\";");
+    out.print("var $gwt_version = \"" + About.getGwtVersionNum() + "\";");
      out.newlineOpt();
      out.print("var $wnd = window;");
      out.newlineOpt();

Modified: trunk/dev/core/src/com/google/gwt/dev/About.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/dev/About.java    (original)
+++ trunk/dev/core/src/com/google/gwt/dev/About.java    Fri Jun  5 07:19:33  
2009
@@ -15,8 +15,8 @@
   */
  package com.google.gwt.dev;

-import java.io.InputStream;
  import java.io.IOException;
+import java.io.InputStream;
  import java.util.Properties;

  /**
@@ -24,13 +24,38 @@
   */
  public class About {

+  // TODO(zundel): These public constants should be removed some day.
+  // Java inlines static final constants in compiled classes, leading to
+  // version incompatibility warnings.
+  /**
+   * @deprecated use {...@link #getGwtName()} instead.
+   */
+  @Deprecated
+  public static String GWT_NAME;
+
+  /**
+   * @deprecated use {...@link #getGwtSvnRev()} instead.
+   */
+  @Deprecated
    public static String GWT_SVNREV;

-  public static String GWT_VERSION_NUM;
+  /**
+   * @deprecated use {...@link #getGwtVersion()} instead.
+   */
+  @Deprecated
+  public static String GWT_VERSION;

-  public static String GWT_NAME = "Google Web Toolkit";
+  /**
+   * @deprecated use {...@link #getGwtVersionArray()} or
+   *             {...@link #getGwtVersionNum()} instead.
+   */
+  @Deprecated
+  public static String GWT_VERSION_NUM;

-  public static String GWT_VERSION;
+  private static final String gwtName = "Google Web Toolkit";
+  private static final String gwtSvnRev;
+  private static int[] gwtVersionArray = null;
+  private static final String gwtVersionNum;

    static {
      Properties props = new Properties();
@@ -41,18 +66,129 @@
        // okay... we use default values, then.
      }

-    GWT_SVNREV = props.getProperty("gwt.svnrev");
+    String tmp;
+    tmp = props.getProperty("gwt.svnrev");
      // Check for null or sentinel value (break up to avoid text replace)
-    if (GWT_SVNREV == null || GWT_SVNREV.equals("@GWT_" + "SVNREV@")) {
-      GWT_SVNREV = "unknown";
+    if (tmp == null || tmp.equals("@GWT_" + "SVNREV@")) {
+      gwtSvnRev = "unknown";
+    } else {
+      gwtSvnRev = tmp;
      }

-    GWT_VERSION_NUM = props.getProperty("gwt.version");
+    tmp = props.getProperty("gwt.version");
      // Check for null or sentinel value (break up to avoid text replace)
-    if (GWT_VERSION_NUM == null || GWT_VERSION_NUM.equals("@GWT_"  
+ "VERSION@")) {
-      GWT_VERSION_NUM = "0.0.0";
+    if (tmp == null || tmp.equals("@GWT_" + "VERSION@")) {
+      gwtVersionNum = "0.0.0";
+    } else {
+      gwtVersionNum = tmp;
+    }
+
+    // Initialize deprecated constants
+    GWT_NAME = getGwtName();
+    GWT_VERSION = getGwtVersion();
+    GWT_VERSION_NUM = getGwtVersionNum();
+    GWT_SVNREV = getGwtSvnRev();
+  }
+
+  /**
+   * Returns the name of the product.
+   */
+  public static String getGwtName() {
+    return gwtName;
+  }
+
+  /**
+   * Returns the Subversion repository revision number.
+   *
+   * @return the subversion revision or 'unknown' if the value couldn't be
+   *         determined at build time.
+   */
+  public static String getGwtSvnRev() {
+    return gwtSvnRev;
+  }
+
+  /**
+   * Returns the product name and release number concatenated with a space.
+   */
+  public static String getGwtVersion() {
+    return getGwtName() + " " + getGwtVersionNum();
+  }
+
+  /**
+   * The Google Web Toolkit release number.
+   *
+   * @return the release number or the array {0, 0, 0} if the value  
couldn't be
+   *         determined at build time.
+   */
+  public static int[] getGwtVersionArray() {
+    if (gwtVersionArray == null) {
+      gwtVersionArray = parseGwtVersionString(getGwtVersionNum());
+    }
+    return gwtVersionArray;
+  }
+
+  /**
+   * The Google Web Toolkit release number.
+   *
+   * @return the release number or the string '0.0.0' if the value  
couldn't be
+   *         determined at build time.
+   */
+  public static String getGwtVersionNum() {
+    return gwtVersionNum;
+  }
+
+  /**
+   * Takes a string formatted as 3 numbers separated by periods and  
returns an 3
+   * element array. Non-numeric prefixes and suffixes are stripped.
+   *
+   * @param versionString A string formatted as 3 numbers.
+   * @return a 3 element array of the parsed string
+   * @throws NumberFormatException if the string is malformed
+   */
+  public static int[] parseGwtVersionString(String versionString)
+      throws NumberFormatException {
+    int[] version = {0, 0, 0};
+    if (versionString == null) {
+      return version;
+    }
+    int len = versionString.length();
+    int index = 0;
+    // Skip leading characters that are not digits to support a
+    // non-numeric prefix on a version string.
+    for (; index < len; ++index) {
+      if (Character.isDigit(versionString.charAt(index))) {
+        break;
+      }
+    }
+    int part = 0;
+    int v = 0;
+    for (; index < len; ++index) {
+      char ch = versionString.charAt(index);
+      if (ch == '.') {
+        if (part >= version.length) {
+          throw new NumberFormatException("Too many period chracters");
+        }
+        version[part++] = v;
+        v = 0;
+      } else if (Character.isDigit(ch)) {
+        int digit = Character.digit(ch, 10);
+        if (digit < 0) {
+          throw new NumberFormatException("Negative number encountered");
+        }
+        v = v * 10 + digit;
+      } else {
+        // end the parse to support a non-numeric suffix
+        break;
+      }
+    }
+    if (part >= version.length) {
+      throw new NumberFormatException("Too many digits in string. Expected  
3");
+    }
+    version[part++] = v;
+    if (part != version.length) {
+      throw new NumberFormatException("Expected 3 elements in array");
      }
-    GWT_VERSION = GWT_NAME + " " + GWT_VERSION_NUM;
+    return version;
    }

    private About() {

Modified: trunk/dev/core/src/com/google/gwt/dev/GWTMain.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/dev/GWTMain.java  (original)
+++ trunk/dev/core/src/com/google/gwt/dev/GWTMain.java  Fri Jun  5 07:19:33  
2009
@@ -28,7 +28,7 @@
      if (aboutText != null) {
        System.err.println(aboutText);
      } else {
-      System.err.println(About.GWT_VERSION);
+      System.err.println(About.getGwtVersion());
      }
      System.err.println("Available main classes:");
      System.err.println(addSpaces(HostedMode.class.getName(),

Modified: trunk/dev/core/src/com/google/gwt/dev/SignatureDumper.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/dev/SignatureDumper.java  (original)
+++ trunk/dev/core/src/com/google/gwt/dev/SignatureDumper.java  Fri Jun  5  
07:19:33 2009
@@ -42,7 +42,7 @@
        PrintWriter out = new PrintWriter(osw);
        out.println("# Contains all signatures dumped from the GWT  
compiler");
        out.println("FileVersion 1");
-      out.println("GwtVersion " + About.GWT_VERSION_NUM);
+      out.println("GwtVersion " + About.getGwtVersionNum());
        out.print(dumpAllSignatures(typeOracle));
        out.close();
        logger.log(TreeLogger.INFO, "Signatures dumped into " + outFile,  
null);

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    Fri  
Jun  5 07:19:33 2009
@@ -61,12 +61,16 @@
     */
    public static class GwtVersion implements Comparable<GwtVersion> {

-    private final int[] version = new int[3];
+    /**
+     *  Always a 3 element array.
+     */
+    private final int[] version;

      /**
       * Create a version that avoids any nagging -- "0.0.999".
       */
      public GwtVersion() {
+      version = new int[3];
        version[2] = 999;
      }

@@ -78,29 +82,7 @@
       * @throws NumberFormatException
       */
      public GwtVersion(String versionString) throws NumberFormatException {
-      if (versionString == null) {
-        return;
-      }
-      int part = 0;
-      int v = 0;
-      int len = versionString.length();
-      for (int i = 0; i < len; ++i) {
-        char ch = versionString.charAt(i);
-        if (ch == '.') {
-          if (part >= version.length) {
-            throw new NumberFormatException();
-          }
-          version[part++] = v;
-          v = 0;
-        } else if (Character.isDigit(ch)) {
-          int digit = Character.digit(ch, 10);
-          if (digit < 0) {
-            throw new NumberFormatException();
-          }
-          v = v * 10 + digit;
-        }
-      }
-      version[part++] = v;
+     version = About.parseGwtVersionString(versionString);
      }

      public int compareTo(GwtVersion o) {
@@ -357,7 +339,7 @@
      this.logger = logger;
      this.entryPoint = entryPoint;
      try {
-      myVersion = new GwtVersion(About.GWT_VERSION_NUM);
+      myVersion = new GwtVersion(About.getGwtVersionNum());
      } catch (NumberFormatException e) {
        // if our build version number is bogus, use one that avoids nagging
        myVersion = new GwtVersion();
@@ -445,8 +427,8 @@

        // See if new version is available.
        //
-      String url = queryURL + "?v=" + About.GWT_VERSION_NUM + "&id="
-          + firstLaunch + "&r=" + About.GWT_SVNREV;
+      String url = queryURL + "?v=" + About.getGwtVersionNum() + "&id="
+          + firstLaunch + "&r=" + About.getGwtSvnRev();
        if (entryPoint != null) {
          url += "&e=" + entryPoint;
        }

Modified: trunk/dev/core/src/com/google/gwt/dev/shell/GWTBridgeImpl.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/dev/shell/GWTBridgeImpl.java       
(original)
+++ trunk/dev/core/src/com/google/gwt/dev/shell/GWTBridgeImpl.java      Fri Jun 
  
5 07:19:33 2009
@@ -42,11 +42,11 @@
            + "' (did you forget to inherit a required module?)";
        throw new RuntimeException(msg, e);
      }
-  };
+  }

    @Override
    public String getVersion() {
-    return About.GWT_VERSION_NUM;
+    return About.getGwtVersionNum();
    }

    /**

Modified: trunk/dev/core/src/com/google/gwt/util/tools/ToolBase.java
==============================================================================
--- trunk/dev/core/src/com/google/gwt/util/tools/ToolBase.java  (original)
+++ trunk/dev/core/src/com/google/gwt/util/tools/ToolBase.java  Fri Jun  5  
07:19:33 2009
@@ -85,7 +85,7 @@
    }

    protected void printHelp() {
-    System.err.println(About.GWT_VERSION);
+    System.err.println(About.getGwtVersion());

      ArgHandler nullHandler = null;
      int widest = 0;

Added: trunk/dev/core/test/com/google/gwt/dev/AboutTest.java
==============================================================================
--- (empty file)
+++ trunk/dev/core/test/com/google/gwt/dev/AboutTest.java       Fri Jun  5  
07:19:33 2009
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may  
not
+ * use this file except in compliance with the License. You may obtain a  
copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations  
under
+ * the License.
+ */
+package com.google.gwt.dev;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests the methods in About
+ */
+public class AboutTest extends TestCase {
+
+  @SuppressWarnings("deprecation")
+  public void testDepreciatedConstants() {
+    assertEquals("GWT_NAME", About.getGwtName(), About.GWT_NAME);
+    assertEquals("GWT_VERSION", About.getGwtVersion(), About.GWT_VERSION);
+    assertEquals("GWT_VERSION_NUM", About.getGwtVersionNum(),  
About.GWT_VERSION_NUM);
+    assertEquals("GWT_SVNREV", About.getGwtSvnRev(), About.GWT_SVNREV);
+  }
+
+  public void testGwtName() {
+    String result = About.getGwtName();
+    assertTrue("Google Web Toolkit".equals(result));
+  }
+
+  public void testGwtSvnRev() {
+    String result = About.getGwtSvnRev();
+    assertFalse(result.length() == 0);
+  }
+
+  public void testGwtVersion() {
+    String result = About.getGwtVersion();
+    assertFalse(result.length() == 0);
+    String compare = About.getGwtName() + " " + About.getGwtVersionNum();
+
+  }
+
+  public void testGwtVersionNum() {
+    String result = About.getGwtVersionNum();
+    assertFalse(result.length() == 0);
+  }
+
+  public void testParseGwtVersionString() {
+    int[] result;
+    result = About.parseGwtVersionString("0.0.0");
+    assertEquals("result.length", 3, result.length);
+    assertEquals("0.0.0 - 0", 0, result[0]);
+    assertEquals("0.0.0 - 1", 0, result[1]);
+    assertEquals("0.0.0 - 2", 0, result[2]);
+
+    result = About.parseGwtVersionString(null);
+    assertEquals("result.length", 3, result.length);
+    assertEquals("null - 0", 0, result[0]);
+    assertEquals("null - 1", 0, result[1]);
+    assertEquals("null - 2", 0, result[2]);
+
+    result = About.parseGwtVersionString("1.5.4");
+    assertEquals("result.length", 3, result.length);
+    assertEquals("1.5.4 - 0", 1, result[0]);
+    assertEquals("1.5.4 - 1", 5, result[1]);
+    assertEquals("1.5.4 - 2", 4, result[2]);
+
+    result = About.parseGwtVersionString("prefix1.5.4");
+    assertEquals("prefix1.5.4 - 0", 1, result[0]);
+    assertEquals("prefix1.5.4 - 1", 5, result[1]);
+    assertEquals("prefix1.5.4 - 2", 4, result[2]);
+
+    result = About.parseGwtVersionString("1.5.4-suffix0");
+    assertEquals("result.length", 3, result.length);
+    assertEquals("1.5.4-suffix0 - 0", 1, result[0]);
+    assertEquals("1.5.4-suffix0 - 1", 5, result[1]);
+    assertEquals("1.5.4-suffix0 - 2", 4, result[2]);
+
+    result = About.parseGwtVersionString("1.5.4-patch0");
+    assertEquals("result.length", 3, result.length);
+    assertEquals("1.5.4-patch0 - 0", 1, result[0]);
+    assertEquals("1.5.4-patch0 - 1", 5, result[1]);
+    assertEquals("1.5.4-patch0 - 2", 4, result[2]);
+
+    try {
+      result = About.parseGwtVersionString("1.5.4.2");
+      fail("Should have thrown exception parsing 1.5.4.2. Got "
+          + result[0] +", " + result[1] + ", " + result[2]);
+    } catch (NumberFormatException ex) {
+      // OK
+    }
+
+    try {
+      result = About.parseGwtVersionString("1.5baloney");
+      fail("Should have thrown exception parsing 1.5baloney Got "
+          + result[0] +", " + result[1] + ", " + result[2]);
+    } catch (NumberFormatException ex) {
+      // OK
+    }
+
+    try {
+      result = About.parseGwtVersionString("1");
+      fail("Should have thrown exception parsing 1 Got "
+          + result[0] +", " + result[1] + ", " + result[2]);
+    } catch (NumberFormatException ex) {
+      // OK
+    }
+
+    try {
+      result = About.parseGwtVersionString("1.5");
+      fail("Should have thrown exception parsing 1.5 Got "
+          + result[0] +", " + result[1] + ", " + result[2]);
+    } catch (NumberFormatException ex) {
+      // OK
+    }
+  }
+}

Modified: trunk/user/src/com/google/gwt/junit/GWTDummyBridge.java
==============================================================================
--- trunk/user/src/com/google/gwt/junit/GWTDummyBridge.java     (original)
+++ trunk/user/src/com/google/gwt/junit/GWTDummyBridge.java     Fri Jun  5  
07:19:33 2009
@@ -37,10 +37,10 @@
    }

    /**
-   * @return the current version of GWT ({...@link About#GWT_VERSION_NUM})
+   * @return the current version of GWT ({...@link About#getGwtVersionNum()})
     */
    public String getVersion() {
-    return About.GWT_VERSION_NUM;
+    return About.getGwtVersionNum();
    }

    /**

Modified: trunk/user/src/com/google/gwt/user/tools/WebAppCreator.java
==============================================================================
--- trunk/user/src/com/google/gwt/user/tools/WebAppCreator.java (original)
+++ trunk/user/src/com/google/gwt/user/tools/WebAppCreator.java Fri Jun  5  
07:19:33 2009
@@ -219,12 +219,13 @@

      // Public builds generate a DTD reference.
      String gwtModuleDtd = "";
-    if (!About.GWT_VERSION_NUM.endsWith(".999")
-        && !About.GWT_VERSION_NUM.startsWith("0.0")) {
+    int gwtVersion[] = About.getGwtVersionArray();
+    if (gwtVersion[2] == 999
+        && !(gwtVersion[0] == 0 && gwtVersion[1] == 0)) {
        gwtModuleDtd = "\n<!DOCTYPE module PUBLIC \"-//Google Inc.//DTD  
Google Web Toolkit "
-          + About.GWT_VERSION_NUM
+          + About.getGwtVersionNum()
            + "//EN\" \"http://google-web-toolkit.googlecode.com/svn/tags/";
-          + About.GWT_VERSION_NUM  
+ "/distro-source/core/src/gwt-module.dtd\">";
+          + About.getGwtVersionNum()  
+ "/distro-source/core/src/gwt-module.dtd\">";
      }

      // Figure out what platform we're on
@@ -256,7 +257,7 @@
      replacements.put("@gwtUserPath", gwtUserPath);
      replacements.put("@gwtDevPath", gwtDevPath);
      replacements.put("@gwtOophmPath", gwtOophmPath);
-    replacements.put("@gwtVersion", About.GWT_VERSION_NUM);
+    replacements.put("@gwtVersion", About.getGwtVersionNum());
      replacements.put("@gwtModuleDtd", gwtModuleDtd);
      replacements.put("@shellClass", HostedMode.class.getName());
      replacements.put("@compileClass", Compiler.class.getName());

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

Reply via email to