[logback-dev] svn commit: r1132 - in logback/trunk: logback-classic/src/main/java/ch/qos/logback/classic/util logback-core/src/main/java/ch/qos/logback/core/util

noreply.ceki at qos.ch noreply.ceki at qos.ch
Tue Dec 19 21:40:25 CET 2006


Author: ceki
Date: Tue Dec 19 21:40:25 2006
New Revision: 1132

Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java

Log:

Simplified Loader.getResource method

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java	Tue Dec 19 21:40:25 2006
@@ -26,9 +26,10 @@
 
   public static void autoConfig(LoggerContext loggerContext) {
 
-    URL url = Loader.getResource(AUTOCONFIG_FILE);
+    ClassLoader tccl = Loader.getTCL();
+    URL url = Loader.getResource(AUTOCONFIG_FILE, tccl);
     if (url == null) {
-      url = Loader.getResource(TEST_AUTOCONFIG_FILE);
+      url = Loader.getResource(TEST_AUTOCONFIG_FILE, tccl);
     }
 
     if (url != null) {

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java	Tue Dec 19 21:40:25 2006
@@ -44,8 +44,8 @@
    * parameter is false.</li>
    * 
    * <p>
-   * <li>If the above step fails, search for <code>resource</code> using
-   * the class loader that loaded this class (<code>Loader</code>).</li>
+   * <li>If the above step fails, search for <code>resource</code> using the
+   * class loader that loaded this class (<code>Loader</code>).</li>
    * 
    * <p>
    * <li>Try one last time with
@@ -55,61 +55,22 @@
    * 
    * </ol>
    */
-  public static URL getResource(String resource) {
-    ClassLoader classLoader = null;
-    URL url = null;
-
+  public static URL getResource(String resource, ClassLoader classLoader) {
     try {
-      classLoader = getTCL();
-
-      if (classLoader != null) {
-        // LogLog.debug(
-        // "Trying to find [" + resource + "] using context classloader "
-        // + classLoader + ".");
-        url = classLoader.getResource(resource);
-
-        if (url != null) {
-          return url;
-        }
-      }
-
-      // We could not find resource. Ler us now try with the
-      // classloader that loaded this class.
-      classLoader = Loader.class.getClassLoader();
-
-      if (classLoader != null) {
-        // LogLog.debug(
-        // "Trying to find [" + resource + "] using " + classLoader
-        // + " class loader.");
-        url = classLoader.getResource(resource);
-
-        if (url != null) {
-          return url;
-        }
-      }
+      return classLoader.getResource(resource);
     } catch (Throwable t) {
-      // LogLog.warn(TSTR, t);
+      return null;
     }
 
-    // Last ditch attempt: get the resource from the class path. It
-    // may be the case that clazz was loaded by the Extentsion class
-    // loader which the parent of the system class loader. Hence the
-    // code below.
-    // LogLog.debug(
-    // "Trying to find [" + resource
-    // + "] using ClassLoader.getSystemResource().");
-
-    return ClassLoader.getSystemResource(resource);
   }
 
-
   /**
    * Get the Thread Context Loader which is a JDK 1.2 feature. If we are running
    * under JDK 1.1 or anything else goes wrong the method returns
    * <code>null<code>.
    *
    */
-  private static ClassLoader getTCL() {
+  public static ClassLoader getTCL() {
     return Thread.currentThread().getContextClassLoader();
   }
 



More information about the logback-dev mailing list