[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.28-6-ga444d42

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Thu Feb 3 00:26:55 CET 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  a444d428421d4ccdd63b7347299bafecf170d844 (commit)
      from  a460c71cff87906385e2d4194e5eb369819b7f99 (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=a444d428421d4ccdd63b7347299bafecf170d844
http://github.com/ceki/logback/commit/a444d428421d4ccdd63b7347299bafecf170d844

commit a444d428421d4ccdd63b7347299bafecf170d844
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Thu Feb 3 00:23:31 2011 +0100

    better error message in IfAction when janono.jar is missing

diff --git a/logback-classic/integration.xml b/logback-classic/integration.xml
index 552e918..e0257cb 100644
--- a/logback-classic/integration.xml
+++ b/logback-classic/integration.xml
@@ -23,7 +23,8 @@
 
 
 
-	<target name="testAll" depends="testWithoutGroovy" unless="maven.test.skip">
+	<target name="testAll" depends="testWithoutGroovy, testConditionalsWithoutJanino" 
+          unless="maven.test.skip">
 	</target>
 
 
@@ -38,4 +39,18 @@
 		</junit>
 	</target>
 
+
+	<target name="testConditionalsWithoutJanino" unless="maven.test.skip">
+		<junit printsummary="yes" fork="no" haltonfailure="yes">
+			<classpath refid="basicClasspath" />
+			<formatter type="plain" />
+			<test fork="yes" todir="target/unit-reports" 
+            outfile="TEST-NoJanino" 
+            name="ch.qos.logback.classic.boolex.ConditionalWithoutJanino" />
+		</junit>
+	</target>
+
+
+
+
 </project>
\ No newline at end of file
diff --git a/logback-classic/src/test/input/joran/conditional/withoutJanino.xml b/logback-classic/src/test/input/joran/conditional/withoutJanino.xml
new file mode 100644
index 0000000..d506b04
--- /dev/null
+++ b/logback-classic/src/test/input/joran/conditional/withoutJanino.xml
@@ -0,0 +1,16 @@
+
+<configuration>
+
+  <if condition='property("HOSTNAME") != null'>
+    <then>
+      <root level="ERROR"/>
+    </then>
+    <else>
+      <root level="INFO"/>
+    </else>
+  </if>
+
+  <root level="WARN"/>
+
+
+</configuration>
\ No newline at end of file
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/boolex/ConditionalWithoutJanino.java b/logback-classic/src/test/java/ch/qos/logback/classic/boolex/ConditionalWithoutJanino.java
new file mode 100644
index 0000000..4dee365
--- /dev/null
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/boolex/ConditionalWithoutJanino.java
@@ -0,0 +1,44 @@
+package ch.qos.logback.classic.boolex;
+
+import ch.qos.logback.classic.ClassicTestConstants;
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.joran.conditional.IfAction;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.read.ListAppender;
+import ch.qos.logback.core.status.Status;
+import ch.qos.logback.core.status.StatusChecker;
+import ch.qos.logback.core.util.StatusPrinter;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Ceki G&uuml;c&uuml;
+ */
+public class ConditionalWithoutJanino {
+
+  LoggerContext loggerContext = new LoggerContext();
+  Logger root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
+
+  void configure(String file) throws JoranException {
+    JoranConfigurator jc = new JoranConfigurator();
+    jc.setContext(loggerContext);
+    jc.doConfigure(file);
+  }
+
+  // assume that janino.jar ia NOT on the classpath
+  @Test
+  public void condtionalWithoutJanino() throws JoranException {
+    configure(ClassicTestConstants.JORAN_INPUT_PREFIX + "conditional/withoutJanino.xml");
+    StatusPrinter.print(loggerContext);
+    StatusChecker checker = new StatusChecker(loggerContext);
+    assertTrue(checker.containsMatch(IfAction.MISSING_JANINO_MSG));
+    assertSame(Level.WARN, root.getLevel());
+  }
+
+}
+
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/IfAction.java b/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/IfAction.java
index b65a139..7a77f1a 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/IfAction.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/IfAction.java
@@ -3,6 +3,7 @@ package ch.qos.logback.core.joran.conditional;
 import java.util.List;
 import java.util.Stack;
 
+import ch.qos.logback.core.util.EnvUtil;
 import org.xml.sax.Attributes;
 
 import ch.qos.logback.core.joran.action.Action;
@@ -14,7 +15,8 @@ import ch.qos.logback.core.util.OptionHelper;
 
 public class IfAction extends Action {
   private static final String CONDITION_ATTR = "condition";
-  
+
+  public static String MISSING_JANINO_MSG = "Could not find Janino library on the class path. Skipping conditional processing.";
 
   Stack<IfState> stack = new Stack<IfState>();
   
@@ -30,11 +32,17 @@ public class IfAction extends Action {
       return;
     }
     
-    state.active = true;
     ic.pushObject(this);
-    
+    if(!EnvUtil.isJaninoAvailable()) {
+       addError(MISSING_JANINO_MSG);
+       return;
+     }
+
+    state.active = true;
     Condition condition = null;
     String conditionAttribute = attributes.getValue(CONDITION_ATTR);
+
+
     if (!OptionHelper.isEmpty(conditionAttribute)) {
       conditionAttribute = OptionHelper.substVars(conditionAttribute, context);
       PropertyEvalScriptBuilder pesb = new PropertyEvalScriptBuilder();
diff --git a/logback-core/src/main/java/ch/qos/logback/core/util/EnvUtil.java b/logback-core/src/main/java/ch/qos/logback/core/util/EnvUtil.java
new file mode 100644
index 0000000..165e52a
--- /dev/null
+++ b/logback-core/src/main/java/ch/qos/logback/core/util/EnvUtil.java
@@ -0,0 +1,42 @@
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2010, QOS.ch. All rights reserved.
+ *
+ * This program and the accompanying materials are dual-licensed under
+ * either the terms of the Eclipse Public License v1.0 as published by
+ * the Eclipse Foundation
+ *
+ *   or (per the licensee's choosing)
+ *
+ * under the terms of the GNU Lesser General Public License version 2.1
+ * as published by the Free Software Foundation.
+ */
+package ch.qos.logback.core.util;
+
+/**
+ * @author Ceki G&uuml;c&uuml;
+ */
+public class EnvUtil {
+
+
+  static public boolean isGroovyAvailable() {
+    ClassLoader classLoader = EnvUtil.class.getClassLoader();
+    try {
+      Class bindingClass = classLoader.loadClass("groovy.lang.Binding");
+      return (bindingClass != null);
+    } catch (ClassNotFoundException e) {
+      return false;
+    }
+  }
+
+
+  static public boolean isJaninoAvailable() {
+    ClassLoader classLoader = EnvUtil.class.getClassLoader();
+    try {
+      Class bindingClass = classLoader.loadClass("org.codehaus.janino.Cookable");
+      return (bindingClass != null);
+    } catch (ClassNotFoundException e) {
+      return false;
+    }
+  }
+}

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

Summary of changes:
 logback-classic/integration.xml                    |   17 ++++-
 .../test/input/joran/conditional/withoutJanino.xml |   16 ++++
 .../classic/boolex/ConditionalWithoutJanino.java   |   44 ++++++++++++
 .../logback/core/joran/conditional/IfAction.java   |   14 +++-
 .../java/ch/qos/logback/core}/util/EnvUtil.java    |   74 +++++++++++---------
 5 files changed, 129 insertions(+), 36 deletions(-)
 create mode 100644 logback-classic/src/test/input/joran/conditional/withoutJanino.xml
 create mode 100644 logback-classic/src/test/java/ch/qos/logback/classic/boolex/ConditionalWithoutJanino.java
 copy {logback-classic/src/main/java/ch/qos/logback/classic => logback-core/src/main/java/ch/qos/logback/core}/util/EnvUtil.java (63%)


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


More information about the logback-dev mailing list