[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. release_0.9.19-9-gdb3e3e2

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Tue Mar 30 18:41:27 CEST 2010


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  db3e3e278df194d84b0259458515b9709fe0510d (commit)
      from  c9f58e8f6a1372a08fef830ac1c3e8faa38c5abf (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=db3e3e278df194d84b0259458515b9709fe0510d
http://github.com/ceki/logback/commit/db3e3e278df194d84b0259458515b9709fe0510d

commit db3e3e278df194d84b0259458515b9709fe0510d
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Tue Mar 30 18:38:48 2010 +0200

    - added support for <if> statement nested within <if> statements or
      or <include> statement nested <if> statements or <if> nested within
      <include>

diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/ElseAction.java b/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/ElseAction.java
index 63ede3f..83db5ee 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/ElseAction.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/ElseAction.java
@@ -1,44 +1,28 @@
+/**
+ * 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.joran.conditional;
 
-import java.util.ArrayList;
 import java.util.List;
 
-import org.xml.sax.Attributes;
-
-import ch.qos.logback.core.joran.action.Action;
-import ch.qos.logback.core.joran.event.InPlayListener;
 import ch.qos.logback.core.joran.event.SaxEvent;
-import ch.qos.logback.core.joran.spi.ActionException;
-import ch.qos.logback.core.joran.spi.InterpretationContext;
-
-public class ElseAction  extends Action implements InPlayListener {
 
-  List<SaxEvent> saxEventList;
-  
-  @Override
-  public void begin(InterpretationContext ic, String name, Attributes attributes)
-      throws ActionException {
-    saxEventList = new ArrayList<SaxEvent>();
-    ic.addInPlayListener(this);
-  }
+public class ElseAction  extends ThenOrElseActionBase {
 
   @Override
-  public void end(InterpretationContext ic, String name) throws ActionException {
-    ic.removeInPlayListener(this);
-    Object o = ic.peekObject();
-    if (o instanceof IfAction) {
-      IfAction ifAction = (IfAction) o;
-      removeFirstLastFromList();
-      ifAction.setElseSaxEventList(saxEventList);
-    }
+  void registerEventList(IfAction ifAction, List<SaxEvent> eventList) {
+   ifAction.setElseSaxEventList(eventList);
+    
   }
 
-  public void inPlay(SaxEvent event) {
-    saxEventList.add(event);
-  }
-
-  void removeFirstLastFromList() {
-    saxEventList.remove(0);
-    saxEventList.remove(saxEventList.size() - 1);
-  }
 }
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 2c35649..7898f4d 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
@@ -1,6 +1,7 @@
 package ch.qos.logback.core.joran.conditional;
 
 import java.util.List;
+import java.util.Stack;
 
 import org.xml.sax.Attributes;
 
@@ -14,14 +15,22 @@ import ch.qos.logback.core.util.OptionHelper;
 public class IfAction extends Action {
   private static final String CONDITION_ATTR = "condition";
   
-  Boolean boolResult;
-  List<SaxEvent> thenSaxEventList;
-  List<SaxEvent> elseSaxEventList;
 
+  Stack<IfState> stack = new Stack<IfState>();
+  
   @Override
   public void begin(InterpretationContext ic, String name, Attributes attributes)
       throws ActionException {
 
+    IfState state = new IfState();
+    boolean emptyStack = stack.isEmpty();
+    stack.push(state);
+
+    if(!emptyStack) {
+      return;
+    }
+    
+    state.active = true;
     ic.pushObject(this);
     
     Condition condition = null;
@@ -37,7 +46,7 @@ public class IfAction extends Action {
       }
      
       if(condition!=null) {
-        boolResult = condition.evaluate();
+        state.boolResult = condition.evaluate();
       }
       
     }
@@ -47,6 +56,12 @@ public class IfAction extends Action {
   @Override
   public void end(InterpretationContext ic, String name) throws ActionException {
 
+    IfState state = stack.pop();
+    if(!state.active) {
+      return;
+    }
+   
+    
     Object o = ic.peekObject();
     if (o == null) {
       throw new IllegalStateException("Unexpected null object on stack");
@@ -62,15 +77,15 @@ public class IfAction extends Action {
     }
     ic.popObject();
 
-    if (boolResult == null) {
+    if (state.boolResult == null) {
       addError("Failed to determine \"if then else\" result");
       return;
     }
 
     Interpreter interpreter = ic.getJoranInterpreter();
-    List<SaxEvent> listToPlay = thenSaxEventList;
-    if (!boolResult) {
-      listToPlay = elseSaxEventList;
+    List<SaxEvent> listToPlay = state.thenSaxEventList;
+    if (!state.boolResult) {
+      listToPlay = state.elseSaxEventList;
     }
     
     // insert past this event
@@ -80,11 +95,29 @@ public class IfAction extends Action {
 
 
   public void setThenSaxEventList(List<SaxEvent> thenSaxEventList) {
-    this.thenSaxEventList = thenSaxEventList;
+    IfState state = stack.firstElement();
+    if(state.active) {
+      state.thenSaxEventList = thenSaxEventList;
+    } else {
+      throw new IllegalStateException("setThenSaxEventList() invoked on inactive IfAction");
+    }
   }
 
   public void setElseSaxEventList(List<SaxEvent> elseSaxEventList) {
-    this.elseSaxEventList = elseSaxEventList;
+    IfState state = stack.firstElement();
+    if(state.active) {
+      state.elseSaxEventList = elseSaxEventList;
+    } else {
+      throw new IllegalStateException("setElseSaxEventList() invoked on inactive IfAction");
+    }
+
   }
 
 }
+
+class IfState {
+  Boolean boolResult;
+  List<SaxEvent> thenSaxEventList;
+  List<SaxEvent> elseSaxEventList;
+  boolean active;
+}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/ThenAction.java b/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/ThenAction.java
index 5e5f99b..4a95833 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/ThenAction.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/ThenAction.java
@@ -1,46 +1,28 @@
+/**
+ * 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.joran.conditional;
 
-import java.util.ArrayList;
 import java.util.List;
 
-import org.xml.sax.Attributes;
-
-import ch.qos.logback.core.joran.action.Action;
-import ch.qos.logback.core.joran.event.InPlayListener;
 import ch.qos.logback.core.joran.event.SaxEvent;
-import ch.qos.logback.core.joran.spi.ActionException;
-import ch.qos.logback.core.joran.spi.InterpretationContext;
-
-public class ThenAction  extends Action implements InPlayListener {
 
-  List<SaxEvent> eventList;
-  
-  @Override
-  public void begin(InterpretationContext ic, String name, Attributes attributes)
-      throws ActionException {
-    eventList = new ArrayList<SaxEvent>();
-    ic.addInPlayListener(this);
-  }
+public class ThenAction  extends ThenOrElseActionBase {
 
   @Override
-  public void end(InterpretationContext ic, String name) throws ActionException {
-    ic.removeInPlayListener(this);
-    Object o = ic.peekObject();
-    if (o instanceof IfAction) {
-      IfAction ifAction = (IfAction) o;
-      removeFirstLastFromList();
-      ifAction.setThenSaxEventList(eventList);
-    } else {
-      throw new IllegalStateException("Missing IfAction on top of stack");
-    }
+  void registerEventList(IfAction ifAction, List<SaxEvent> eventList) {
+   ifAction.setThenSaxEventList(eventList);
+    
   }
 
-  public void inPlay(SaxEvent event) {
-    eventList.add(event);
-  }
-
-  void removeFirstLastFromList() {
-    eventList.remove(0);
-    eventList.remove(eventList.size() - 1);
-  }
 }
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/ThenOrElseActionBase.java b/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/ThenOrElseActionBase.java
new file mode 100644
index 0000000..1b52a8c
--- /dev/null
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/conditional/ThenOrElseActionBase.java
@@ -0,0 +1,76 @@
+/**
+ * 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.joran.conditional;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Stack;
+
+import org.xml.sax.Attributes;
+
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.event.InPlayListener;
+import ch.qos.logback.core.joran.event.SaxEvent;
+import ch.qos.logback.core.joran.spi.ActionException;
+import ch.qos.logback.core.joran.spi.InterpretationContext;
+
+abstract public class ThenOrElseActionBase extends Action {
+
+  Stack<ThenActionState> stateStack = new Stack<ThenActionState>();
+
+  @Override
+  public void begin(InterpretationContext ic, String name, Attributes attributes)
+      throws ActionException {
+    ThenActionState state = new ThenActionState();
+    if (ic.isListenerListEmpty()) {
+      ic.addInPlayListener(state);
+      state.isRegistered = true;
+    }
+    stateStack.push(state);
+  }
+
+  @Override
+  public void end(InterpretationContext ic, String name) throws ActionException {
+    ThenActionState state = stateStack.pop();
+    if (state.isRegistered) {
+      ic.removeInPlayListener(state);
+      Object o = ic.peekObject();
+      if (o instanceof IfAction) {
+        IfAction ifAction = (IfAction) o;
+        removeFirstAndLastFromList(state.eventList);
+        registerEventList(ifAction, state.eventList);
+      } else {
+        throw new IllegalStateException("Missing IfAction on top of stack");
+      }
+    }
+  }
+  
+  abstract void registerEventList(IfAction ifAction, List<SaxEvent> eventList);
+
+  void removeFirstAndLastFromList(List<SaxEvent> eventList) {
+    eventList.remove(0);
+    eventList.remove(eventList.size() - 1);
+  }
+
+}
+
+class ThenActionState implements InPlayListener {
+
+  List<SaxEvent> eventList = new ArrayList<SaxEvent>();
+  boolean isRegistered = false;
+  
+  public void inPlay(SaxEvent event) {
+    eventList.add(event);
+  }
+}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/spi/InterpretationContext.java b/logback-core/src/main/java/ch/qos/logback/core/joran/spi/InterpretationContext.java
index ccdc9a3..a594014 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/spi/InterpretationContext.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/spi/InterpretationContext.java
@@ -173,6 +173,13 @@ public class InterpretationContext extends ContextAwareBase implements
     return OptionHelper.substVars(value, this);
   }
 
+
+  
+
+  public boolean isListenerListEmpty() {
+    return listenerList.isEmpty();
+  }
+  
   public void addInPlayListener(InPlayListener ipl) {
     if (listenerList.contains(ipl)) {
       addWarn("InPlayListener " + ipl + " has been already registered");
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Interpreter.java b/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Interpreter.java
index b720312..599c776 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Interpreter.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Interpreter.java
@@ -337,29 +337,6 @@ public class Interpreter {
       player.addEventsDynamically(eventList, offset);
     }
   }
-
-  /**
-   * Pop from the stack if the top most element matches 'name'. Returns whether
-   * the top most element matched.
-   * 
-   * @param name
-   * @return whether the top most element matched 'name'
-   */
-  public boolean popIfMatch(String name) {
-    boolean match = pattern.peekLast().equals(name);
-    if (match) {
-      pattern.pop();
-    }
-    return match;
-  }
-  
-  /**
-   * Intended for internal use.
-   * @param name
-   */
-  public void patternPush(String name) {
-    pattern.push(name);
-  }
 }
 
 /**
diff --git a/logback-core/src/test/input/joran/conditional/if0.xml b/logback-core/src/test/input/joran/conditional/if0.xml
index 0273e59..b843dcc 100644
--- a/logback-core/src/test/input/joran/conditional/if0.xml
+++ b/logback-core/src/test/input/joran/conditional/if0.xml
@@ -1,13 +1,14 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 
 <x>
+  <stack name="BEGIN"/>
   <if condition='p("Ki1").equals("Val1")'>
     <then>
-      <inc increment="1"/>
+      <stack name="a"/>
     </then>
     <else>
-      <inc increment="1"/>
-      <inc increment="1"/>
+      <stack name="b"/>
     </else>
   </if>
+  <stack name="END"/>
 </x>
diff --git a/logback-core/src/test/input/joran/conditional/if2.xml b/logback-core/src/test/input/joran/conditional/if2.xml
deleted file mode 100644
index bc70e1f..0000000
--- a/logback-core/src/test/input/joran/conditional/if2.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-
-<x>
-  <if class="">
-    <a>asd</a>
-    <then>
-      <inc increment="1"/>
-    </then>
-    <else>
-      <inc increment="1"/>
-      <inc increment="1"/>
-    </else>
-  </if>
-</x>
diff --git a/logback-core/src/test/input/joran/inclusion/included.xml b/logback-core/src/test/input/joran/conditional/includedA.xml
similarity index 51%
copy from logback-core/src/test/input/joran/inclusion/included.xml
copy to logback-core/src/test/input/joran/conditional/includedA.xml
index 7dfb5fe..ecb4360 100644
--- a/logback-core/src/test/input/joran/inclusion/included.xml
+++ b/logback-core/src/test/input/joran/conditional/includedA.xml
@@ -2,8 +2,6 @@
 <!DOCTYPE included>
 
 <included>
-
-  <inc increment="1"/>
-  <inc increment="1"/>
-  
+  <stack name="IncludedA0"/>
+  <stack name="IncludedA1"/>
 </included>
\ No newline at end of file
diff --git a/logback-core/src/test/input/joran/inclusion/second.xml b/logback-core/src/test/input/joran/conditional/includedB.xml
similarity index 63%
copy from logback-core/src/test/input/joran/inclusion/second.xml
copy to logback-core/src/test/input/joran/conditional/includedB.xml
index 3351857..84974b7 100644
--- a/logback-core/src/test/input/joran/inclusion/second.xml
+++ b/logback-core/src/test/input/joran/conditional/includedB.xml
@@ -2,7 +2,5 @@
 <!DOCTYPE included>
 
 <included>
-
-  <inc increment="1"/>
-  
+  <stack name="IncludedB0"/>  
 </included>
\ No newline at end of file
diff --git a/logback-core/src/test/input/joran/conditional/nestedIf.xml b/logback-core/src/test/input/joran/conditional/nestedIf.xml
new file mode 100644
index 0000000..0751237
--- /dev/null
+++ b/logback-core/src/test/input/joran/conditional/nestedIf.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+
+<x>
+  <stack name="BEGIN"/>
+
+  <if condition='1 == 1'>
+    <then>
+      <stack name="a"/>
+      <if condition='1 != 1'>
+        <then>
+          <stack name="b"/>
+        </then>
+        <else>
+          <stack name="c"/>
+        </else>
+      </if>
+    </then>
+    <else>
+      <stack name="d"/>
+    </else>
+  </if>
+  <stack name="END"/>
+
+</x>
+
diff --git a/logback-core/src/test/input/joran/conditional/nestedInclude.xml b/logback-core/src/test/input/joran/conditional/nestedInclude.xml
new file mode 100644
index 0000000..4aa8617
--- /dev/null
+++ b/logback-core/src/test/input/joran/conditional/nestedInclude.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+
+<x>
+  <stack name="BEGIN"/>
+
+  <if condition='1 != 1'>
+    <then>
+      <stack name="t0"/>
+      <include file="${thenFileToInclude}"/>
+      <stack name="t1"/>
+    </then>
+    <else>
+      <stack name="e0"/>
+      <include file="${elseFileToInclude}"/>
+      <stack name="e1"/>
+    </else>
+  </if>
+  <stack name="END"/>
+
+</x>
+
diff --git a/logback-core/src/test/input/joran/inclusion/included.xml b/logback-core/src/test/input/joran/inclusion/included.xml
index 7dfb5fe..8ce1cd1 100644
--- a/logback-core/src/test/input/joran/inclusion/included.xml
+++ b/logback-core/src/test/input/joran/inclusion/included.xml
@@ -3,7 +3,7 @@
 
 <included>
 
-  <inc increment="1"/>
-  <inc increment="1"/>
+  <stack name="IA"/>
+  <stack name="IB"/>
   
 </included>
\ No newline at end of file
diff --git a/logback-core/src/test/input/joran/inclusion/intermediaryByFile.xml b/logback-core/src/test/input/joran/inclusion/intermediaryByFile.xml
new file mode 100644
index 0000000..dce2acb
--- /dev/null
+++ b/logback-core/src/test/input/joran/inclusion/intermediaryByFile.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE x>
+
+<included>
+  <stack name="a"/>
+  <include file="${subFileKey}" />
+  <stack name="c"/>
+</included>
diff --git a/logback-core/src/test/input/joran/inclusion/second.xml b/logback-core/src/test/input/joran/inclusion/second.xml
index 3351857..32beaf0 100644
--- a/logback-core/src/test/input/joran/inclusion/second.xml
+++ b/logback-core/src/test/input/joran/inclusion/second.xml
@@ -3,6 +3,6 @@
 
 <included>
 
-  <inc increment="1"/>
+  <stack name="SECOND"/>
   
 </included>
\ No newline at end of file
diff --git a/logback-core/src/test/input/joran/inclusion/subByFile.xml b/logback-core/src/test/input/joran/inclusion/subByFile.xml
index 5f82d77..b351583 100644
--- a/logback-core/src/test/input/joran/inclusion/subByFile.xml
+++ b/logback-core/src/test/input/joran/inclusion/subByFile.xml
@@ -1,6 +1,3 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE included>
-
 <included>
-  <include file="${includeKey}" />
-</<included>
+  <stack name="b"/>
+</included>
diff --git a/logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java b/logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java
index d65ac45..ad7a3f6 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java
@@ -23,7 +23,9 @@ import org.junit.runners.Suite.SuiteClasses;
   ch.qos.logback.core.joran.util.PackageTest.class,
   ch.qos.logback.core.joran.spi.PackageTest.class,
   ch.qos.logback.core.joran.replay.PackageTest.class,
-  ch.qos.logback.core.joran.implicitAction.PackageTest.class
+  ch.qos.logback.core.joran.implicitAction.PackageTest.class,
+  ch.qos.logback.core.joran.conditional.PackageTest.class,
+  
  })
 public class PackageTest {
 
diff --git a/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncludeActionTest.java b/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncludeActionTest.java
index 372a00b..1f31383 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncludeActionTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncludeActionTest.java
@@ -23,7 +23,9 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.UnknownHostException;
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.Stack;
 
 import org.junit.After;
 import org.junit.Before;
@@ -33,7 +35,7 @@ import org.xml.sax.SAXParseException;
 import ch.qos.logback.core.Context;
 import ch.qos.logback.core.ContextBase;
 import ch.qos.logback.core.joran.TrivialConfigurator;
-import ch.qos.logback.core.joran.action.ext.IncAction;
+import ch.qos.logback.core.joran.action.ext.StackAction;
 import ch.qos.logback.core.joran.spi.JoranException;
 import ch.qos.logback.core.joran.spi.Pattern;
 import ch.qos.logback.core.status.Status;
@@ -57,6 +59,9 @@ public class IncludeActionTest {
 
   static final String TOP_BY_FILE = INCLUSION_DIR_PREFIX + "topByFile.xml";
 
+  static final String INTERMEDIARY_FILE = INCLUSION_DIR_PREFIX + "intermediaryByFile.xml";
+
+  
   static final String SUB_FILE = INCLUSION_DIR_PREFIX + "subByFile.xml";
 
   static final String MULTI_INCLUDE_BY_FILE = INCLUSION_DIR_PREFIX
@@ -82,43 +87,42 @@ public class IncludeActionTest {
   public void setUp() throws Exception {
     HashMap<Pattern, Action> rulesMap = new HashMap<Pattern, Action>();
     rulesMap.put(new Pattern("x"), new NOPAction());
-    rulesMap.put(new Pattern("x/inc"), new IncAction());
     rulesMap.put(new Pattern("x/include"), new IncludeAction());
-
+    rulesMap.put(new Pattern("x/stack"), new StackAction());
+    
     tc = new TrivialConfigurator(rulesMap);
     tc.setContext(context);
-    IncAction.reset();
   }
 
   @After
   public void tearDown() throws Exception {
+    StatusPrinter.printInCaseOfErrorsOrWarnings(context);
     context = null;
     System.clearProperty(INCLUDE_KEY);
     System.clearProperty(SECOND_FILE_KEY);
     System.clearProperty(SUB_FILE_KEY);
+    StackAction.reset();
   }
 
   @Test
   public void basicFile() throws JoranException {
     System.setProperty(INCLUDE_KEY, INCLUDED_FILE);
     tc.doConfigure(TOP_BY_FILE);
-    verifyConfig(2);
+    verifyConfig(new String[] {"IA", "IB"});
   }
 
   @Test
   public void basicResource() throws JoranException {
     System.setProperty(INCLUDE_KEY, INCLUDED_AS_RESOURCE);
     tc.doConfigure(INCLUDE_BY_RESOURCE);
-    StatusPrinter.print(context);
-    verifyConfig(2);
+    verifyConfig(new String[] {"AR_A", "AR_B"});
   }
 
   @Test
   public void basicURL() throws JoranException {
     System.setProperty(INCLUDE_KEY, URL_TO_INCLUDE);
     tc.doConfigure(TOP_BY_URL);
-    StatusPrinter.print(context);
-    verifyConfig(2);
+    verifyConfig(new String[] {"IA", "IB"});
   }
 
   @Test
@@ -184,37 +188,28 @@ public class IncludeActionTest {
 
   @Test
   public void nestedInclude() throws JoranException {
-    System.setProperty(SUB_FILE_KEY, INCLUDED_FILE);
-    System.setProperty(INCLUDE_KEY, SECOND_FILE);
+    System.setProperty(SUB_FILE_KEY, SUB_FILE);
+    System.setProperty(INCLUDE_KEY, INTERMEDIARY_FILE);
     tc.doConfigure(TOP_BY_FILE);
-    StatusPrinter.print(context);
-    verifyConfig(1);
-
-  }
+    Stack<String> witness = new Stack<String>();
+    witness.push("a");
+    witness.push("b");
+    witness.push("c");
+    assertEquals(witness, StackAction.stack);
+    }
 
   @Test
   public void multiInclude() throws JoranException {
     System.setProperty(INCLUDE_KEY, INCLUDED_FILE);
     System.setProperty(SECOND_FILE_KEY, SECOND_FILE);
     tc.doConfigure(MULTI_INCLUDE_BY_FILE);
-    verifyConfig(3);
-  }
-
-  @Test
-  public void saxParseException() throws JoranException {
-    System.setProperty(INCLUDE_KEY, INCLUDED_FILE);
-    System.setProperty(SECOND_FILE_KEY, SECOND_FILE);
-    tc.doConfigure(MULTI_INCLUDE_BY_FILE);
-    verifyConfig(3);
-  }
-
-  @Test
-  public void errorInDoBegin() {
-
+    verifyConfig(new String[] {"IA", "IB", "SECOND"});
   }
-
-  void verifyConfig(int expected) {
-    assertEquals(expected, IncAction.beginCount);
-    assertEquals(expected, IncAction.endCount);
+  
+  void verifyConfig(String[] expected) {
+    Stack<String> witness = new Stack<String>();
+    witness.addAll(Arrays.asList(expected));
+    assertEquals(witness, StackAction.stack);
   }
+  
 }
diff --git a/logback-core/src/test/java/ch/qos/logback/core/joran/action/ext/StackCounterAction.java b/logback-core/src/test/java/ch/qos/logback/core/joran/action/ext/StackAction.java
similarity index 73%
rename from logback-core/src/test/java/ch/qos/logback/core/joran/action/ext/StackCounterAction.java
rename to logback-core/src/test/java/ch/qos/logback/core/joran/action/ext/StackAction.java
index 48beaff..e198345 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/joran/action/ext/StackCounterAction.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/joran/action/ext/StackAction.java
@@ -14,30 +14,27 @@
 package ch.qos.logback.core.joran.action.ext;
 
 
+import java.util.Stack;
+
 import org.xml.sax.Attributes;
 
-import ch.qos.logback.core.Layout;
 import ch.qos.logback.core.joran.action.Action;
 import ch.qos.logback.core.joran.spi.InterpretationContext;
 
 
 
-public class StackCounterAction extends Action {
- Layout layout;
-
+public class StackAction extends Action {
 
-  public StackCounterAction() {
-  }
+  public static Stack<String> stack = new Stack<String>();
 
   public void begin(InterpretationContext ec, String name, Attributes attributes) {
-    //String str = "Pushing "+name+"-begin";
-    ec.pushObject(name+"-begin");
+    stack.push(attributes.getValue("name"));
   }
 
   public void end(InterpretationContext ec, String name) {
-    ec.pushObject(name+"-end");    
   }
 
-  public void finish(InterpretationContext ec) {
+  static public void reset() {
+    stack.clear();
   }
 }
diff --git a/logback-core/src/test/java/ch/qos/logback/core/joran/conditional/IfThenElseTest.java b/logback-core/src/test/java/ch/qos/logback/core/joran/conditional/IfThenElseAndIncludeCompositionTest.java
similarity index 59%
copy from logback-core/src/test/java/ch/qos/logback/core/joran/conditional/IfThenElseTest.java
copy to logback-core/src/test/java/ch/qos/logback/core/joran/conditional/IfThenElseAndIncludeCompositionTest.java
index bf9aa89..c354999 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/joran/conditional/IfThenElseTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/joran/conditional/IfThenElseAndIncludeCompositionTest.java
@@ -13,10 +13,11 @@
  */
 package ch.qos.logback.core.joran.conditional;
 
-
 import static org.junit.Assert.assertEquals;
 
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.Stack;
 
 import org.junit.After;
 import org.junit.Before;
@@ -26,33 +27,42 @@ import ch.qos.logback.core.Context;
 import ch.qos.logback.core.ContextBase;
 import ch.qos.logback.core.joran.TrivialConfigurator;
 import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.action.IncludeAction;
 import ch.qos.logback.core.joran.action.NOPAction;
-import ch.qos.logback.core.joran.action.ext.IncAction;
+import ch.qos.logback.core.joran.action.ext.StackAction;
 import ch.qos.logback.core.joran.spi.JoranException;
 import ch.qos.logback.core.joran.spi.Pattern;
 import ch.qos.logback.core.testUtil.RandomUtil;
 import ch.qos.logback.core.util.CoreTestConstants;
 import ch.qos.logback.core.util.StatusPrinter;
 
-public class IfThenElseTest {
+public class IfThenElseAndIncludeCompositionTest {
 
   Context context = new ContextBase();
   TrivialConfigurator tc;
   int diff = RandomUtil.getPositiveInt();
   static final String CONDITIONAL_DIR_PREFIX = CoreTestConstants.JORAN_INPUT_PREFIX
-  + "conditional/";
+      + "conditional/";
 
+  final static String THEN_FILE_TO_INCLUDE_KEY = "thenFileToInclude";
+  final static String ELSE_FILE_TO_INCLUDE_KEY = "elseFileToInclude";
+  
+  static final String NESTED_INCLUDE_FILE = CONDITIONAL_DIR_PREFIX+"nestedInclude.xml";
+  static final String THEN_FILE_TO_INCLUDE = CONDITIONAL_DIR_PREFIX+"includedA.xml";
+  static final String ELSE_FILE_TO_INCLUDE = CONDITIONAL_DIR_PREFIX+"includedB.xml";
+  
   
   @Before
   public void setUp() throws Exception {
     HashMap<Pattern, Action> rulesMap = new HashMap<Pattern, Action>();
     rulesMap.put(new Pattern("x"), new NOPAction());
-    rulesMap.put(new Pattern("x/inc"), new IncAction());
+    rulesMap.put(new Pattern("x/stack"), new StackAction());
     rulesMap.put(new Pattern("*/if"), new IfAction());
     rulesMap.put(new Pattern("*/if/then"), new ThenAction());
     rulesMap.put(new Pattern("*/if/then/*"), new NOPAction());
     rulesMap.put(new Pattern("*/if/else"), new ElseAction());
     rulesMap.put(new Pattern("*/if/else/*"), new NOPAction());    
+    rulesMap.put(new Pattern("x/include"), new IncludeAction());
     
     tc = new TrivialConfigurator(rulesMap);
     tc.setContext(context);
@@ -60,29 +70,24 @@ public class IfThenElseTest {
 
   @After
   public void tearDown() throws Exception {
-    IncAction.reset();
-  }
-
-  @Test
-  public void if0_Then() throws JoranException {
-    context.putProperty("Ki1", "Val1");
-    tc.doConfigure(CONDITIONAL_DIR_PREFIX+"if0.xml");
-    verifyConfig(1);
+    StatusPrinter.printInCaseOfErrorsOrWarnings(context);
+    context = null;
+    StackAction.reset();
   }
-
-  @Test
-  public void if0_Else() throws JoranException {
-    tc.doConfigure(CONDITIONAL_DIR_PREFIX+"if0.xml");
-    StatusPrinter.print(context);
-    verifyConfig(2);
-  }
-
   
-  void verifyConfig(int expected) {
-    assertEquals(expected, IncAction.beginCount);
-    assertEquals(expected, IncAction.endCount);
+  @Test
+  public void includeNestedWithinIf() throws JoranException {
+    context.putProperty(THEN_FILE_TO_INCLUDE_KEY, THEN_FILE_TO_INCLUDE);
+    context.putProperty(ELSE_FILE_TO_INCLUDE_KEY, ELSE_FILE_TO_INCLUDE);
+    tc.doConfigure(NESTED_INCLUDE_FILE);
+    verifyConfig(new String[] {"BEGIN", "e0", "IncludedB0", "e1", "END"});
   }
   
   
+  void verifyConfig(String[] expected) {
+    Stack<String> witness = new Stack<String>();
+    witness.addAll(Arrays.asList(expected));
+    assertEquals(witness, StackAction.stack);
+  }
   
 }
diff --git a/logback-core/src/test/java/ch/qos/logback/core/joran/conditional/IfThenElseTest.java b/logback-core/src/test/java/ch/qos/logback/core/joran/conditional/IfThenElseTest.java
index bf9aa89..5d3f98b 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/joran/conditional/IfThenElseTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/joran/conditional/IfThenElseTest.java
@@ -16,7 +16,9 @@ package ch.qos.logback.core.joran.conditional;
 
 import static org.junit.Assert.assertEquals;
 
+import java.util.Arrays;
 import java.util.HashMap;
+import java.util.Stack;
 
 import org.junit.After;
 import org.junit.Before;
@@ -27,7 +29,7 @@ import ch.qos.logback.core.ContextBase;
 import ch.qos.logback.core.joran.TrivialConfigurator;
 import ch.qos.logback.core.joran.action.Action;
 import ch.qos.logback.core.joran.action.NOPAction;
-import ch.qos.logback.core.joran.action.ext.IncAction;
+import ch.qos.logback.core.joran.action.ext.StackAction;
 import ch.qos.logback.core.joran.spi.JoranException;
 import ch.qos.logback.core.joran.spi.Pattern;
 import ch.qos.logback.core.testUtil.RandomUtil;
@@ -47,7 +49,7 @@ public class IfThenElseTest {
   public void setUp() throws Exception {
     HashMap<Pattern, Action> rulesMap = new HashMap<Pattern, Action>();
     rulesMap.put(new Pattern("x"), new NOPAction());
-    rulesMap.put(new Pattern("x/inc"), new IncAction());
+    rulesMap.put(new Pattern("x/stack"), new StackAction());
     rulesMap.put(new Pattern("*/if"), new IfAction());
     rulesMap.put(new Pattern("*/if/then"), new ThenAction());
     rulesMap.put(new Pattern("*/if/then/*"), new NOPAction());
@@ -60,27 +62,34 @@ public class IfThenElseTest {
 
   @After
   public void tearDown() throws Exception {
-    IncAction.reset();
+    StackAction.reset();
   }
 
   @Test
   public void if0_Then() throws JoranException {
     context.putProperty("Ki1", "Val1");
     tc.doConfigure(CONDITIONAL_DIR_PREFIX+"if0.xml");
-    verifyConfig(1);
+    StatusPrinter.printIfErrorsOccured(context);
+    verifyConfig(new String[] {"BEGIN", "a", "END"});
   }
 
   @Test
   public void if0_Else() throws JoranException {
     tc.doConfigure(CONDITIONAL_DIR_PREFIX+"if0.xml");
-    StatusPrinter.print(context);
-    verifyConfig(2);
+    verifyConfig(new String[] {"BEGIN", "b", "END"});
   }
 
+  @Test
+  public void nestedIf() throws JoranException {
+    tc.doConfigure(CONDITIONAL_DIR_PREFIX+"nestedIf.xml");
+    StatusPrinter.printIfErrorsOccured(context);
+    verifyConfig(new String[] {"BEGIN", "a", "c", "END"});
+  }
   
-  void verifyConfig(int expected) {
-    assertEquals(expected, IncAction.beginCount);
-    assertEquals(expected, IncAction.endCount);
+  void verifyConfig(String[] expected) {
+    Stack<String> witness = new Stack<String>();
+    witness.addAll(Arrays.asList(expected));
+    assertEquals(witness, StackAction.stack);
   }
   
   
diff --git a/logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java b/logback-core/src/test/java/ch/qos/logback/core/joran/conditional/PackageTest.java
similarity index 59%
copy from logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java
copy to logback-core/src/test/java/ch/qos/logback/core/joran/conditional/PackageTest.java
index d65ac45..0a5b973 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/joran/conditional/PackageTest.java
@@ -11,20 +11,15 @@
  * 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.joran;
+package ch.qos.logback.core.joran.conditional;
 
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 import org.junit.runners.Suite.SuiteClasses;
 
 @RunWith(Suite.class)
- at SuiteClasses({SkippingInInterpreterTest.class, TrivialConfiguratorTest.class, ch.qos.logback.core.joran.action.PackageTest.class,
-  ch.qos.logback.core.joran.event.PackageTest.class,
-  ch.qos.logback.core.joran.util.PackageTest.class,
-  ch.qos.logback.core.joran.spi.PackageTest.class,
-  ch.qos.logback.core.joran.replay.PackageTest.class,
-  ch.qos.logback.core.joran.implicitAction.PackageTest.class
- })
+ at SuiteClasses( { PropertyEvalScriptBuilderTest.class, IfThenElseTest.class,
+    IfThenElseAndIncludeCompositionTest.class })
 public class PackageTest {
 
 }
diff --git a/logback-core/src/test/resources/asResource/joran/inclusion/includedAsResource.xml b/logback-core/src/test/resources/asResource/joran/inclusion/includedAsResource.xml
index 1b80687..e80121e 100644
--- a/logback-core/src/test/resources/asResource/joran/inclusion/includedAsResource.xml
+++ b/logback-core/src/test/resources/asResource/joran/inclusion/includedAsResource.xml
@@ -3,7 +3,7 @@
 
 <included>
 
-  <inc increment="1"/>
-  <inc increment="1"/>
+  <stack name="AR_A" />
+  <stack name="AR_B" />
 
 </included>
\ No newline at end of file

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

Summary of changes:
 .../logback/core/joran/conditional/ElseAction.java |   50 +++++---------
 .../logback/core/joran/conditional/IfAction.java   |   53 +++++++++++---
 .../logback/core/joran/conditional/ThenAction.java |   52 +++++---------
 .../joran/conditional/ThenOrElseActionBase.java    |   76 ++++++++++++++++++++
 .../core/joran/spi/InterpretationContext.java      |    7 ++
 .../ch/qos/logback/core/joran/spi/Interpreter.java |   23 ------
 .../src/test/input/joran/conditional/if0.xml       |    7 +-
 .../src/test/input/joran/conditional/if2.xml       |   14 ----
 .../included.xml => conditional/includedA.xml}     |    6 +-
 .../second.xml => conditional/includedB.xml}       |    4 +-
 .../src/test/input/joran/conditional/nestedIf.xml  |   26 +++++++
 .../test/input/joran/conditional/nestedInclude.xml |   22 ++++++
 .../src/test/input/joran/inclusion/included.xml    |    4 +-
 .../input/joran/inclusion/intermediaryByFile.xml   |    8 ++
 .../src/test/input/joran/inclusion/second.xml      |    2 +-
 .../src/test/input/joran/inclusion/subByFile.xml   |    7 +--
 .../ch/qos/logback/core/joran/PackageTest.java     |    4 +-
 .../core/joran/action/IncludeActionTest.java       |   61 +++++++---------
 .../{StackCounterAction.java => StackAction.java}  |   17 ++---
 ...va => IfThenElseAndIncludeCompositionTest.java} |   53 ++++++++------
 .../core/joran/conditional/IfThenElseTest.java     |   27 +++++---
 .../conditional}/PackageTest.java                  |    5 +-
 .../joran/inclusion/includedAsResource.xml         |    4 +-
 23 files changed, 318 insertions(+), 214 deletions(-)
 create mode 100644 logback-core/src/main/java/ch/qos/logback/core/joran/conditional/ThenOrElseActionBase.java
 delete mode 100644 logback-core/src/test/input/joran/conditional/if2.xml
 copy logback-core/src/test/input/joran/{inclusion/included.xml => conditional/includedA.xml} (51%)
 copy logback-core/src/test/input/joran/{inclusion/second.xml => conditional/includedB.xml} (63%)
 create mode 100644 logback-core/src/test/input/joran/conditional/nestedIf.xml
 create mode 100644 logback-core/src/test/input/joran/conditional/nestedInclude.xml
 create mode 100644 logback-core/src/test/input/joran/inclusion/intermediaryByFile.xml
 rename logback-core/src/test/java/ch/qos/logback/core/joran/action/ext/{StackCounterAction.java => StackAction.java} (73%)
 copy logback-core/src/test/java/ch/qos/logback/core/joran/conditional/{IfThenElseTest.java => IfThenElseAndIncludeCompositionTest.java} (59%)
 copy logback-core/src/test/java/ch/qos/logback/core/{helpers => joran/conditional}/PackageTest.java (78%)


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


More information about the logback-dev mailing list