Revision: 10538
Author: mrruss...@google.com
Date: Wed Aug 17 06:37:04 2011
Log: Cherry picking r10489 into release/2.4 for public issue 1508802
http://code.google.com/p/google-web-toolkit/source/detail?r=10538
Added:
/releases/2.4/dev/core/src/com/google/gwt/util/tools/shared
/releases/2.4/dev/core/src/com/google/gwt/util/tools/shared/Md5Utils.java
/releases/2.4/dev/core/src/com/google/gwt/util/tools/shared/StringUtils.java
/releases/2.4/dev/core/src/com/google/gwt/util/tools/shared/package-info.java
Modified:
/releases/2.4/dev/core/src/com/google/gwt/dev/ExternalPermutationWorkerFactory.java
/releases/2.4/dev/core/src/com/google/gwt/dev/util/Util.java
/releases/2.4/dev/core/src/com/google/gwt/util/tools/Utility.java
/releases/2.4/servlet/build.xml
/releases/2.4/user/src/com/google/gwt/i18n/rebind/keygen/MD5KeyGenerator.java
/releases/2.4/user/src/com/google/gwt/i18n/server/keygen/MD5KeyGenerator.java
/releases/2.4/user/src/com/google/gwt/user/server/rpc/XsrfProtectedServiceServlet.java
/releases/2.4/user/src/com/google/gwt/user/server/rpc/XsrfTokenServiceServlet.java
=======================================
--- /dev/null
+++
/releases/2.4/dev/core/src/com/google/gwt/util/tools/shared/Md5Utils.java
Wed Aug 17 06:37:04 2011
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2011 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.util.tools.shared;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+/**
+ * Utility class to generate MD5 hashes using per-thread MD5
+ * {@link MessageDigest} instance.
+ */
+public class Md5Utils {
+
+ /**
+ * Per thread MD5 instance.
+ */
+ private static final ThreadLocal<MessageDigest> perThreadMd5 =
+ new ThreadLocal<MessageDigest>() {
+ @Override
+ protected MessageDigest initialValue() {
+ try {
+ return MessageDigest.getInstance("MD5");
+ } catch (NoSuchAlgorithmException e) {
+ throw new RuntimeException("MD5 implementation not found", e);
+ }
+ };
+ };
+
+ /**
+ * Generate MD5 digest.
+ *
+ * @param input input data to be hashed.
+ * @return MD5 digest.
+ */
+ public static byte[] getMd5Digest(byte[] input) {
+ MessageDigest md5 = perThreadMd5.get();
+ md5.reset();
+ md5.update(input);
+ return md5.digest();
+ }
+}
=======================================
--- /dev/null
+++
/releases/2.4/dev/core/src/com/google/gwt/util/tools/shared/StringUtils.java
Wed Aug 17 06:37:04 2011
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2006 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.util.tools.shared;
+
+/**
+ * String utility methods.
+ */
+public class StringUtils {
+
+ public static char[] HEX_CHARS = new char[] {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
+ 'E', 'F'};
+
+ /**
+ * A 4-digit hex result.
+ */
+ public static void hex4(char c, StringBuffer sb) {
+ sb.append(HEX_CHARS[(c & 0xF000) >> 12]);
+ sb.append(HEX_CHARS[(c & 0x0F00) >> 8]);
+ sb.append(HEX_CHARS[(c & 0x00F0) >> 4]);
+ sb.append(HEX_CHARS[c & 0x000F]);
+ }
+
+ /**
+ * Returns a string representation of the byte array as a series of
+ * hexadecimal characters.
+ *
+ * @param bytes byte array to convert
+ * @return a string representation of the byte array as a series of
+ * hexadecimal characters
+ */
+ public static String toHexString(byte[] bytes) {
+ char[] hexString = new char[2 * bytes.length];
+ int j = 0;
+ for (int i = 0; i < bytes.length; i++) {
+ hexString[j++] = HEX_CHARS[(bytes[i] & 0xF0) >> 4];
+ hexString[j++] = HEX_CHARS[bytes[i] & 0x0F];
+ }
+ return new String(hexString);
+ }
+}
=======================================
--- /dev/null
+++
/releases/2.4/dev/core/src/com/google/gwt/util/tools/shared/package-info.java
Wed Aug 17 06:37:04 2011
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2011 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.
+ */
+
+/**
+ * Utility classes shared between gwt-dev and gwt-servlet.
+ */
+@com.google.gwt.util.PreventSpuriousRebuilds
+package com.google.gwt.util.tools.shared;
=======================================
---
/releases/2.4/dev/core/src/com/google/gwt/dev/ExternalPermutationWorkerFactory.java
Tue Apr 26 08:02:24 2011
+++
/releases/2.4/dev/core/src/com/google/gwt/dev/ExternalPermutationWorkerFactory.java
Wed Aug 17 06:37:04 2011
@@ -21,7 +21,7 @@
import com.google.gwt.dev.jjs.UnifiedAst;
import com.google.gwt.dev.util.FileBackedObject;
import com.google.gwt.dev.util.Util;
-import com.google.gwt.util.tools.Utility;
+import com.google.gwt.util.tools.shared.StringUtils;
import java.io.BufferedReader;
import java.io.EOFException;
@@ -254,7 +254,7 @@
byte[] cookieBytes = new byte[16];
random.nextBytes(cookieBytes);
- String cookie = Utility.toHexString(cookieBytes);
+ String cookie = StringUtils.toHexString(cookieBytes);
// Cook up the classpath, main class, and extra args
args.addAll(Arrays.asList("-classpath",
=======================================
--- /releases/2.4/dev/core/src/com/google/gwt/dev/util/Util.java Mon Apr 18
04:15:28 2011
+++ /releases/2.4/dev/core/src/com/google/gwt/dev/util/Util.java Wed Aug 17
06:37:04 2011
@@ -22,6 +22,7 @@
import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger;
import com.google.gwt.dev.util.log.speedtracer.SpeedTracerLogger.Event;
import com.google.gwt.util.tools.Utility;
+import com.google.gwt.util.tools.shared.StringUtils;
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
@@ -172,7 +173,7 @@
for (int i = 0; i < contents.length; i++) {
md5.update(contents[i]);
}
- return Utility.toHexString(md5.digest());
+ return StringUtils.toHexString(md5.digest());
}
public static void copy(InputStream is, OutputStream os) throws
IOException {
@@ -437,11 +438,11 @@
/**
* A 4-digit hex result.
*
- * @deprecated use {@link Utility#hex4(char, StringBuffer)} instead.
+ * @deprecated use {@link StringUtils#hex4(char, StringBuffer)} instead.
*/
@Deprecated
public static void hex4(char c, StringBuffer sb) {
- Utility.hex4(c, sb);
+ StringUtils.hex4(c, sb);
}
/**
@@ -913,11 +914,11 @@
* @param bytes byte array to convert
* @return a string representation of the byte array as a series of
* hexadecimal characters
- * @deprecated use {@link Utility#toHexString(byte[])} instead.
+ * @deprecated use {@link StringUtils#toHexString(byte[])} instead.
*/
@Deprecated
public static String toHexString(byte[] bytes) {
- return Utility.toHexString(bytes);
+ return StringUtils.toHexString(bytes);
}
/**
=======================================
--- /releases/2.4/dev/core/src/com/google/gwt/util/tools/Utility.java Mon
Mar 7 08:21:08 2011
+++ /releases/2.4/dev/core/src/com/google/gwt/util/tools/Utility.java Wed
Aug 17 06:37:04 2011
@@ -32,8 +32,6 @@
import java.net.Socket;
import java.net.URI;
import java.net.URL;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -44,24 +42,6 @@
*/
public final class Utility {
- /**
- * Per thread MD5 instance.
- */
- private static final ThreadLocal<MessageDigest> perThreadMd5 =
- new ThreadLocal<MessageDigest>() {
- @Override
- protected MessageDigest initialValue() {
- try {
- return MessageDigest.getInstance("MD5");
- } catch (NoSuchAlgorithmException e) {
- return null;
- }
- };
- };
-
- public static char[] HEX_CHARS = new char[] {
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
- 'E', 'F'};
private static String sInstallPath = null;
@@ -253,29 +233,6 @@
}
return sInstallPath;
}
-
- /**
- * Generate MD5 digest.
- *
- * @param input input data to be hashed.
- * @return MD5 digest.
- */
- public static byte[] getMd5Digest(byte[] input) {
- MessageDigest md5 = perThreadMd5.get();
- md5.reset();
- md5.update(input);
- return md5.digest();
- }
-
- /**
- * A 4-digit hex result.
- */
- public static void hex4(char c, StringBuffer sb) {
- sb.append(HEX_CHARS[(c & 0xF000) >> 12]);
- sb.append(HEX_CHARS[(c & 0x0F00) >> 8]);
- sb.append(HEX_CHARS[(c & 0x00F0) >> 4]);
- sb.append(HEX_CHARS[c & 0x000F]);
- }
/**
* Creates a randomly-named temporary directory.
@@ -341,25 +298,6 @@
}
}
}
-
- /**
- * Returns a string representation of the byte array as a series of
- * hexadecimal characters.
- *
- * @param bytes byte array to convert
- * @return a string representation of the byte array as a series of
- * hexadecimal characters
- */
- public static String toHexString(byte[] bytes) {
- char[] hexString = new char[2 * bytes.length];
- int j = 0;
- for (int i = 0; i < bytes.length; i++) {
- hexString[j++] = HEX_CHARS[(bytes[i] & 0xF0) >> 4];
- hexString[j++] = HEX_CHARS[bytes[i] & 0x0F];
- }
-
- return new String(hexString);
- }
public static void writeTemplateBinaryFile(File file, byte[] contents)
throws IOException {
=======================================
--- /releases/2.4/servlet/build.xml Wed Jul 13 10:55:20 2011
+++ /releases/2.4/servlet/build.xml Wed Aug 17 06:37:04 2011
@@ -27,6 +27,7 @@
<include name="com/google/gwt/dev/asm/**" />
<include name="com/google/gwt/dev/util/Name*.class" />
<include name="com/google/gwt/dev/util/StringKey.class" />
+ <include name="com/google/gwt/util/tools/shared/**" />
</fileset>
<fileset dir="${gwt.user.bin}">
<exclude name="**/rebind/**" />
=======================================
---
/releases/2.4/user/src/com/google/gwt/i18n/rebind/keygen/MD5KeyGenerator.java
Fri Mar 11 11:18:03 2011
+++
/releases/2.4/user/src/com/google/gwt/i18n/rebind/keygen/MD5KeyGenerator.java
Wed Aug 17 06:37:04 2011
@@ -15,7 +15,7 @@
*/
package com.google.gwt.i18n.rebind.keygen;
-import com.google.gwt.util.tools.Utility;
+import com.google.gwt.util.tools.shared.StringUtils;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
@@ -55,6 +55,6 @@
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("UTF-8 unsupported", e);
}
- return Utility.toHexString(md5.digest());
+ return StringUtils.toHexString(md5.digest());
}
}
=======================================
---
/releases/2.4/user/src/com/google/gwt/i18n/server/keygen/MD5KeyGenerator.java
Fri Mar 11 11:18:03 2011
+++
/releases/2.4/user/src/com/google/gwt/i18n/server/keygen/MD5KeyGenerator.java
Wed Aug 17 06:37:04 2011
@@ -17,7 +17,7 @@
import com.google.gwt.i18n.server.KeyGenerator;
import com.google.gwt.i18n.server.Message;
-import com.google.gwt.util.tools.Utility;
+import com.google.gwt.util.tools.shared.StringUtils;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
@@ -55,6 +55,6 @@
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("UTF-8 unsupported", e);
}
- return Utility.toHexString(md5.digest());
+ return StringUtils.toHexString(md5.digest());
}
}
=======================================
---
/releases/2.4/user/src/com/google/gwt/user/server/rpc/XsrfProtectedServiceServlet.java
Wed Apr 13 19:08:53 2011
+++
/releases/2.4/user/src/com/google/gwt/user/server/rpc/XsrfProtectedServiceServlet.java
Wed Aug 17 06:37:04 2011
@@ -19,7 +19,8 @@
import com.google.gwt.user.client.rpc.RpcTokenException;
import com.google.gwt.user.client.rpc.XsrfToken;
import com.google.gwt.user.server.Util;
-import com.google.gwt.util.tools.Utility;
+import com.google.gwt.util.tools.shared.Md5Utils;
+import com.google.gwt.util.tools.shared.StringUtils;
import java.lang.reflect.Method;
@@ -111,8 +112,8 @@
"Unable to verify XSRF cookie");
}
- String expectedToken = Utility.toHexString(
- Utility.getMd5Digest(sessionCookie.getValue().getBytes()));
+ String expectedToken = StringUtils.toHexString(
+ Md5Utils.getMd5Digest(sessionCookie.getValue().getBytes()));
XsrfToken xsrfToken = (XsrfToken) token;
if (!expectedToken.equals(xsrfToken.getToken())) {
=======================================
---
/releases/2.4/user/src/com/google/gwt/user/server/rpc/XsrfTokenServiceServlet.java
Wed Apr 13 19:08:53 2011
+++
/releases/2.4/user/src/com/google/gwt/user/server/rpc/XsrfTokenServiceServlet.java
Wed Aug 17 06:37:04 2011
@@ -19,7 +19,8 @@
import com.google.gwt.user.client.rpc.XsrfToken;
import com.google.gwt.user.client.rpc.XsrfTokenService;
import com.google.gwt.user.server.Util;
-import com.google.gwt.util.tools.Utility;
+import com.google.gwt.util.tools.shared.Md5Utils;
+import com.google.gwt.util.tools.shared.StringUtils;
import javax.servlet.http.Cookie;
@@ -195,7 +196,7 @@
"Unable to generate XSRF cookie");
}
byte[] cookieBytes = sessionCookie.getValue().getBytes();
- return Utility.toHexString(Utility.getMd5Digest(cookieBytes));
+ return StringUtils.toHexString(Md5Utils.getMd5Digest(cookieBytes));
}
/**
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors