Cherry picking r10489 into release/2.4 for public issue 1508802 git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/2.4@10538 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/ExternalPermutationWorkerFactory.java b/dev/core/src/com/google/gwt/dev/ExternalPermutationWorkerFactory.java index 66b02fa..a4109e1 100644 --- a/dev/core/src/com/google/gwt/dev/ExternalPermutationWorkerFactory.java +++ b/dev/core/src/com/google/gwt/dev/ExternalPermutationWorkerFactory.java
@@ -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",
diff --git a/dev/core/src/com/google/gwt/dev/util/Util.java b/dev/core/src/com/google/gwt/dev/util/Util.java index 5a19a38..168cbaf 100644 --- a/dev/core/src/com/google/gwt/dev/util/Util.java +++ b/dev/core/src/com/google/gwt/dev/util/Util.java
@@ -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); } /**
diff --git a/dev/core/src/com/google/gwt/util/tools/Utility.java b/dev/core/src/com/google/gwt/util/tools/Utility.java index fddb1ac..966be1e 100644 --- a/dev/core/src/com/google/gwt/util/tools/Utility.java +++ b/dev/core/src/com/google/gwt/util/tools/Utility.java
@@ -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; @@ -255,29 +235,6 @@ } /** - * 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. * * @param baseDir base directory to contain the new directory. May be @@ -342,25 +299,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 { FileOutputStream o = new FileOutputStream(file);
diff --git a/dev/core/src/com/google/gwt/util/tools/shared/Md5Utils.java b/dev/core/src/com/google/gwt/util/tools/shared/Md5Utils.java new file mode 100644 index 0000000..d0af4e1 --- /dev/null +++ b/dev/core/src/com/google/gwt/util/tools/shared/Md5Utils.java
@@ -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(); + } +}
diff --git a/dev/core/src/com/google/gwt/util/tools/shared/StringUtils.java b/dev/core/src/com/google/gwt/util/tools/shared/StringUtils.java new file mode 100644 index 0000000..c7ffb3b --- /dev/null +++ b/dev/core/src/com/google/gwt/util/tools/shared/StringUtils.java
@@ -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); + } +}
diff --git a/dev/core/src/com/google/gwt/util/tools/shared/package-info.java b/dev/core/src/com/google/gwt/util/tools/shared/package-info.java new file mode 100644 index 0000000..201db87 --- /dev/null +++ b/dev/core/src/com/google/gwt/util/tools/shared/package-info.java
@@ -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;
diff --git a/servlet/build.xml b/servlet/build.xml index dcb9a83..f274e05 100755 --- a/servlet/build.xml +++ b/servlet/build.xml
@@ -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/**" />
diff --git a/user/src/com/google/gwt/i18n/rebind/keygen/MD5KeyGenerator.java b/user/src/com/google/gwt/i18n/rebind/keygen/MD5KeyGenerator.java index ff3bf48..71cc694 100644 --- a/user/src/com/google/gwt/i18n/rebind/keygen/MD5KeyGenerator.java +++ b/user/src/com/google/gwt/i18n/rebind/keygen/MD5KeyGenerator.java
@@ -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()); } }
diff --git a/user/src/com/google/gwt/i18n/server/keygen/MD5KeyGenerator.java b/user/src/com/google/gwt/i18n/server/keygen/MD5KeyGenerator.java index 3849027..24c6e09 100644 --- a/user/src/com/google/gwt/i18n/server/keygen/MD5KeyGenerator.java +++ b/user/src/com/google/gwt/i18n/server/keygen/MD5KeyGenerator.java
@@ -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()); } }
diff --git a/user/src/com/google/gwt/user/server/rpc/XsrfProtectedServiceServlet.java b/user/src/com/google/gwt/user/server/rpc/XsrfProtectedServiceServlet.java index 5a6c062..43702cc 100644 --- a/user/src/com/google/gwt/user/server/rpc/XsrfProtectedServiceServlet.java +++ b/user/src/com/google/gwt/user/server/rpc/XsrfProtectedServiceServlet.java
@@ -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())) {
diff --git a/user/src/com/google/gwt/user/server/rpc/XsrfTokenServiceServlet.java b/user/src/com/google/gwt/user/server/rpc/XsrfTokenServiceServlet.java index fa5343d..265b96f 100644 --- a/user/src/com/google/gwt/user/server/rpc/XsrfTokenServiceServlet.java +++ b/user/src/com/google/gwt/user/server/rpc/XsrfTokenServiceServlet.java
@@ -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)); } /**