Add bytecode rewriting for the LogManager.getLoggerNames() function so this works correctly in DevMode

Review by: cromwellian@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10755 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/shell/rewrite/UseMirroredClasses.java b/dev/core/src/com/google/gwt/dev/shell/rewrite/UseMirroredClasses.java
index a2da9af..4782e37 100644
--- a/dev/core/src/com/google/gwt/dev/shell/rewrite/UseMirroredClasses.java
+++ b/dev/core/src/com/google/gwt/dev/shell/rewrite/UseMirroredClasses.java
@@ -56,6 +56,9 @@
         logManagerMethods.put(
             "getLogger",
             "com/google/gwt/logging/impl/DevModeLoggingFixes:logManagerGetLogger");
+        logManagerMethods.put(
+            "getLoggerNames",
+            "com/google/gwt/logging/impl/DevModeLoggingFixes:logManagerGetLoggerNames");
         mirrorMap.put("java/util/logging/LogManager", logManagerMethods);
         
         HashMap<String, String> loggerMethods = new HashMap<String, String>();
diff --git a/user/src/com/google/gwt/logging/impl/DevModeLoggingFixes.java b/user/src/com/google/gwt/logging/impl/DevModeLoggingFixes.java
index e72c506..28c921f 100644
--- a/user/src/com/google/gwt/logging/impl/DevModeLoggingFixes.java
+++ b/user/src/com/google/gwt/logging/impl/DevModeLoggingFixes.java
@@ -22,6 +22,11 @@
 import java.util.logging.LogRecord;
 import java.util.logging.Logger;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+
 /**
  * This class is used by the byte code rewriting which happens in DevMode only.
  * We rewrite all calls that create and access loggers by name to include a 
@@ -86,6 +91,25 @@
   public static Logger logManagerGetLogger(LogManager manager, String name) {
     return manager.getLogger(addLoggerPrefix(name));
   }
+
+  /**
+   * Replaces all LogManager.getLoggerNames() calls, deleting the thread specific
+   * prefix which is appended to all logger names in dev mode in order to
+   * maintain a pseudo tree of loggers for each thread.  Also deletes all logger
+   * names that do not start with the prefix since those belong to the server
+   * and should not be returned in this function.
+   */
+  public static Enumeration<String> logManagerGetLoggerNames(LogManager manager) {
+    Enumeration<String> loggerList = manager.getLoggerNames();
+    List<String> newList = new ArrayList<String>();
+    while (loggerList.hasMoreElements()) {
+      String name = loggerList.nextElement();
+      if (startsWithLoggerPrefix(name)) {
+        newList.add(removeLoggerPrefix(name));
+      }
+    }
+    return Collections.enumeration(newList);
+  }
   
   private static String addLoggerPrefix(String name) {
     return getLoggerPrefix() + name;
@@ -102,4 +126,8 @@
   private static String removeLoggerPrefix(String name) {
     return name.replaceFirst("^" + getLoggerPrefix(), "");
   }
+
+  private static boolean startsWithLoggerPrefix(String name) {
+    return name.startsWith(getLoggerPrefix());
+  }
 }