[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.29-24-g75da45d

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Thu Sep 8 22:26:31 CEST 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".

The branch, master has been updated
       via  75da45d0f69a3877de3b3ab669c50ea6837ec996 (commit)
      from  039eb9e9b9987b36f4e44fdab7967aea71810cd2 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=75da45d0f69a3877de3b3ab669c50ea6837ec996
http://github.com/ceki/logback/commit/75da45d0f69a3877de3b3ab669c50ea6837ec996

commit 75da45d0f69a3877de3b3ab669c50ea6837ec996
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Thu Sep 8 22:25:06 2011 +0200

    LBCLASSIC-263 and LBCLASSIC-292

diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/spi/PackagingDataCalculator.java b/logback-classic/src/main/java/ch/qos/logback/classic/spi/PackagingDataCalculator.java
index c2d4da5..f9c5ba8 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/spi/PackagingDataCalculator.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/spi/PackagingDataCalculator.java
@@ -16,12 +16,12 @@ package ch.qos.logback.classic.spi;
 import java.net.URL;
 import java.util.HashMap;
 
+import ch.qos.logback.core.util.Loader;
 import sun.reflect.Reflection;
-
+// import java.security.AccessControlException; import java.security.AccessController;import java.security.PrivilegedAction;
 /**
- * 
  * Given a classname locate associated PackageInfo (jar name, version name).
- * 
+ *
  * @author James Strachan
  * @Ceki G&uuml;lc&uuml;
  */
@@ -31,7 +31,7 @@ public class PackagingDataCalculator {
 
   HashMap<String, ClassPackagingData> cache = new HashMap<String, ClassPackagingData>();
 
-  private static boolean GET_CALLER_CLASS_METHOD_AVAILABLE = false;
+  private static boolean GET_CALLER_CLASS_METHOD_AVAILABLE = false; //private static boolean HAS_GET_CLASS_LOADER_PERMISSION = false;
 
   static {
     // if either the Reflection class or the getCallerClass method
@@ -50,6 +50,7 @@ public class PackagingDataCalculator {
     }
   }
 
+
   public PackagingDataCalculator() {
   }
 
@@ -66,7 +67,7 @@ public class PackagingDataCalculator {
     final Throwable t = new Throwable("local stack reference");
     final StackTraceElement[] localteSTEArray = t.getStackTrace();
     final int commonFrames = STEUtil.findNumberOfCommonFrames(localteSTEArray,
-        stepArray);
+            stepArray);
     final int localFirstCommon = localteSTEArray.length - commonFrames;
     final int stepFirstCommon = stepArray.length - commonFrames;
 
@@ -78,12 +79,13 @@ public class PackagingDataCalculator {
       Class callerClass = null;
       if (GET_CALLER_CLASS_METHOD_AVAILABLE) {
         callerClass = Reflection.getCallerClass(localFirstCommon + i
-            - missfireCount + 1);
+                - missfireCount + 1);
       }
       StackTraceElementProxy step = stepArray[stepFirstCommon + i];
       String stepClassname = step.ste.getClassName();
 
       if (callerClass != null && stepClassname.equals(callerClass.getName())) {
+        // see also LBCLASSIC-263
         lastExactClassLoader = callerClass.getClassLoader();
         if (firsExactClassLoader == null) {
           firsExactClassLoader = lastExactClassLoader;
@@ -100,7 +102,7 @@ public class PackagingDataCalculator {
   }
 
   void populateUncommonFrames(int commonFrames,
-      StackTraceElementProxy[] stepArray, ClassLoader firstExactClassLoader) {
+                              StackTraceElementProxy[] stepArray, ClassLoader firstExactClassLoader) {
     int uncommonFrames = stepArray.length - commonFrames;
     for (int i = 0; i < uncommonFrames; i++) {
       StackTraceElementProxy step = stepArray[i];
@@ -123,7 +125,7 @@ public class PackagingDataCalculator {
   }
 
   private ClassPackagingData computeBySTEP(StackTraceElementProxy step,
-      ClassLoader lastExactClassLoader) {
+                                           ClassLoader lastExactClassLoader) {
     String className = step.ste.getClassName();
     ClassPackagingData cpd = cache.get(className);
     if (cpd != null) {
@@ -208,15 +210,12 @@ public class PackagingDataCalculator {
   }
 
   /**
-   * 
-   * @param lastGuaranteedClassLoader
-   *                may be null
-   * 
+   * @param lastGuaranteedClassLoader may be null
    * @param className
    * @return
    */
   private Class bestEffortLoadClass(ClassLoader lastGuaranteedClassLoader,
-      String className) {
+                                    String className) {
     Class result = loadClass(lastGuaranteedClassLoader, className);
     if (result != null) {
       return result;
diff --git a/logback-classic/src/test/input/joran/conditional/conditionalIncludeExistingFile.xml b/logback-classic/src/test/input/joran/conditional/conditionalIncludeExistingFile.xml
new file mode 100644
index 0000000..f39b5f5
--- /dev/null
+++ b/logback-classic/src/test/input/joran/conditional/conditionalIncludeExistingFile.xml
@@ -0,0 +1,14 @@
+
+<configuration>
+
+  <define name="INCLUDED_FILE_EXISTS" 
+          class="ch.qos.logback.core.property.FileExistsPropertyDefiner">
+      <path>src/test/input/joran/conditional/includedFile.xml</path>
+  </define>
+  
+   <if condition='property("INCLUDED_FILE_EXISTS").equals("true")'>
+    <then>
+        <include file="src/test/input/joran/conditional/includedFile.xml"/>
+    </then>
+  </if> 
+</configuration>
\ No newline at end of file
diff --git a/logback-classic/src/test/input/joran/conditional/conditionalIncludeInexistentFile.xml b/logback-classic/src/test/input/joran/conditional/conditionalIncludeInexistentFile.xml
new file mode 100644
index 0000000..6cbf0af
--- /dev/null
+++ b/logback-classic/src/test/input/joran/conditional/conditionalIncludeInexistentFile.xml
@@ -0,0 +1,14 @@
+
+<configuration>
+
+  <define name="INCLUDED_FILE_EXISTS" 
+          class="ch.qos.logback.core.property.FileExistsPropertyDefiner">
+      <path>src/test/input/joran/conditional/inexistent.xml</path>
+  </define>
+  
+   <if condition='property("INCLUDED_FILE_EXISTS").equals("true")'>
+    <then>
+        <include file="src/test/input/joran/conditional/inexistent.xml"/>
+    </then>
+  </if> 
+</configuration>
\ No newline at end of file
diff --git a/logback-classic/src/test/input/joran/conditional/includedFile.xml b/logback-classic/src/test/input/joran/conditional/includedFile.xml
new file mode 100644
index 0000000..703102c
--- /dev/null
+++ b/logback-classic/src/test/input/joran/conditional/includedFile.xml
@@ -0,0 +1,10 @@
+<included>
+  <appender name="CON" class="ch.qos.logback.core.ConsoleAppender">
+    <encoder>
+      <pattern>%d %-5level %logger{35} - %msg %n</pattern>
+    </encoder>
+  </appender>
+  <root>
+    <appender-ref ref="CON"/>
+  </root>
+</included>
\ No newline at end of file
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/joran/conditional/ConditionalTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/joran/conditional/ConditionalTest.java
index 1d4ee9c..0fe480e 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/joran/conditional/ConditionalTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/joran/conditional/ConditionalTest.java
@@ -123,4 +123,35 @@ public class ConditionalTest {
     assertTrue(checker.isErrorFree(0));
   }
 
+  @Test
+  public void conditionalInclusionWithExistingFile() throws JoranException,
+           IOException, InterruptedException {
+
+     String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX
+             + "conditional/conditionalIncludeExistingFile.xml";
+     configure(configFileAsStr);
+
+     StatusPrinter.print(context);
+     ConsoleAppender consoleAppender = (ConsoleAppender) root.getAppender("CON");
+     assertNotNull(consoleAppender);
+     StatusChecker checker = new StatusChecker(context);
+     assertTrue(checker.isErrorFree(0));
+   }
+  @Test
+
+  public void conditionalInclusionWithInexistentFile() throws JoranException,
+           IOException, InterruptedException {
+
+     String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX
+             + "conditional/conditionalIncludeInexistentFile.xml";
+     configure(configFileAsStr);
+
+     StatusPrinter.print(context);
+     ConsoleAppender consoleAppender = (ConsoleAppender) root.getAppender("CON");
+     assertNull(consoleAppender);
+     StatusChecker checker = new StatusChecker(context);
+     assertTrue(checker.isErrorFree(0));
+   }
+
+
 }
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/action/DefinePropertyAction.java b/logback-core/src/main/java/ch/qos/logback/core/joran/action/DefinePropertyAction.java
index aba52e3..b805334 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/action/DefinePropertyAction.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/action/DefinePropertyAction.java
@@ -91,8 +91,12 @@ public class DefinePropertyAction extends Action {
       addInfo("Popping property definer for property named [" + propertyName
           + "] from the object stack");
       ec.popObject();
-      // let's put defined property and value to context
-      context.putProperty(propertyName, definer.getPropertyValue());
+      // let's put defined property and value to context but only if it is
+      // not null
+      String propertyValue = definer.getPropertyValue();
+      if(propertyValue != null) {
+        context.putProperty(propertyName, propertyValue);
+      }
     }
   }
 }
diff --git a/logback-core/src/main/java/ch/qos/logback/core/property/FileExistsPropertyDefiner.java b/logback-core/src/main/java/ch/qos/logback/core/property/FileExistsPropertyDefiner.java
new file mode 100644
index 0000000..89b16e7
--- /dev/null
+++ b/logback-core/src/main/java/ch/qos/logback/core/property/FileExistsPropertyDefiner.java
@@ -0,0 +1,31 @@
+package ch.qos.logback.core.property;
+
+import ch.qos.logback.core.PropertyDefinerBase;
+import java.io.File;
+
+/**
+ * @author Ceki G&uuml;c&uuml;
+ */
+public class FileExistsPropertyDefiner extends PropertyDefinerBase {
+
+  String path;
+
+  public String getPath() {
+    return path;
+  }
+
+  public void setPath(String path) {
+    this.path = path;
+  }
+
+  public String getPropertyValue() {
+    if(path == null)
+      return "false";
+    File file = new File(path);
+    System.out.println(file.getAbsolutePath());
+    if(file.exists())
+      return "true";
+    else
+    return "false";
+  }
+}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java b/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java
index cd610a3..feade42 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/util/Loader.java
@@ -15,6 +15,9 @@ package ch.qos.logback.core.util;
 
 import java.io.IOException;
 import java.net.URL;
+import java.security.AccessControlException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;
@@ -23,7 +26,7 @@ import ch.qos.logback.core.Context;
 
 /**
  * Load resources (or images) from various sources.
- * 
+ *
  * @author Ceki G&uuml;lc&uuml;
  */
 public class Loader {
@@ -31,28 +34,41 @@ public class Loader {
 
   private static boolean ignoreTCL = false;
   public static final String IGNORE_TCL_PROPERTY_NAME = "logback.ignoreTCL";
+  private static boolean HAS_GET_CLASS_LOADER_PERMISSION = false;
 
   static {
-
     String ignoreTCLProp = OptionHelper.getSystemProperty(
-        IGNORE_TCL_PROPERTY_NAME, null);
+            IGNORE_TCL_PROPERTY_NAME, null);
 
     if (ignoreTCLProp != null) {
       ignoreTCL = OptionHelper.toBoolean(ignoreTCLProp, true);
     }
+
+    HAS_GET_CLASS_LOADER_PERMISSION =
+            AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+              public Boolean run() {
+                try {
+                  AccessController.checkPermission(
+                          new RuntimePermission("getClassLoader"));
+                  return true;
+                } catch (AccessControlException e) {
+                  return false;
+                }
+              }
+            });
   }
 
   /**
    * Compute the number of occurrences a resource can be found by a class
    * loader.
-   * 
+   *
    * @param resource
    * @param classLoader
    * @return
    * @throws IOException
    */
   public static List<URL> getResourceOccurenceCount(String resource,
-      ClassLoader classLoader) throws IOException {
+                                                    ClassLoader classLoader) throws IOException {
     List<URL> urlList = new ArrayList<URL>();
     Enumeration<URL> urlEnum = classLoader.getResources(resource);
     while (urlEnum.hasMoreElements()) {
@@ -65,11 +81,9 @@ public class Loader {
 
   /**
    * Search for a resource using the classloader passed as parameter.
-   * 
-   * @param resource
-   *                the resource name to look for
-   * @param classLoader
-   *                the classloader used for the search
+   *
+   * @param resource    the resource name to look for
+   * @param classLoader the classloader used for the search
    */
   public static URL getResource(String resource, ClassLoader classLoader) {
     try {
@@ -82,7 +96,7 @@ public class Loader {
   /**
    * Attempt to find a resource by using the classloader that loaded this class,
    * namely Loader.class.
-   * 
+   *
    * @param resource
    * @return
    */
@@ -98,14 +112,13 @@ public class Loader {
    * 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>.
-   *
    */
   public static ClassLoader getTCL() {
     return Thread.currentThread().getContextClassLoader();
   }
 
   public static Class loadClass(String clazz, Context context)
-      throws ClassNotFoundException {
+          throws ClassNotFoundException {
     ClassLoader cl = getClassLoaderOfObject(context);
     return cl.loadClass(clazz);
   }
@@ -113,7 +126,7 @@ public class Loader {
   /**
    * Get the class loader of the object passed as argument. Return the system
    * class loader if appropriate.
-   * 
+   *
    * @param o
    * @return
    */
@@ -125,13 +138,30 @@ public class Loader {
   }
 
   /**
+   * Returns the class loader of clazz if
+   * @param clazz
+   * @return
+   */
+  public static ClassLoader getClassLoaderAsPrivileged(final Class clazz) {
+    if (!HAS_GET_CLASS_LOADER_PERMISSION)
+      return null;
+    else
+      return AccessController.doPrivileged(
+              new PrivilegedAction<ClassLoader>() {
+                public ClassLoader run() {
+                  return clazz.getClassLoader();
+                }
+              });
+  }
+
+  /**
    * Return the class loader which loaded the class passed as argument. Return
    * the system class loader if appropriate.
-   * 
+   *
    * @param clazz
    * @return
    */
-  public static ClassLoader getClassLoaderOfClass(Class clazz) {
+  public static ClassLoader getClassLoaderOfClass(final Class clazz) {
     ClassLoader cl = clazz.getClassLoader();
     if (cl == null) {
       return ClassLoader.getSystemClassLoader();
@@ -144,7 +174,6 @@ public class Loader {
    * If running under JDK 1.2 load the specified class using the
    * <code>Thread</code> <code>contextClassLoader</code> if that fails try
    * Class.forname. Under JDK 1.1 only Class.forName is used.
-   * 
    */
   public static Class loadClass(String clazz) throws ClassNotFoundException {
     // Just call Class.forName(clazz) if we are running under JDK 1.1

-----------------------------------------------------------------------

Summary of changes:
 .../classic/spi/PackagingDataCalculator.java       |   25 ++++----
 .../conditional/conditionalIncludeExistingFile.xml |   14 ++++
 .../conditionalIncludeInexistentFile.xml           |   14 ++++
 .../test/input/joran/conditional/includedFile.xml  |   10 +++
 .../classic/joran/conditional/ConditionalTest.java |   31 ++++++++++
 .../core/joran/action/DefinePropertyAction.java    |    8 ++-
 .../core/property/FileExistsPropertyDefiner.java   |   31 ++++++++++
 .../main/java/ch/qos/logback/core/util/Loader.java |   63 ++++++++++++++-----
 8 files changed, 164 insertions(+), 32 deletions(-)
 create mode 100644 logback-classic/src/test/input/joran/conditional/conditionalIncludeExistingFile.xml
 create mode 100644 logback-classic/src/test/input/joran/conditional/conditionalIncludeInexistentFile.xml
 create mode 100644 logback-classic/src/test/input/joran/conditional/includedFile.xml
 create mode 100644 logback-core/src/main/java/ch/qos/logback/core/property/FileExistsPropertyDefiner.java


hooks/post-receive
-- 
Logback: the generic, reliable, fast and flexible logging framework.


More information about the logback-dev mailing list