[logback-dev] svn commit: r2102 - in logback/trunk: logback-access/src/main/java/ch/qos/logback/access/boolex logback-access/src/main/java/ch/qos/logback/access/jetty logback-access/src/main/java/ch/qos/logback/access/joran/action logback-access/src/main/java/ch/qos/logback/access/net logback-access/src/main/java/ch/qos/logback/access/spi logback-access/src/main/java/ch/qos/logback/access/tomcat logback-classic/src/main/java/ch/qos/logback/classic/boolex logback-classic/src/main/java/ch/qos/logback/classic/joran/action logback-classic/src/main/java/ch/qos/logback/classic/net logback-classic/src/main/java/ch/qos/logback/classic/pattern logback-classic/src/test/java/ch/qos/logback/classic logback-classic/src/test/java/ch/qos/logback/classic/boolex logback-classic/src/test/java/ch/qos/logback/classic/control logback-classic/src/test/java/ch/qos/logback/classic/db logback-classic/src/test/java/ch/qos/logback/classic/html logback-classic/src/test/java/ch/qos/logback/classic/jmx logback -classic/src/test/java/ch/qos/logback/classic/joran logback-classic/src/test/java/ch/qos/logback/classic/net logback-classic/src/test/java/ch/qos/logback/classic/pattern logback-classic/src/test/java/ch/qos/logback/classic/selector logback-classic/src/test/java/ch/qos/logback/classic/spi logback-classic/src/test/java/ch/qos/logback/classic/util logback-classic/src/test/java/org/slf4j/impl logback-core/src/main/java/ch/qos/logback/core logback-core/src/main/java/ch/qos/logback/core/boolex logback-core/src/main/java/ch/qos/logback/core/filter logback-core/src/main/java/ch/qos/logback/core/joran/action logback-core/src/main/java/ch/qos/logback/core/joran/spi logback-core/src/main/java/ch/qos/logback/core/net logback-core/src/main/java/ch/qos/logback/core/spi logback-core/src/test/java/ch/qos/logback/core/joran/spi
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Fri Dec 26 14:55:28 CET 2008
Author: ceki
Date: Fri Dec 26 14:55:28 2008
New Revision: 2102
Added:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/boolex/OnErrorEvaluator.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/EventEvaluatorBase.java
Modified:
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/boolex/JaninoEventEvaluator.java
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/joran/action/EvaluatorAction.java
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/SMTPAppender.java
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessContext.java
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/boolex/JaninoEventEvaluator.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/EvaluatorAction.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SMTPAppender.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/CallerDataConverter.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/EnsureExceptionHandling.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ThrowableProxyConverter.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllClassicTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/PackageTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/PackageTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/html/PackageTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/PackageTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/EvaluatorJoranTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/PackageTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/PackageTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/MDCConverterTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/MarkerConverterTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/PackageTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextDetachingSCLTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/PackageTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/CallerDataTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/ContextListenerTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/PackageTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/PackageTest.java
logback/trunk/logback-classic/src/test/java/org/slf4j/impl/PackageTest.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/Appender.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/UnsynchronizedAppenderBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/EventEvaluator.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/JaninoEventEvaluatorBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/Matcher.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractMatcherFilter.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/Filter.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AbstractEventEvaluatorAction.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/IADataForComplexProperty.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/MatcherAction.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComplexPropertyIA.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/PropertySetter.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachable.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachableImpl.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PropertySetterTest.java
Log:
- Migrate all tests to Junit4
- add tests for verifying that parameter types which are concrete classes
can be instantiated by implicit actions
- ongoing work on evaluators
Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/boolex/JaninoEventEvaluator.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/boolex/JaninoEventEvaluator.java (original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/boolex/JaninoEventEvaluator.java Fri Dec 26 14:55:28 2008
@@ -1,3 +1,12 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
package ch.qos.logback.access.boolex;
import java.util.ArrayList;
@@ -8,16 +17,13 @@
import ch.qos.logback.core.boolex.JaninoEventEvaluatorBase;
import ch.qos.logback.core.boolex.Matcher;
-
-
-public class JaninoEventEvaluator extends JaninoEventEvaluatorBase {
+public class JaninoEventEvaluator extends JaninoEventEvaluatorBase<AccessEvent> {
public final static List<String> DEFAULT_PARAM_NAME_LIST = new ArrayList<String>();
public final static List<Class> DEFAULT_PARAM_TYPE_LIST = new ArrayList<Class>();
static {
DEFAULT_PARAM_NAME_LIST.add("event");
-
DEFAULT_PARAM_TYPE_LIST.add(AccessEvent.class);
}
@@ -51,14 +57,14 @@
return (Class[]) fullTypeList.toArray(CoreConstants.EMPTY_CLASS_ARRAY);
}
- protected Object[] getParameterValues(Object event) {
- AccessEvent loggingEvent = (AccessEvent) event;
+ protected Object[] getParameterValues(AccessEvent event) {
+ AccessEvent accessEvent = (AccessEvent) event;
final int matcherListSize = matcherList.size();
int i = 0;
Object[] values = new Object[DEFAULT_PARAM_NAME_LIST.size()+matcherListSize];
- values[i++] = loggingEvent;
+ values[i++] = accessEvent;
for(int j = 0; j < matcherListSize; j++) {
values[i++] = (Matcher) matcherList.get(j);
Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java (original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/jetty/RequestLogImpl.java Fri Dec 26 14:55:28 2008
@@ -110,13 +110,13 @@
* @author Sébastien Pennec
*/
public class RequestLogImpl extends ContextBase implements RequestLog,
- AppenderAttachable<AccessEvent>, FilterAttachable {
+ AppenderAttachable<AccessEvent>, FilterAttachable<AccessEvent> {
public final static String DEFAULT_CONFIG_FILE = "etc" + File.separatorChar
+ "logback-access.xml";
AppenderAttachableImpl<AccessEvent> aai = new AppenderAttachableImpl<AccessEvent>();
- FilterAttachableImpl fai = new FilterAttachableImpl();
+ FilterAttachableImpl<AccessEvent> fai = new FilterAttachableImpl<AccessEvent>();
String filename;
boolean started = false;
@@ -235,7 +235,7 @@
return aai.detachAppender(name);
}
- public void addFilter(Filter newFilter) {
+ public void addFilter(Filter<AccessEvent> newFilter) {
fai.addFilter(newFilter);
}
@@ -243,7 +243,7 @@
fai.clearAllFilters();
}
- public FilterReply getFilterChainDecision(Object event) {
+ public FilterReply getFilterChainDecision(AccessEvent event) {
return fai.getFilterChainDecision(event);
}
Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/joran/action/EvaluatorAction.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/joran/action/EvaluatorAction.java (original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/joran/action/EvaluatorAction.java Fri Dec 26 14:55:28 2008
@@ -1,17 +1,11 @@
package ch.qos.logback.access.joran.action;
import ch.qos.logback.access.boolex.JaninoEventEvaluator;
-import ch.qos.logback.core.boolex.EventEvaluator;
import ch.qos.logback.core.joran.action.AbstractEventEvaluatorAction;
public class EvaluatorAction extends AbstractEventEvaluatorAction {
- protected boolean isOfCorrectType(EventEvaluator ee) {
- return (ee instanceof JaninoEventEvaluator);
- }
-
-
protected String defaultClassName() {
return JaninoEventEvaluator.class.getName();
}
Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/SMTPAppender.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/SMTPAppender.java (original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/net/SMTPAppender.java Fri Dec 26 14:55:28 2008
@@ -47,7 +47,7 @@
* Use <code>evaluator</code> passed as parameter as the {@link
* EventEvaluator} for this SMTPAppender.
*/
- public SMTPAppender(EventEvaluator evaluator) {
+ public SMTPAppender(EventEvaluator<AccessEvent> evaluator) {
this.eventEvaluator = evaluator;
}
Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessContext.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessContext.java (original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessContext.java Fri Dec 26 14:55:28 2008
@@ -18,10 +18,10 @@
*
* @author Sébastien Pennec
*/
-public class AccessContext extends ContextBase implements AppenderAttachable<AccessEvent>, FilterAttachable {
+public class AccessContext extends ContextBase implements AppenderAttachable<AccessEvent>, FilterAttachable<AccessEvent> {
AppenderAttachableImpl<AccessEvent> aai = new AppenderAttachableImpl<AccessEvent>();
- FilterAttachableImpl fai = new FilterAttachableImpl();
+ FilterAttachableImpl<AccessEvent> fai = new FilterAttachableImpl<AccessEvent>();
public void callAppenders(AccessEvent event) {
aai.appendLoopOnAppenders(event);
@@ -55,7 +55,7 @@
return aai.iteratorForAppenders();
}
- public void addFilter(Filter newFilter) {
+ public void addFilter(Filter<AccessEvent> newFilter) {
fai.addFilter(newFilter);
}
@@ -63,7 +63,7 @@
fai.clearAllFilters();
}
- public FilterReply getFilterChainDecision(Object event) {
+ public FilterReply getFilterChainDecision(AccessEvent event) {
return fai.getFilterChainDecision(event);
}
Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java (original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java Fri Dec 26 14:55:28 2008
@@ -54,7 +54,7 @@
* @author Sébastien Pennec
*/
public class LogbackValve extends ValveBase implements Lifecycle, Context,
- AppenderAttachable<AccessEvent>, FilterAttachable {
+ AppenderAttachable<AccessEvent>, FilterAttachable<AccessEvent> {
public final static String DEFAULT_CONFIG_FILE = "conf" + File.separatorChar
+ "logback-access.xml";
@@ -67,7 +67,7 @@
// serialized. For the time being, we ignore this shortcoming.
Map<String, String> propertyMap = new HashMap<String, String>();
Map<String, Object> objectMap = new HashMap<String, Object>();
- private FilterAttachableImpl fai = new FilterAttachableImpl();
+ private FilterAttachableImpl<AccessEvent> fai = new FilterAttachableImpl<AccessEvent>();
AppenderAttachableImpl<AccessEvent> aai = new AppenderAttachableImpl<AccessEvent>();
String filename;
@@ -204,7 +204,7 @@
objectMap.put(key, value);
}
- public void addFilter(Filter newFilter) {
+ public void addFilter(Filter<AccessEvent> newFilter) {
fai.addFilter(newFilter);
}
@@ -216,7 +216,7 @@
fai.clearAllFilters();
}
- public FilterReply getFilterChainDecision(Object event) {
+ public FilterReply getFilterChainDecision(AccessEvent event) {
return fai.getFilterChainDecision(event);
}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/boolex/JaninoEventEvaluator.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/boolex/JaninoEventEvaluator.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/boolex/JaninoEventEvaluator.java Fri Dec 26 14:55:28 2008
@@ -1,3 +1,12 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
package ch.qos.logback.classic.boolex;
import java.util.ArrayList;
@@ -15,7 +24,7 @@
-public class JaninoEventEvaluator extends JaninoEventEvaluatorBase {
+public class JaninoEventEvaluator extends JaninoEventEvaluatorBase<LoggingEvent> {
public final static String IMPORT_LEVEL = "import ch.qos.logback.classic.Level;\r\n";
@@ -83,8 +92,7 @@
return (Class[]) fullTypeList.toArray(CoreConstants.EMPTY_CLASS_ARRAY);
}
- protected Object[] getParameterValues(Object event) {
- LoggingEvent loggingEvent = (LoggingEvent) event;
+ protected Object[] getParameterValues(LoggingEvent loggingEvent) {
final int matcherListSize = matcherList.size();
int i = 0;
Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/boolex/OnErrorEvaluator.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/boolex/OnErrorEvaluator.java Fri Dec 26 14:55:28 2008
@@ -0,0 +1,23 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.classic.boolex;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.boolex.EvaluationException;
+import ch.qos.logback.core.boolex.EventEvaluatorBase;
+
+public class OnErrorEvaluator extends EventEvaluatorBase<LoggingEvent> {
+
+ public boolean evaluate(LoggingEvent event) throws NullPointerException,
+ EvaluationException {
+ return event.getLevel().levelInt >= Level.ERROR_INT;
+ }
+}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/EvaluatorAction.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/EvaluatorAction.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/EvaluatorAction.java Fri Dec 26 14:55:28 2008
@@ -1,21 +1,22 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
package ch.qos.logback.classic.joran.action;
import ch.qos.logback.classic.boolex.JaninoEventEvaluator;
-import ch.qos.logback.core.boolex.EventEvaluator;
import ch.qos.logback.core.joran.action.AbstractEventEvaluatorAction;
public class EvaluatorAction extends AbstractEventEvaluatorAction {
- protected boolean isOfCorrectType(EventEvaluator ee) {
- return (ee instanceof JaninoEventEvaluator);
- }
-
-
- protected String defaultClassName() {
+ protected String defaultClassName() {
return JaninoEventEvaluator.class.getName();
}
-
-
}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SMTPAppender.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SMTPAppender.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SMTPAppender.java Fri Dec 26 14:55:28 2008
@@ -63,7 +63,7 @@
* Use the parameter as the {@link
* EventEvaluator} for this SMTPAppender.
*/
- public SMTPAppender(EventEvaluator eventEvaluator) {
+ public SMTPAppender(EventEvaluator<LoggingEvent> eventEvaluator) {
this.eventEvaluator = eventEvaluator;
}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/CallerDataConverter.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/CallerDataConverter.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/CallerDataConverter.java Fri Dec 26 14:55:28 2008
@@ -1,11 +1,11 @@
/**
- * LOGBack: the reliable, fast and flexible logging library for Java.
- *
- * Copyright (C) 1999-2006, QOS.ch
- *
- * This library is free software, you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation.
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
*/
package ch.qos.logback.classic.pattern;
@@ -21,7 +21,6 @@
import ch.qos.logback.core.boolex.EventEvaluator;
import ch.qos.logback.core.status.ErrorStatus;
-
/**
* This converter outputs caller data depending on depth and marker data.
*
@@ -30,11 +29,12 @@
public class CallerDataConverter extends ClassicConverter {
int depth = 5;
- List<EventEvaluator> evaluatorList = null;
+ List<EventEvaluator<LoggingEvent>> evaluatorList = null;
final int MAX_ERROR_COUNT = 4;
int errorCount = 0;
-
+
+ @SuppressWarnings("unchecked")
public void start() {
String depthStr = getFirstOption();
if (depthStr == null) {
@@ -55,8 +55,10 @@
String evaluatorStr = (String) optionList.get(i);
Context context = getContext();
if (context != null) {
- Map evaluatorMap = (Map) context.getObject(CoreConstants.EVALUATOR_MAP);
- EventEvaluator ee = (EventEvaluator) evaluatorMap.get(evaluatorStr);
+ Map evaluatorMap = (Map) context
+ .getObject(CoreConstants.EVALUATOR_MAP);
+ EventEvaluator<LoggingEvent> ee = (EventEvaluator<LoggingEvent>) evaluatorMap
+ .get(evaluatorStr);
if (ee != null) {
addEvaluator(ee);
}
@@ -66,9 +68,9 @@
}
- private void addEvaluator(EventEvaluator ee) {
+ private void addEvaluator(EventEvaluator<LoggingEvent> ee) {
if (evaluatorList == null) {
- evaluatorList = new ArrayList<EventEvaluator>();
+ evaluatorList = new ArrayList<EventEvaluator<LoggingEvent>>();
}
evaluatorList.add(ee);
}
@@ -79,7 +81,7 @@
if (evaluatorList != null) {
boolean printCallerData = false;
for (int i = 0; i < evaluatorList.size(); i++) {
- EventEvaluator ee = (EventEvaluator) evaluatorList.get(i);
+ EventEvaluator<LoggingEvent> ee = evaluatorList.get(i);
try {
if (ee.evaluate(le)) {
printCallerData = true;
@@ -94,8 +96,9 @@
ErrorStatus errorStatus = new ErrorStatus(
"Exception thrown for evaluator named [" + ee.getName() + "].",
this, eex);
- errorStatus.add(new ErrorStatus("This was the last warning about this evaluator's errors." +
- "We don't want the StatusManager to get flooded.", this));
+ errorStatus.add(new ErrorStatus(
+ "This was the last warning about this evaluator's errors."
+ + "We don't want the StatusManager to get flooded.", this));
addStatus(errorStatus);
}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/EnsureExceptionHandling.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/EnsureExceptionHandling.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/EnsureExceptionHandling.java Fri Dec 26 14:55:28 2008
@@ -8,11 +8,6 @@
public class EnsureExceptionHandling implements
PostCompileProcessor<LoggingEvent> {
- // public void process(Converter head) {
- // // TODO Auto-generated method stub
- //
- // }
-
/**
* This implementation checks if any of the converters in the chain handles
* exceptions. If not, then this method adds a
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ThrowableProxyConverter.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ThrowableProxyConverter.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ThrowableProxyConverter.java Fri Dec 26 14:55:28 2008
@@ -30,11 +30,12 @@
public class ThrowableProxyConverter extends ThrowableHandlingConverter {
int lengthOption;
- List<EventEvaluator> evaluatorList = null;
+ List<EventEvaluator<LoggingEvent>> evaluatorList = null;
final int MAX_ERROR_COUNT = 4;
int errorCount = 0;
+ @SuppressWarnings("unchecked")
public void start() {
String lengthStr = getFirstOption();
@@ -66,16 +67,16 @@
String evaluatorStr = (String) optionList.get(i);
Context context = getContext();
Map evaluatorMap = (Map) context.getObject(CoreConstants.EVALUATOR_MAP);
- EventEvaluator ee = (EventEvaluator) evaluatorMap.get(evaluatorStr);
+ EventEvaluator<LoggingEvent> ee = (EventEvaluator<LoggingEvent>) evaluatorMap.get(evaluatorStr);
addEvaluator(ee);
}
}
super.start();
}
- private void addEvaluator(EventEvaluator ee) {
+ private void addEvaluator(EventEvaluator<LoggingEvent> ee) {
if (evaluatorList == null) {
- evaluatorList = new ArrayList<EventEvaluator>();
+ evaluatorList = new ArrayList<EventEvaluator<LoggingEvent>>();
}
evaluatorList.add(ee);
}
@@ -111,7 +112,7 @@
if (evaluatorList != null) {
boolean printStack = true;
for (int i = 0; i < evaluatorList.size(); i++) {
- EventEvaluator ee = (EventEvaluator) evaluatorList.get(i);
+ EventEvaluator<LoggingEvent> ee = evaluatorList.get(i);
try {
if (ee.evaluate(event)) {
printStack = false;
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllClassicTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllClassicTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllClassicTest.java Fri Dec 26 14:55:28 2008
@@ -9,33 +9,27 @@
*/
package ch.qos.logback.classic;
-import junit.framework.JUnit4TestAdapter;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
-public class AllClassicTest extends TestCase {
+ at RunWith(Suite.class)
+ at SuiteClasses({org.slf4j.impl.PackageTest.class,
+ ch.qos.logback.classic.PackageTest.class,
+ ch.qos.logback.classic.util.PackageTest.class,
+ ch.qos.logback.classic.control.PackageTest.class,
+ ch.qos.logback.classic.joran.PackageTest.class,
+ ch.qos.logback.classic.jmx.PackageTest.class,
+ ch.qos.logback.classic.boolex.PackageTest.class,
+ ch.qos.logback.classic.selector.PackageTest.class,
+ ch.qos.logback.classic.html.PackageTest.class,
+ ch.qos.logback.classic.net.PackageTest.class,
+ ch.qos.logback.classic.pattern.PackageTest.class,
+ ch.qos.logback.classic.db.PackageTest.class,
+ ch.qos.logback.classic.spi.PackageTest.class,
+ ch.qos.logback.classic.turbo.PackageTest.class,
+ ch.qos.logback.classic.sift.PackageTest.class})
+public class AllClassicTest {
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(org.slf4j.impl.PackageTest.suite());
- suite.addTest(new JUnit4TestAdapter(
- ch.qos.logback.classic.PackageTest.class));
- suite.addTest(ch.qos.logback.classic.util.PackageTest.suite());
- suite.addTest(ch.qos.logback.classic.control.PackageTest.suite());
- suite.addTest(ch.qos.logback.classic.joran.PackageTest.suite());
- suite.addTest(ch.qos.logback.classic.jmx.PackageTest.suite());
- suite.addTest(ch.qos.logback.classic.boolex.PackageTest.suite());
- suite.addTest(ch.qos.logback.classic.selector.PackageTest.suite());
- suite.addTest(ch.qos.logback.classic.html.PackageTest.suite());
- suite.addTest(ch.qos.logback.classic.net.PackageTest.suite());
- suite.addTest(ch.qos.logback.classic.pattern.PackageTest.suite());
- suite.addTest(ch.qos.logback.classic.db.PackageTest.suite());
- suite.addTest(ch.qos.logback.classic.spi.PackageTest.suite());
- suite.addTest(new JUnit4TestAdapter(ch.qos.logback.classic.turbo.PackageTest.class));
- suite.addTest(new JUnit4TestAdapter(
- ch.qos.logback.classic.sift.PackageTest.class));
- return suite;
- }
}
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/JaninoEventEvaluatorTest.java Fri Dec 26 14:55:28 2008
@@ -1,7 +1,10 @@
package ch.qos.logback.classic.boolex;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import org.junit.Test;
import org.slf4j.MarkerFactory;
import ch.qos.logback.classic.Level;
@@ -13,16 +16,14 @@
import ch.qos.logback.core.boolex.JaninoEventEvaluatorBase;
import ch.qos.logback.core.boolex.Matcher;
-public class JaninoEventEvaluatorTest extends TestCase {
+public class JaninoEventEvaluatorTest {
LoggerContext loggerContext = new LoggerContext();
Logger logger = loggerContext.getLogger(ConverterTest.class);
Matcher matcherX = new Matcher();
- public JaninoEventEvaluatorTest(String arg0) {
- super(arg0);
-
+ public JaninoEventEvaluatorTest() {
matcherX.setName("x");
matcherX.setRegex("^Some\\s.*");
matcherX.start();
@@ -36,6 +37,7 @@
return e;
}
+ @Test
public void testBasic() throws Exception {
JaninoEventEvaluator jee = new JaninoEventEvaluator();
jee.setExpression("message.equals(\"Some message\")");
@@ -47,6 +49,7 @@
assertTrue(jee.evaluate(event));
}
+ @Test
public void testLevel() throws Exception {
JaninoEventEvaluator jee = new JaninoEventEvaluator();
jee.setExpression("level > DEBUG");
@@ -58,6 +61,7 @@
assertTrue(jee.evaluate(event));
}
+ @Test
public void testtimeStamp() throws Exception {
JaninoEventEvaluator jee = new JaninoEventEvaluator();
jee.setExpression("timeStamp > 10");
@@ -68,6 +72,7 @@
assertTrue(jee.evaluate(event));
}
+ @Test
public void testWithMatcher() throws Exception {
JaninoEventEvaluator jee = new JaninoEventEvaluator();
@@ -80,6 +85,7 @@
assertTrue(jee.evaluate(event));
}
+ @Test
public void testMarker() throws Exception {
JaninoEventEvaluator jee = new JaninoEventEvaluator();
jee.setExpression("marker.contains(\"BLUE\")");
@@ -92,6 +98,7 @@
assertTrue(jee.evaluate(event));
}
+ @Test
public void testWithNullMarker() throws Exception {
JaninoEventEvaluator jee = new JaninoEventEvaluator();
jee.setExpression("marker.contains(\"BLUE\")");
@@ -108,6 +115,7 @@
}
}
+ @Test
public void testComplex() throws Exception {
JaninoEventEvaluator jee = new JaninoEventEvaluator();
@@ -127,6 +135,7 @@
*
* @throws Exception
*/
+ @Test
public void testBogusExp1() {
JaninoEventEvaluator jee = new JaninoEventEvaluator();
@@ -145,6 +154,7 @@
}
// check that eval stops after errors
+ @Test
public void testBogusExp2() {
JaninoEventEvaluator jee = new JaninoEventEvaluator();
@@ -185,6 +195,7 @@
//System.out.println(msg + (end - start) / LEN + " nanos");
}
+ @Test
public void testLoop1() throws Exception {
JaninoEventEvaluator jee = new JaninoEventEvaluator();
jee.setExpression("timeStamp > 10");
@@ -194,6 +205,7 @@
loop(jee, "timestamp > 10]: ");
}
+ @Test
public void testLoop2() throws Exception {
JaninoEventEvaluator jee = new JaninoEventEvaluator();
jee.setExpression("x.matches(message)");
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/PackageTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/boolex/PackageTest.java Fri Dec 26 14:55:28 2008
@@ -9,13 +9,13 @@
*/
package ch.qos.logback.classic.boolex;
-import junit.framework.*;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
-public class PackageTest extends TestCase {
+import ch.qos.logback.classic.jmx.JMXConfiguratorTest;
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTestSuite(JaninoEventEvaluatorTest.class);
- return suite;
- }
+ at RunWith(Suite.class)
+ at SuiteClasses(JMXConfiguratorTest.class)
+public class PackageTest {
}
\ No newline at end of file
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/PackageTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/control/PackageTest.java Fri Dec 26 14:55:28 2008
@@ -9,13 +9,12 @@
*/
package ch.qos.logback.classic.control;
-import junit.framework.*;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
-public class PackageTest extends TestCase {
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new JUnit4TestAdapter(RandomUtilTest.class));
- return suite;
- }
+ at RunWith(Suite.class)
+ at SuiteClasses({RandomUtilTest.class})
+public class PackageTest {
}
\ No newline at end of file
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/db/PackageTest.java Fri Dec 26 14:55:28 2008
@@ -9,13 +9,11 @@
*/
package ch.qos.logback.classic.db;
-import junit.framework.*;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
-public class PackageTest extends TestCase {
-
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new JUnit4TestAdapter(DBAppenderTest.class));
- return suite;
- }
+ at RunWith(Suite.class)
+ at SuiteClasses( {DBAppenderTest.class})
+public class PackageTest {
}
\ No newline at end of file
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/html/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/html/PackageTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/html/PackageTest.java Fri Dec 26 14:55:28 2008
@@ -9,16 +9,11 @@
*/
package ch.qos.logback.classic.html;
-import junit.framework.JUnit4TestAdapter;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
-public class PackageTest extends TestCase {
-
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new JUnit4TestAdapter(HTMLLayoutTest.class));
- return suite;
- }
+ at RunWith(Suite.class)
+ at SuiteClasses(HTMLLayoutTest.class)
+public class PackageTest {
}
\ No newline at end of file
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/PackageTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/jmx/PackageTest.java Fri Dec 26 14:55:28 2008
@@ -10,16 +10,12 @@
package ch.qos.logback.classic.jmx;
-import junit.framework.JUnit4TestAdapter;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
-public class PackageTest extends TestCase {
+ at RunWith(Suite.class)
+ at SuiteClasses(JMXConfiguratorTest.class)
+public class PackageTest {
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new JUnit4TestAdapter (JMXConfiguratorTest.class));
- return suite;
- }
}
\ No newline at end of file
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/EvaluatorJoranTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/EvaluatorJoranTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/EvaluatorJoranTest.java Fri Dec 26 14:55:28 2008
@@ -1,18 +1,20 @@
/**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
- *
- * Copyright (C) 1999-2006, QOS.ch
- *
- * This library is free software, you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation.
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
*/
package ch.qos.logback.classic.joran;
-import java.util.Map;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
-import junit.framework.TestCase;
+import java.util.Map;
+import org.junit.Test;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;
@@ -27,9 +29,10 @@
import ch.qos.logback.core.joran.spi.JoranException;
-public class EvaluatorJoranTest extends TestCase {
+public class EvaluatorJoranTest {
- public void xtest() throws NullPointerException, EvaluationException, JoranException {
+ @Test
+ public void testSimpleEvaluator() throws NullPointerException, EvaluationException, JoranException {
JoranConfigurator jc = new JoranConfigurator();
LoggerContext loggerContext = new LoggerContext();
jc.setContext(loggerContext);
@@ -50,6 +53,7 @@
//StatusPrinter.print(loggerContext.getStatusManager());
}
+ @Test
public void testIgnoreMarker() throws NullPointerException, EvaluationException, JoranException {
JoranConfigurator jc = new JoranConfigurator();
LoggerContext loggerContext = new LoggerContext();
@@ -80,6 +84,7 @@
//StatusPrinter.print(loggerContext.getStatusManager());
}
+ @Test
public void testMultipleConditionsInExpression() throws NullPointerException, EvaluationException {
LoggerContext loggerContext = new LoggerContext();
Logger logger = loggerContext.getLogger("xx");
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/PackageTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/PackageTest.java Fri Dec 26 14:55:28 2008
@@ -1,22 +1,20 @@
-/**
- * LOGBack: the reliable, fast and flexible logging library for Java.
- *
- * Copyright (C) 1999-2005, QOS.ch, LOGBack.com
- *
- * This library is free software, you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation.
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
*/
package ch.qos.logback.classic.joran;
-import junit.framework.*;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
-public class PackageTest extends TestCase {
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new JUnit4TestAdapter(JoranConfiguratorTest.class));
- suite.addTestSuite(EvaluatorJoranTest.class);
- return suite;
- }
+ at RunWith(Suite.class)
+ at SuiteClasses( { JoranConfiguratorTest.class, EvaluatorJoranTest.class})
+public class PackageTest {
}
\ No newline at end of file
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java Fri Dec 26 14:55:28 2008
@@ -1,11 +1,19 @@
package ch.qos.logback.classic.net;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.util.Properties;
import javax.jms.ObjectMessage;
import javax.naming.Context;
-import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.net.mock.MockTopic;
import ch.qos.logback.classic.net.mock.MockTopicConnectionFactory;
@@ -15,13 +23,14 @@
import ch.qos.logback.classic.util.MockInitialContextFactory;
import ch.qos.logback.core.ContextBase;
-public class JMSTopicAppenderTest extends TestCase {
+public class JMSTopicAppenderTest {
ch.qos.logback.core.Context context;
JMSTopicAppender appender;
- @Override
- protected void setUp() throws Exception {
+
+ @Before
+ public void setUp() throws Exception {
context = new ContextBase();
appender = new JMSTopicAppender();
appender.setContext(context);
@@ -34,17 +43,17 @@
MockInitialContext mic = MockInitialContextFactory.getContext();
mic.map.put(appender.tcfBindingName, new MockTopicConnectionFactory());
mic.map.put(appender.topicBindingName, new MockTopic(appender.topicBindingName));
-
- super.setUp();
+
}
- @Override
- protected void tearDown() throws Exception {
+
+ @After
+ public void tearDown() throws Exception {
appender = null;
context = null;
- super.tearDown();
}
+ @Test
public void testAppendOk() {
appender.start();
@@ -61,6 +70,7 @@
}
}
+ @Test
public void testAppendFailure() {
appender.start();
@@ -78,6 +88,7 @@
assertFalse(appender.isStarted());
}
+ @Test
public void testBuildEnvProperties() {
appender.setInitialContextFactoryName("icfn");
appender.setProviderURL("url");
@@ -98,6 +109,7 @@
.getProperty(Context.SECURITY_CREDENTIALS));
}
+ @Test
public void testBuildEnvPropertiesWithNullProviderURL() {
appender.setInitialContextFactoryName("icfn");
appender.setProviderURL(null);
@@ -120,6 +132,7 @@
assertEquals(1, context.getStatusManager().getCount());
}
+ @Test
public void testBuildEnvPropertiesWithNullCredentials() {
appender.setInitialContextFactoryName("icfn");
appender.setProviderURL("url");
@@ -142,6 +155,7 @@
assertEquals(1, context.getStatusManager().getCount());
}
+ @Test
public void testBuildEnvPropertiesWithPkgNull() {
appender.setInitialContextFactoryName("icfn");
appender.setProviderURL("url");
@@ -164,6 +178,7 @@
assertEquals(0, context.getStatusManager().getCount());
}
+ @Test
public void testStartMinimalInfo() {
//let's leave only what's in the setup()
//method, minus the providerURL
@@ -179,6 +194,7 @@
}
}
+ @Test
public void testStartUserPass() {
appender.setUserName("test");
appender.setPassword("test");
@@ -194,6 +210,7 @@
}
}
+ @Test
public void testStartFails() {
appender.topicBindingName = null;
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/PackageTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/PackageTest.java Fri Dec 26 14:55:28 2008
@@ -9,20 +9,12 @@
*/
package ch.qos.logback.classic.net;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
-import junit.framework.JUnit4TestAdapter;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-public class PackageTest extends TestCase {
-
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new JUnit4TestAdapter(SyslogAppenderTest.class));
- suite.addTest(new JUnit4TestAdapter(DilutedSMTPAppenderTest.class));
- suite.addTest(new JUnit4TestAdapter(SocketAppenderTest.class));
- suite.addTestSuite(JMSTopicAppenderTest.class);
- return suite;
- }
+ at RunWith(Suite.class)
+ at SuiteClasses( { SyslogAppenderTest.class, DilutedSMTPAppenderTest.class,
+ SocketAppenderTest.class, JMSTopicAppenderTest.class })
+public class PackageTest {
}
\ No newline at end of file
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/MDCConverterTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/MDCConverterTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/MDCConverterTest.java Fri Dec 26 14:55:28 2008
@@ -1,7 +1,10 @@
package ch.qos.logback.classic.pattern;
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.slf4j.MDC;
import ch.qos.logback.classic.Level;
@@ -9,23 +12,26 @@
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.util.SystemInfo;
-public class MDCConverterTest extends TestCase {
+public class MDCConverterTest {
LoggerContext lc;
MDCConverter converter;
+ @Before
public void setUp() throws Exception {
lc = new LoggerContext();
converter = new MDCConverter();
converter.start();
}
+ @After
public void tearDown() throws Exception {
lc = null;
converter.stop();
converter = null;
}
+ @Test
public void testConverWithOneEntry() {
MDC.clear();
MDC.put("testKey", "testValue");
@@ -34,6 +40,7 @@
assertEquals("testKey=testValue", result);
}
+ @Test
public void testConverWithMultipleEntries() {
MDC.clear();
MDC.put("testKey", "testValue");
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/MarkerConverterTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/MarkerConverterTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/MarkerConverterTest.java Fri Dec 26 14:55:28 2008
@@ -1,7 +1,10 @@
package ch.qos.logback.classic.pattern;
-import junit.framework.TestCase;
+import static org.junit.Assert.*;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.slf4j.IMarkerFactory;
import org.slf4j.Marker;
import org.slf4j.helpers.BasicMarkerFactory;
@@ -10,30 +13,34 @@
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.LoggingEvent;
-public class MarkerConverterTest extends TestCase {
+public class MarkerConverterTest {
LoggerContext lc;
MarkerConverter converter;
// use a different facotry for each test so that they are independent
IMarkerFactory markerFactory = new BasicMarkerFactory();
+ @Before
public void setUp() throws Exception {
lc = new LoggerContext();
converter = new MarkerConverter();
converter.start();
}
+ @After
public void tearDown() throws Exception {
lc = null;
converter.stop();
converter = null;
}
+ @Test
public void testWithNullMarker() {
String result = converter.convert(createLoggingEvent(null));
assertEquals("", result);
}
+ @Test
public void testWithMarker() {
String name = "test";
Marker marker = markerFactory.getMarker(name);
@@ -41,6 +48,7 @@
assertEquals(name, result);
}
+ @Test
public void testWithOneChildMarker() {
Marker marker = markerFactory.getMarker("test");
marker.add(markerFactory.getMarker("child"));
@@ -50,6 +58,7 @@
assertEquals("test [ child ]", result);
}
+ @Test
public void testWithSeveralChildMarker() {
Marker marker = markerFactory.getMarker("testParent");
marker.add(markerFactory.getMarker("child1"));
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/PackageTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/PackageTest.java Fri Dec 26 14:55:28 2008
@@ -1,28 +1,22 @@
/**
- * LOGBack: the reliable, fast and flexible logging library for Java.
- *
- * Copyright (C) 1999-2006, QOS.ch
- *
- * This library is free software, you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation.
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
*/
package ch.qos.logback.classic.pattern;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
-import junit.framework.JUnit4TestAdapter;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+ at RunWith(Suite.class)
+ at SuiteClasses( { ConverterTest.class,
+ TargetLengthBasedClassNameAbbreviatorTest.class, MDCConverterTest.class,
+ MarkerConverterTest.class })
+public class PackageTest {
-public class PackageTest extends TestCase {
-
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new JUnit4TestAdapter(ConverterTest.class));
- suite.addTest(new JUnit4TestAdapter(TargetLengthBasedClassNameAbbreviatorTest.class));
- suite.addTestSuite(MDCConverterTest.class);
- suite.addTestSuite(MarkerConverterTest.class);
- return suite;
- }
}
\ No newline at end of file
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextDetachingSCLTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextDetachingSCLTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextDetachingSCLTest.java Fri Dec 26 14:55:28 2008
@@ -1,7 +1,10 @@
package ch.qos.logback.classic.selector;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.slf4j.LoggerFactory;
import org.slf4j.impl.StaticLoggerBinder;
@@ -10,14 +13,14 @@
import ch.qos.logback.classic.util.MockInitialContext;
import ch.qos.logback.classic.util.MockInitialContextFactory;
-public class ContextDetachingSCLTest extends TestCase {
+public class ContextDetachingSCLTest {
static String INITIAL_CONTEXT_KEY = "java.naming.factory.initial";
ContextDetachingSCL listener;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
System.setProperty(ClassicGlobal.LOGBACK_CONTEXT_SELECTOR, "JNDI");
//LoggerFactory.setup();
@@ -33,21 +36,22 @@
//this call will create the context "toto"
LoggerFactory.getLogger(ContextDetachingSCLTest.class);
- super.setUp();
}
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
System.clearProperty(INITIAL_CONTEXT_KEY);
- super.tearDown();
}
-
+
+ @Test
public void testDetach() {
ContextJNDISelector selector = (ContextJNDISelector) StaticLoggerBinder.getSingleton().getContextSelector();
listener.contextDestroyed(null);
assertEquals(0, selector.getCount());
}
+
+ @Test
public void testDetachWithMissingContext() {
MockInitialContext mic = MockInitialContextFactory.getContext();
mic.map.put(ClassicGlobal.JNDI_CONTEXT_NAME, "tata");
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/PackageTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/PackageTest.java Fri Dec 26 14:55:28 2008
@@ -9,14 +9,11 @@
*/
package ch.qos.logback.classic.selector;
-import junit.framework.*;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
-public class PackageTest extends TestCase {
-
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new JUnit4TestAdapter(ContextJNDISelectorTest.class));
- suite.addTestSuite(ContextDetachingSCLTest.class);
- return suite;
- }
+ at RunWith(Suite.class)
+ at SuiteClasses({ContextJNDISelectorTest.class, ContextDetachingSCLTest.class})
+public class PackageTest {
}
\ No newline at end of file
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/CallerDataTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/CallerDataTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/CallerDataTest.java Fri Dec 26 14:55:28 2008
@@ -1,21 +1,15 @@
package ch.qos.logback.classic.spi;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
-public class CallerDataTest extends TestCase {
+import org.junit.Test;
- public CallerDataTest(String name) {
- super(name);
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- }
+public class CallerDataTest {
- protected void tearDown() throws Exception {
- super.tearDown();
- }
+ @Test
public void testBasic() {
Throwable t = new Throwable();
StackTraceElement[] steArray = t.getStackTrace();
@@ -31,6 +25,7 @@
* extracted, CallerData.extract does not throw an exception
*
*/
+ @Test
public void testDeferredProcessing() {
CallerData[] cda = CallerData.extract(new Throwable(), "com.inexistent.foo");
assertNotNull(cda);
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/ContextListenerTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/ContextListenerTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/ContextListenerTest.java Fri Dec 26 14:55:28 2008
@@ -1,27 +1,33 @@
package ch.qos.logback.classic.spi;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.BasicContextListener.UpdateType;
-public class ContextListenerTest extends TestCase {
+public class ContextListenerTest {
LoggerContext context;
BasicContextListener listener;
+ @Before
public void setUp() throws Exception {
context = new LoggerContext();
listener = new BasicContextListener();
context.addListener(listener);
- super.setUp();
}
-
+
+ @Test
public void testNotifyOnReset() {
context.reset();
assertEquals(UpdateType.RESET, listener.updateType);
assertEquals(listener.context, context);
}
+ @Test
public void testNotifyOnStopResistant() {
listener.setResetResistant(true);
context.stop();
@@ -29,13 +35,14 @@
assertEquals(listener.context, context);
}
+ @Test
public void testNotifyOnStopNotResistant() {
context.stop();
assertEquals(UpdateType.RESET, listener.updateType);
assertEquals(listener.context, context);
}
-
+ @Test
public void testNotifyOnStart() {
context.start();
assertEquals(UpdateType.START, listener.updateType);
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/PackageTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/spi/PackageTest.java Fri Dec 26 14:55:28 2008
@@ -9,23 +9,14 @@
*/
package ch.qos.logback.classic.spi;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
-import junit.framework.JUnit4TestAdapter;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-public class PackageTest extends TestCase {
-
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTestSuite(ContextListenerTest.class);
- suite.addTestSuite(CallerDataTest.class);
- suite.addTest(new JUnit4TestAdapter (LoggerComparatorTest.class));
- suite.addTest(new JUnit4TestAdapter (LoggingEventSerializationTest.class));
- suite.addTest(new JUnit4TestAdapter(LoggingEventSerializationPerfTest.class));
- suite.addTest(new JUnit4TestAdapter(ThrowableToDataPointTest.class));
- suite.addTest(new JUnit4TestAdapter(BasicCPDCTest.class));
- return suite;
- }
+ at RunWith(Suite.class)
+ at SuiteClasses( { ContextListenerTest.class, CallerDataTest.class,
+ LoggerComparatorTest.class, LoggingEventSerializationTest.class,
+ LoggingEventSerializationPerfTest.class, ThrowableToDataPointTest.class,
+ BasicCPDCTest.class })
+public class PackageTest {
}
\ No newline at end of file
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/PackageTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/PackageTest.java Fri Dec 26 14:55:28 2008
@@ -10,17 +10,12 @@
package ch.qos.logback.classic.util;
-import junit.framework.JUnit4TestAdapter;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
-public class PackageTest extends TestCase {
-
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new JUnit4TestAdapter(InitializationTest.class));
- suite.addTest(new JUnit4TestAdapter(LevelToSyslogSeverityTest.class));
- return suite;
- }
+ at RunWith(Suite.class)
+ at SuiteClasses({InitializationTest.class, LevelToSyslogSeverityTest.class} )
+
+public class PackageTest {
}
\ No newline at end of file
Modified: logback/trunk/logback-classic/src/test/java/org/slf4j/impl/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/org/slf4j/impl/PackageTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/org/slf4j/impl/PackageTest.java Fri Dec 26 14:55:28 2008
@@ -9,14 +9,14 @@
*/
package org.slf4j.impl;
-import junit.framework.*;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
-public class PackageTest extends TestCase {
+import ch.qos.logback.classic.LoggerPerfTest;
+
+ at RunWith(Suite.class)
+ at SuiteClasses( { RecursiveInitializationTest.class, LoggerPerfTest.class})
+public class PackageTest {
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new JUnit4TestAdapter(RecursiveInitializationTest.class));
- suite.addTest(new JUnit4TestAdapter(LogbackMDCAdapterTest.class));
- return suite;
- }
}
\ No newline at end of file
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/Appender.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/Appender.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/Appender.java Fri Dec 26 14:55:28 2008
@@ -14,7 +14,7 @@
import ch.qos.logback.core.spi.LifeCycle;
-public interface Appender<E> extends LifeCycle, ContextAware, FilterAttachable {
+public interface Appender<E> extends LifeCycle, ContextAware, FilterAttachable<E> {
/**
* Get the name of this appender. The name uniquely identifies the appender.
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/AppenderBase.java Fri Dec 26 14:55:28 2008
@@ -11,22 +11,20 @@
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.ContextAwareBase;
-import ch.qos.logback.core.spi.FilterAttachable;
import ch.qos.logback.core.spi.FilterAttachableImpl;
-import ch.qos.logback.core.spi.FilterReply;
+import ch.qos.logback.core.spi.FilterReply;
import ch.qos.logback.core.status.WarnStatus;
/**
* Sets a skeleton implementation for appenders.
*
- * <p>
- * For more information about this appender, please refer to the online manual at
- * http://logback.qos.ch/manual/appenders.html#AppenderBase
- *
+ * <p> For more information about this appender, please refer to the online
+ * manual at http://logback.qos.ch/manual/appenders.html#AppenderBase
+ *
* @author Ceki Gülcü
*/
abstract public class AppenderBase<E> extends ContextAwareBase implements
- Appender<E>, FilterAttachable {
+ Appender<E> {
protected boolean started = false;
@@ -41,7 +39,7 @@
*/
protected String name;
- private FilterAttachableImpl fai = new FilterAttachableImpl();
+ private FilterAttachableImpl<E> fai = new FilterAttachableImpl<E>();
public String getName() {
return name;
@@ -49,10 +47,9 @@
private int statusRepeatCount = 0;
private int exceptionCount = 0;
-
+
static final int ALLOWED_REPEATS = 5;
-
public synchronized void doAppend(E eventObject) {
// WARNING: The guard check MUST be the first statement in the
// doAppend() method.
@@ -77,15 +74,15 @@
if (getFilterChainDecision(eventObject) == FilterReply.DENY) {
return;
}
-
+
// ok, we now invoke derived class' implementation of append
this.append(eventObject);
- } catch(Exception e) {
+ } catch (Exception e) {
if (exceptionCount++ < ALLOWED_REPEATS) {
- addError("Appender ["+name+"] failed to append.", e);
+ addError("Appender [" + name + "] failed to append.", e);
}
- } finally {
+ } finally {
guard = false;
}
}
@@ -115,7 +112,7 @@
return this.getClass().getName() + "[" + name + "]";
}
- public void addFilter(Filter newFilter) {
+ public void addFilter(Filter<E> newFilter) {
fai.addFilter(newFilter);
}
@@ -127,10 +124,10 @@
fai.clearAllFilters();
}
- public FilterReply getFilterChainDecision(Object event) {
+ public FilterReply getFilterChainDecision(E event) {
return fai.getFilterChainDecision(event);
}
-
+
public Layout<E> getLayout() {
return null;
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/UnsynchronizedAppenderBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/UnsynchronizedAppenderBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/UnsynchronizedAppenderBase.java Fri Dec 26 14:55:28 2008
@@ -11,7 +11,6 @@
import ch.qos.logback.core.filter.Filter;
import ch.qos.logback.core.spi.ContextAwareBase;
-import ch.qos.logback.core.spi.FilterAttachable;
import ch.qos.logback.core.spi.FilterAttachableImpl;
import ch.qos.logback.core.spi.FilterReply;
import ch.qos.logback.core.status.WarnStatus;
@@ -24,7 +23,7 @@
* @author Ralph Goers
*/
abstract public class UnsynchronizedAppenderBase<E> extends ContextAwareBase implements
- Appender<E>, FilterAttachable {
+ Appender<E> {
protected boolean started = false;
@@ -46,7 +45,7 @@
*/
protected String name;
- private FilterAttachableImpl fai = new FilterAttachableImpl();
+ private FilterAttachableImpl<E> fai = new FilterAttachableImpl<E>();
public String getName() {
return name;
@@ -119,7 +118,7 @@
return this.getClass().getName() + "[" + name + "]";
}
- public void addFilter(Filter newFilter) {
+ public void addFilter(Filter<E> newFilter) {
fai.addFilter(newFilter);
}
@@ -131,7 +130,7 @@
fai.clearAllFilters();
}
- public FilterReply getFilterChainDecision(Object event) {
+ public FilterReply getFilterChainDecision(E event) {
return fai.getFilterChainDecision(event);
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/EventEvaluator.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/EventEvaluator.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/EventEvaluator.java Fri Dec 26 14:55:28 2008
@@ -24,7 +24,7 @@
* @author Ceki Gülcü
*/
-public interface EventEvaluator extends ContextAware, LifeCycle {
+public interface EventEvaluator<E> extends ContextAware, LifeCycle {
/**
@@ -40,7 +40,7 @@
* @throws NullPointerException can be thrown in presence of null values
* @throws EvaluationException Thrown during evaluation
*/
- boolean evaluate(Object event) throws NullPointerException, EvaluationException;
+ boolean evaluate(E event) throws NullPointerException, EvaluationException;
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/EventEvaluatorBase.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/EventEvaluatorBase.java Fri Dec 26 14:55:28 2008
@@ -0,0 +1,45 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.core.boolex;
+
+import ch.qos.logback.core.spi.ContextAwareBase;
+
+abstract public class EventEvaluatorBase<E> extends ContextAwareBase implements
+ EventEvaluator<E> {
+
+ String name;
+ boolean started;
+
+ public String getName() {
+
+ return name;
+ }
+
+ public void setName(String name) {
+ if (this.name != null) {
+ throw new IllegalStateException("name has been already set");
+ }
+ this.name = name;
+ }
+
+ public boolean isStarted() {
+ return started;
+ }
+
+ public void start() {
+ started = true;
+
+ }
+
+ public void stop() {
+ started = false;
+ }
+
+}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/JaninoEventEvaluatorBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/JaninoEventEvaluatorBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/JaninoEventEvaluatorBase.java Fri Dec 26 14:55:28 2008
@@ -5,11 +5,7 @@
import org.codehaus.janino.ExpressionEvaluator;
-import ch.qos.logback.core.spi.ContextAwareBase;
-import ch.qos.logback.core.spi.LifeCycle;
-
-abstract public class JaninoEventEvaluatorBase extends ContextAwareBase
- implements EventEvaluator, LifeCycle {
+abstract public class JaninoEventEvaluatorBase<E> extends EventEvaluatorBase<E>{
static Class EXPRESSION_TYPE = boolean.class;
static Class[] THROWN_EXCEPTIONS = new Class[1];
@@ -19,10 +15,7 @@
THROWN_EXCEPTIONS[0] = EvaluationException.class;
}
-
- protected boolean start = false;
- private String name;
private String expression;
ExpressionEvaluator ee;
@@ -34,33 +27,26 @@
abstract protected Class[] getParameterTypes();
- abstract protected Object[] getParameterValues(Object event);
+ abstract protected Object[] getParameterValues(E event);
protected List<Matcher> matcherList = new ArrayList<Matcher>();
- public boolean isStarted() {
- return start;
- }
-
- public void stop() {
- start = false;
- }
-
+ @Override
public void start() {
try {
assert context != null;
ClassLoader cl = context.getClass().getClassLoader();
ee = new ExpressionEvaluator(getDecoratedExpression(), EXPRESSION_TYPE,
getParameterNames(), getParameterTypes(), THROWN_EXCEPTIONS, cl);
- start = true;
+ super.start();
} catch (Exception e) {
addError(
"Could not start evaluator with expression [" + expression + "]", e);
}
}
- public boolean evaluate(Object event) throws EvaluationException {
- if (!start) {
+ public boolean evaluate(E event) throws EvaluationException {
+ if (!isStarted()) {
throw new IllegalStateException("Evaluator [" + name + "] was called in stopped state");
}
try {
@@ -69,24 +55,13 @@
} catch (Exception ex) {
errorCount++;
if (errorCount >= ERROR_THRESHOLD) {
- start = false;
+ stop();
}
throw new EvaluationException("Evaluator [" + name
+ "] caused an exception", ex);
}
}
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- if (this.name != null) {
- throw new IllegalStateException("name has been already set");
- }
- this.name = name;
- }
-
public String getExpression() {
return expression;
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/Matcher.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/Matcher.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/boolex/Matcher.java Fri Dec 26 14:55:28 2008
@@ -1,3 +1,12 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
package ch.qos.logback.core.boolex;
import java.util.regex.Pattern;
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractMatcherFilter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractMatcherFilter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractMatcherFilter.java Fri Dec 26 14:55:28 2008
@@ -2,7 +2,7 @@
import ch.qos.logback.core.spi.FilterReply;
-public abstract class AbstractMatcherFilter extends Filter {
+public abstract class AbstractMatcherFilter<E> extends Filter<E> {
protected FilterReply onMatch = FilterReply.NEUTRAL;
protected FilterReply onMismatch = FilterReply.NEUTRAL;
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java Fri Dec 26 14:55:28 2008
@@ -22,9 +22,9 @@
* @author Sébastien Pennec
*/
-public class EvaluatorFilter extends AbstractMatcherFilter {
+public class EvaluatorFilter<E> extends AbstractMatcherFilter<E> {
- EventEvaluator evaluator;
+ EventEvaluator<E> evaluator;
@Override
public void start() {
@@ -35,16 +35,16 @@
}
}
- public EventEvaluator getEvaluator() {
+ public EventEvaluator<E> getEvaluator() {
return evaluator;
}
- public void setEvaluator(EventEvaluator evaluator) {
+ public void setEvaluator(EventEvaluator<E> evaluator) {
this.evaluator = evaluator;
}
- public FilterReply decide(Object event) {
+ public FilterReply decide(E event) {
// let us not throw an exception
// see also bug #17.
if(!isStarted() || !evaluator.isStarted()) {
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/Filter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/Filter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/Filter.java Fri Dec 26 14:55:28 2008
@@ -5,25 +5,20 @@
import ch.qos.logback.core.spi.LifeCycle;
/**
- * Users should extend this class to implement customized event filtering in
- * addition to the build-in filtering rules. It is suggested that you first use
- * and understand the built-in rules before rushing to write your own custom
- * filters.
- * <p>
- * For more information about filters, please refer to the online manual at
+ * Users should extend this class to implement customized event filtering.
+ *
+ * <p>We suggest that you first try to use the built-in rules before rushing to
+ * write your own custom filters.
+ *
+ * <p>For more information about filters, please refer to the online manual at
* http://logback.qos.ch/manual/filters.html
*
* @author Ceki Gülcü
*/
-public abstract class Filter extends ContextAwareBase implements LifeCycle {
+public abstract class Filter<E> extends ContextAwareBase implements LifeCycle {
- /**
- * Points to the next filter in the filter chain.
- */
- private Filter next;
-
private String name;
-
+
boolean start = false;
public void start() {
@@ -46,23 +41,9 @@
* consulting with other filters in the chain.
*
* @param event
- * The event to decide upon.
+ * The event to decide upon.
*/
- public abstract FilterReply decide(Object event);
-
- /**
- * Set the next filter pointer.
- */
- public void setNext(Filter next) {
- this.next = next;
- }
-
- /**
- * Return the pointer to the next filter;
- */
- public Filter getNext() {
- return next;
- }
+ public abstract FilterReply decide(E event);
public String getName() {
return name;
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AbstractEventEvaluatorAction.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AbstractEventEvaluatorAction.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AbstractEventEvaluatorAction.java Fri Dec 26 14:55:28 2008
@@ -1,7 +1,7 @@
/**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
*
- * Copyright (C) 1999-2006, QOS.ch
+ * Copyright (C) 2000-2008, QOS.ch
*
* This library is free software, you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
@@ -10,8 +10,6 @@
package ch.qos.logback.core.joran.action;
-
-
import java.util.Map;
import org.xml.sax.Attributes;
@@ -23,59 +21,57 @@
import ch.qos.logback.core.spi.LifeCycle;
import ch.qos.logback.core.util.OptionHelper;
-
abstract public class AbstractEventEvaluatorAction extends Action {
-
+
EventEvaluator evaluator;
boolean inError = false;
/**
* Instantiates an evaluator of the given class and sets its name.
*/
+ @SuppressWarnings("unchecked")
public void begin(InterpretationContext ec, String name, Attributes attributes) {
// Let us forget about previous errors (in this instance)
inError = false;
evaluator = null;
-
+
String className = attributes.getValue(CLASS_ATTRIBUTE);
- if(OptionHelper.isEmpty(className)) {
+ if (OptionHelper.isEmpty(className)) {
className = defaultClassName();
- addWarn("Assuming default evaluator class ["+className+"]");
+ addWarn("Assuming default evaluator class [" + className + "]");
}
- if(OptionHelper.isEmpty(className)) {
+ if (OptionHelper.isEmpty(className)) {
className = defaultClassName();
inError = true;
- addError("Mandatory \""+CLASS_ATTRIBUTE+"\" attribute not set for <evaluator>");
+ addError("Mandatory \"" + CLASS_ATTRIBUTE
+ + "\" attribute not set for <evaluator>");
return;
}
-
+
String evaluatorName = attributes.getValue(Action.NAME_ATTRIBUTE);
- if(OptionHelper.isEmpty(evaluatorName)) {
+ if (OptionHelper.isEmpty(evaluatorName)) {
inError = true;
- addError("Mandatory \""+NAME_ATTRIBUTE+"\" attribute not set for <evaluator>");
+ addError("Mandatory \"" + NAME_ATTRIBUTE
+ + "\" attribute not set for <evaluator>");
return;
}
try {
- evaluator = (EventEvaluator)
- OptionHelper.instantiateByClassName(
+ evaluator = (EventEvaluator) OptionHelper.instantiateByClassName(
className, ch.qos.logback.core.boolex.EventEvaluator.class, context);
-
- if(isOfCorrectType(evaluator)) {
- evaluator.setContext(this.context);
- evaluator.setName(evaluatorName);
-
- if (ec.getObjectStack().size() > 0 && ec.peekObject() instanceof EvaluatorFilter) {
- ((EvaluatorFilter)ec.peekObject()).setEvaluator(evaluator);
- }
-
- ec.pushObject(evaluator);
- addInfo("Adding evaluator named ["+evaluatorName+"] to the object stack");
- } else {
- inError = true;
- addError("Evaluator of type ["+className+"] is not of the desired type");
+
+ evaluator.setContext(this.context);
+ evaluator.setName(evaluatorName);
+
+ if (ec.getObjectStack().size() > 0
+ && ec.peekObject() instanceof EvaluatorFilter) {
+ ((EvaluatorFilter) ec.peekObject()).setEvaluator(evaluator);
}
+ ec.pushObject(evaluator);
+ addInfo("Adding evaluator named [" + evaluatorName
+ + "] to the object stack");
+
} catch (Exception oops) {
inError = true;
addError("Could not create evaluator of type " + className + "].", oops);
@@ -83,22 +79,15 @@
}
/**
- * Is the layout of the desired type?
- * @param layout
- * @return true if the layout is of the correct type
- */
- abstract protected boolean isOfCorrectType(EventEvaluator ee);
-
- /**
* Returns a default class name in case the class attribute is not specified
+ *
* @return
*/
abstract protected String defaultClassName();
-
-
+
/**
- * Once the children elements are also parsed, now is the time to activate
- * the evaluator options.
+ * Once the children elements are also parsed, now is the time to activate the
+ * evaluator options.
*/
@SuppressWarnings("unchecked")
public void end(InterpretationContext ec, String e) {
@@ -108,23 +97,22 @@
if (evaluator instanceof LifeCycle) {
((LifeCycle) evaluator).start();
- addInfo("Starting evaluator named ["+evaluator.getName()+"]");
+ addInfo("Starting evaluator named [" + evaluator.getName() + "]");
}
Object o = ec.peekObject();
if (o != evaluator) {
- addWarn(
- "The object on the top the of the stack is not the evaluator pushed earlier.");
+ addWarn("The object on the top the of the stack is not the evaluator pushed earlier.");
} else {
ec.popObject();
try {
- Map<String, EventEvaluator> evaluatorMap = (Map<String, EventEvaluator>) context.getObject(CoreConstants.EVALUATOR_MAP);
+ Map<String, EventEvaluator> evaluatorMap = (Map<String, EventEvaluator>) context
+ .getObject(CoreConstants.EVALUATOR_MAP);
evaluatorMap.put(evaluator.getName(), evaluator);
} catch (Exception ex) {
- addError(
- "Could not set evaluator named ["+evaluator+"].", ex);
+ addError("Could not set evaluator named [" + evaluator + "].", ex);
}
}
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/IADataForComplexProperty.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/IADataForComplexProperty.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/IADataForComplexProperty.java Fri Dec 26 14:55:28 2008
@@ -12,7 +12,7 @@
final PropertySetter parentBean;
final AggregationType aggregationType;
final String complexPropertyName;
- Object nestedComplexProperty;
+ private Object nestedComplexProperty;
boolean inError;
public IADataForComplexProperty(PropertySetter parentBean, AggregationType aggregationType, String complexPropertyName) {
@@ -32,6 +32,10 @@
public String getComplexPropertyName() {
return complexPropertyName;
}
+
+ public void setNestedComplexProperty(Object nestedComplexProperty) {
+ this.nestedComplexProperty = nestedComplexProperty;
+ }
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/MatcherAction.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/MatcherAction.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/MatcherAction.java Fri Dec 26 14:55:28 2008
@@ -27,6 +27,8 @@
public void begin(InterpretationContext ec, String localName, Attributes attributes)
throws ActionException {
+ // TODO can we replace MarcherAction by an implicit action?
+
matcher = null;
inError = false;
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComplexPropertyIA.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComplexPropertyIA.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComplexPropertyIA.java Fri Dec 26 14:55:28 2008
@@ -74,7 +74,8 @@
return true;
default:
- addError("PropertySetter.computeAggregationType returned " + aggregationType);
+ addError("PropertySetter.computeAggregationType returned "
+ + aggregationType);
return false;
}
}
@@ -89,43 +90,34 @@
String className = attributes.getValue(CLASS_ATTRIBUTE);
// perform variable name substitution
className = ec.subst(className);
- if (className == null) {
+
+ // guess class name via implicit rules
+ if (OptionHelper.isEmpty(className)) {
PropertySetter parentBean = actionData.parentBean;
- className = parentBean.getDefaultClassNameByAnnonation(actionData
+ className = parentBean.getClassNameViaImplicitRules(actionData
.getComplexPropertyName(), actionData.getAggregationType());
}
if (OptionHelper.isEmpty(className)) {
- Class clazz = actionData.parentBean
- .findUnequivocallyInstantiableClass(actionData);
- if (clazz != null) {
- className = clazz.getName();
- } else {
- actionData.inError = true;
- String errMsg = "No class name attribute in [" + localName + "]";
- addError(errMsg);
-
- return;
- }
+ actionData.inError = true;
+ String errMsg = "No class name attribute in [" + localName + "]";
+ addError(errMsg);
+ return;
}
try {
- // getLogger().debug(
- // "About to instantiate component [{}] of type [{}]", localName,
- // className);
-
- actionData.nestedComplexProperty = Loader.loadClass(className, context)
- .newInstance();
+ actionData.setNestedComplexProperty(Loader.loadClass(className, context)
+ .newInstance());
// pass along the repository
- if (actionData.nestedComplexProperty instanceof ContextAware) {
- ((ContextAware) actionData.nestedComplexProperty)
+ if (actionData.getNestedComplexProperty() instanceof ContextAware) {
+ ((ContextAware) actionData.getNestedComplexProperty())
.setContext(this.context);
}
// getLogger().debug(
addInfo("Pushing component [" + localName
+ "] on top of the object stack.");
- ec.pushObject(actionData.nestedComplexProperty);
+ ec.pushObject(actionData.getNestedComplexProperty());
} catch (Exception oops) {
actionData.inError = true;
String msg = "Could not create component [" + localName + "] of type ["
@@ -145,8 +137,8 @@
return;
}
- PropertySetter nestedBean = new PropertySetter(
- actionData.nestedComplexProperty);
+ PropertySetter nestedBean = new PropertySetter(actionData
+ .getNestedComplexProperty());
nestedBean.setContext(context);
// have the nested element point to its parent if possible
@@ -154,34 +146,26 @@
nestedBean.setComplexProperty("parent", actionData.parentBean.getObj());
}
// start the nested complex attribute if it implements LifeCycle
- if (actionData.nestedComplexProperty instanceof LifeCycle) {
- ((LifeCycle) actionData.nestedComplexProperty).start();
+ if (actionData.getNestedComplexProperty() instanceof LifeCycle) {
+ ((LifeCycle) actionData.getNestedComplexProperty()).start();
}
Object o = ec.peekObject();
- if (o != actionData.nestedComplexProperty) {
+ if (o != actionData.getNestedComplexProperty()) {
addError("The object on the top the of the stack is not the component pushed earlier.");
} else {
- // getLogger().debug("Removing component from the object stack");
ec.popObject();
-
// Now let us attach the component
switch (actionData.aggregationType) {
case AS_COMPLEX_PROPERTY:
- // addInfo("Setting ["+tagName+"}] to parent of type
- // ["+actionData.parentBean.getObjClass()+"]");
-
- actionData.parentBean.setComplexProperty(tagName,
- actionData.nestedComplexProperty);
+ actionData.parentBean.setComplexProperty(tagName, actionData
+ .getNestedComplexProperty());
break;
case AS_COMPLEX_PROPERTY_COLLECTION:
- // getLogger().debug(
- // "Adding [{}] to parent of type [{}]", tagName,
- // actionData.parentBean.getObjClass());
- actionData.parentBean.addComplexProperty(tagName,
- actionData.nestedComplexProperty);
+ actionData.parentBean.addComplexProperty(tagName, actionData
+ .getNestedComplexProperty());
break;
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/PropertySetter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/PropertySetter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/PropertySetter.java Fri Dec 26 14:55:28 2008
@@ -177,7 +177,7 @@
public AggregationType computeAggregationType(String name) {
String cName = capitalizeFirstLetter(name);
- Method addMethod = getMethod("add" + cName);
+ Method addMethod = findAdderMethod(cName);
// if the
if (addMethod != null) {
@@ -217,7 +217,7 @@
}
}
- Class<?> getParameterClassForMethod(Method method) {
+ private Class<?> getParameterClassForMethod(Method method) {
if (method == null) {
return null;
}
@@ -277,13 +277,19 @@
}
}
- boolean isUnequivocallyInstantiable(Class<?> clazz) {
+ /**
+ * Can the given clazz instantiable with certainty?
+ *
+ * @param clazz The class to test for instantiability
+ * @return true if clazz can be instantiated, and false otherwise.
+ */
+ private boolean isUnequivocallyInstantiable(Class<?> clazz) {
if (clazz.isInterface()) {
return false;
}
- // checking for constructors would be slightly more elegant, but in
- // classes
- // without any declared constructors, Class.getConstructor() returns null.
+ // checking for constructors would be more elegant, but in
+ // classes without any declared constructors, Class.getConstructor()
+ // returns null.
Object o;
try {
o = clazz.newInstance();
@@ -339,7 +345,7 @@
}
name = capitalizeFirstLetter(name);
- Method adderMethod = getMethod("add" + name);
+ Method adderMethod = findAdderMethod(name);
if (adderMethod == null) {
addError("No adder for property [" + name + "].");
@@ -530,17 +536,22 @@
return obj;
}
- public <T extends Annotation> T getAnnotation(String name,
- Class<T> annonationClass, AggregationType aggregationType) {
+ Method getRelevantMethod(String name, AggregationType aggregationType) {
String cName = capitalizeFirstLetter(name);
Method relevantMethod;
if (aggregationType == AggregationType.AS_COMPLEX_PROPERTY_COLLECTION) {
- relevantMethod = getMethod("add" + cName);
+ relevantMethod = findAdderMethod(cName);
} else if (aggregationType == AggregationType.AS_COMPLEX_PROPERTY) {
relevantMethod = findSetterMethod(cName);
} else {
throw new IllegalStateException(aggregationType + " not allowed here");
}
+ return relevantMethod;
+ }
+
+ <T extends Annotation> T getAnnotation(String name, Class<T> annonationClass,
+ Method relevantMethod) {
+
if (relevantMethod != null) {
return relevantMethod.getAnnotation(annonationClass);
} else {
@@ -548,11 +559,9 @@
}
}
- public String getDefaultClassNameByAnnonation(String name,
- AggregationType aggregationType) {
-
+ String getDefaultClassNameByAnnonation(String name, Method relevantMethod) {
DefaultClass defaultClassAnnon = getAnnotation(name, DefaultClass.class,
- aggregationType);
+ relevantMethod);
if (defaultClassAnnon != null) {
Class defaultClass = defaultClassAnnon.value();
if (defaultClass != null) {
@@ -561,4 +570,36 @@
}
return null;
}
+
+ String getByConcreteType(String name, Method relevantMethod) {
+
+ Class<?> paramType = getParameterClassForMethod(relevantMethod);
+ if (paramType == null) {
+ return null;
+ }
+
+ boolean isUnequivocallyInstantiable = isUnequivocallyInstantiable(paramType);
+ if(isUnequivocallyInstantiable) {
+ return paramType.getName();
+ } else {
+ return null;
+ }
+
+ }
+
+ public String getClassNameViaImplicitRules(String name,
+ AggregationType aggregationType) {
+
+ // find the relevant method for the given property name and aggregationType
+ Method relevantMethod = getRelevantMethod(name, aggregationType);
+ if (relevantMethod == null) {
+
+ }
+ String byAnnotation = getDefaultClassNameByAnnonation(name, relevantMethod);
+ if (byAnnotation != null) {
+ return byAnnotation;
+ }
+ return getByConcreteType(name, relevantMethod);
+ }
+
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/net/SMTPAppenderBase.java Fri Dec 26 14:55:28 2008
@@ -67,7 +67,7 @@
protected Message msg;
- protected EventEvaluator eventEvaluator;
+ protected EventEvaluator<E> eventEvaluator;
/**
* return a layout for the subjet string as appropriate for the module. If the
@@ -381,7 +381,7 @@
* corresponding object will be instantiated and assigned as the event
* evaluator for the SMTPAppender.
*/
- public void setEvaluator(EventEvaluator eventEvaluator) {
+ public void setEvaluator(EventEvaluator<E> eventEvaluator) {
this.eventEvaluator = eventEvaluator;
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachable.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachable.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachable.java Fri Dec 26 14:55:28 2008
@@ -16,11 +16,11 @@
*
* @author Ceki Gülcü
*/
-public interface FilterAttachable {
+public interface FilterAttachable<E> {
/**
* Add a filter.
*/
- public void addFilter(Filter newFilter);
+ public void addFilter(Filter<E> newFilter);
/**
* Get first filter in the chain.
@@ -34,5 +34,5 @@
* ACCEPT or DENY, then that value is returned. If all of the filters return
* NEUTRAL, then NEUTRAL is returned.
*/
- public FilterReply getFilterChainDecision(Object event);
+ public FilterReply getFilterChainDecision(E event);
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachableImpl.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachableImpl.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/FilterAttachableImpl.java Fri Dec 26 14:55:28 2008
@@ -1,14 +1,16 @@
/**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
- *
- * Copyright (C) 1999-2006, QOS.ch
- *
- * This library is free software, you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation.
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
*/
package ch.qos.logback.core.spi;
+import java.util.concurrent.CopyOnWriteArrayList;
+
import ch.qos.logback.core.filter.Filter;
/**
@@ -16,64 +18,45 @@
*
* @author Ceki Gülcü
*/
-final public class FilterAttachableImpl implements FilterAttachable {
+final public class FilterAttachableImpl<E> implements FilterAttachable<E> {
- Filter headFilter;
- Filter tailFilter;
+ CopyOnWriteArrayList<Filter<E>> filterList = new CopyOnWriteArrayList<Filter<E>>();
/**
* Add a filter to end of the filter list.
*/
- public void addFilter(Filter newFilter) {
- if (headFilter == null) {
- headFilter = newFilter;
- tailFilter = newFilter;
- } else {
- tailFilter.setNext(newFilter);
- tailFilter = newFilter;
- }
+ public void addFilter(Filter<E> newFilter) {
+ filterList.add(newFilter);
}
/**
* Get first filter in the chain.
*/
- public Filter getFirstFilter() {
- return headFilter;
+ public Filter<E> getFirstFilter() {
+ if (filterList.size() > 0) {
+ return filterList.get(0);
+ } else {
+ return null;
+ }
}
/**
* Clear the filter chain
*/
public void clearAllFilters() {
- Filter f = headFilter;
- while (f != null) {
- final Filter next = f.getNext();
- f.setNext(null);
- f = next;
- }
- f = null;
- headFilter = null;
- tailFilter = null;
+ filterList.clear();
}
/**
- * Loop through the filters in the chain. As soon as a filter decides on
+ * Loop through the filters in the list. As soon as a filter decides on
* ACCEPT or DENY, then that value is returned. If all of the filters return
- * NEUTRAL, then NEUTRAL is returned.
+ * NEUTRAL, then NEUTRAL is returned.
*/
- public FilterReply getFilterChainDecision(Object event) {
- Filter f = headFilter;
-
- while (f != null) {
- switch (f.decide(event)) {
- case DENY:
- return FilterReply.DENY;
-
- case ACCEPT:
- return FilterReply.ACCEPT;
-
- case NEUTRAL:
- f = f.getNext();
+ public FilterReply getFilterChainDecision(E event) {
+ for (Filter<E> f : filterList) {
+ final FilterReply r = f.decide(event);
+ if (r == FilterReply.DENY || r == FilterReply.ACCEPT) {
+ return r;
}
}
return FilterReply.NEUTRAL;
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PropertySetterTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PropertySetterTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PropertySetterTest.java Fri Dec 26 14:55:28 2008
@@ -1,7 +1,10 @@
package ch.qos.logback.core.joran.spi;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@@ -9,39 +12,51 @@
import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
-import ch.qos.logback.core.joran.action.IADataForComplexProperty;
import ch.qos.logback.core.spi.FilterReply;
import ch.qos.logback.core.util.AggregationType;
import ch.qos.logback.core.util.Duration;
import ch.qos.logback.core.util.FileSize;
import ch.qos.logback.core.util.StatusPrinter;
-public class PropertySetterTest {
+public class PropertySetterTest {
@Test
public void testCanAggregateComponent() {
House house = new House();
PropertySetter setter = new PropertySetter(house);
- assertEquals(AggregationType.AS_COMPLEX_PROPERTY, setter.computeAggregationType("door"));
-
- assertEquals(AggregationType.AS_BASIC_PROPERTY, setter.computeAggregationType("count"));
- assertEquals(AggregationType.AS_BASIC_PROPERTY, setter.computeAggregationType("Count"));
-
- assertEquals(AggregationType.AS_BASIC_PROPERTY, setter.computeAggregationType("name"));
- assertEquals(AggregationType.AS_BASIC_PROPERTY, setter.computeAggregationType("Name"));
-
- assertEquals(AggregationType.AS_BASIC_PROPERTY, setter.computeAggregationType("Duration"));
- assertEquals(AggregationType.AS_BASIC_PROPERTY, setter.computeAggregationType("fs"));
-
- assertEquals(AggregationType.AS_BASIC_PROPERTY, setter.computeAggregationType("open"));
- assertEquals(AggregationType.AS_BASIC_PROPERTY, setter.computeAggregationType("Open"));
-
- assertEquals(AggregationType.AS_COMPLEX_PROPERTY_COLLECTION, setter.computeAggregationType("Window"));
- assertEquals(AggregationType.AS_BASIC_PROPERTY_COLLECTION, setter.computeAggregationType("adjective"));
-
- assertEquals(AggregationType.AS_BASIC_PROPERTY, setter.computeAggregationType("filterReply"));
- assertEquals(AggregationType.AS_BASIC_PROPERTY, setter.computeAggregationType("houseColor"));
-
+ assertEquals(AggregationType.AS_COMPLEX_PROPERTY, setter
+ .computeAggregationType("door"));
+
+ assertEquals(AggregationType.AS_BASIC_PROPERTY, setter
+ .computeAggregationType("count"));
+ assertEquals(AggregationType.AS_BASIC_PROPERTY, setter
+ .computeAggregationType("Count"));
+
+ assertEquals(AggregationType.AS_BASIC_PROPERTY, setter
+ .computeAggregationType("name"));
+ assertEquals(AggregationType.AS_BASIC_PROPERTY, setter
+ .computeAggregationType("Name"));
+
+ assertEquals(AggregationType.AS_BASIC_PROPERTY, setter
+ .computeAggregationType("Duration"));
+ assertEquals(AggregationType.AS_BASIC_PROPERTY, setter
+ .computeAggregationType("fs"));
+
+ assertEquals(AggregationType.AS_BASIC_PROPERTY, setter
+ .computeAggregationType("open"));
+ assertEquals(AggregationType.AS_BASIC_PROPERTY, setter
+ .computeAggregationType("Open"));
+
+ assertEquals(AggregationType.AS_COMPLEX_PROPERTY_COLLECTION, setter
+ .computeAggregationType("Window"));
+ assertEquals(AggregationType.AS_BASIC_PROPERTY_COLLECTION, setter
+ .computeAggregationType("adjective"));
+
+ assertEquals(AggregationType.AS_BASIC_PROPERTY, setter
+ .computeAggregationType("filterReply"));
+ assertEquals(AggregationType.AS_BASIC_PROPERTY, setter
+ .computeAggregationType("houseColor"));
+
System.out.println();
}
@@ -58,7 +73,7 @@
assertEquals("jack", house.getName());
assertTrue(house.isOpen());
}
-
+
{
House house = new House();
PropertySetter setter = new PropertySetter(house);
@@ -76,14 +91,14 @@
public void testSetCamelProperty() {
House house = new House();
PropertySetter setter = new PropertySetter(house);
-
+
setter.setProperty("camelCase", "trot");
assertEquals("trot", house.getCamelCase());
-
+
setter.setProperty("camelCase", "gh");
assertEquals("gh", house.getCamelCase());
}
-
+
@Test
public void testSetComplexProperty() {
House house = new House();
@@ -94,20 +109,25 @@
}
@Test
- public void testSetComplexProperty2() {
+ public void testgetClassNameViaImplicitRules() {
House house = new House();
- //Door door = new Door();
PropertySetter setter = new PropertySetter(house);
-
- IADataForComplexProperty actionData = new IADataForComplexProperty(setter,
- AggregationType.AS_COMPLEX_PROPERTY, "door");
-
- Class clazz = setter.findUnequivocallyInstantiableClass(actionData);
- assertNotNull(clazz);
- assertEquals(Door.class.getName(), clazz.getName());
- //setter.setComplexProperty("door", door);
- //assertEquals(door, house.getDoor());
+ String className = setter.getClassNameViaImplicitRules("door",
+ AggregationType.AS_COMPLEX_PROPERTY);
+ assertEquals(Door.class.getName(), className);
}
+
+
+
+ @Test
+ public void testgetComplexPropertyColleClassNameViaImplicitRules() {
+ House house = new House();
+ PropertySetter setter = new PropertySetter(house);
+ String className = setter.getClassNameViaImplicitRules("window",
+ AggregationType.AS_COMPLEX_PROPERTY_COLLECTION);
+ assertEquals(Window.class.getName(), className);
+ }
+
@Test
public void testPropertyCollection() {
@@ -128,26 +148,26 @@
House house = new House();
PropertySetter setter = new PropertySetter(house);
Window w1 = new Window();
- w1.handle=10;
+ w1.handle = 10;
Window w2 = new Window();
- w2.handle=20;
-
+ w2.handle = 20;
+
setter.addComplexProperty("window", w1);
setter.addComplexProperty("window", w2);
assertEquals(2, house.windowList.size());
assertEquals(10, house.windowList.get(0).handle);
assertEquals(20, house.windowList.get(1).handle);
}
-
+
@Test
public void testSetComplexWithCamelCaseName() {
House house = new House();
- SwimmingPool pool = new SwimmingPool();
+ SwimmingPool pool = new SwimmingPoolImpl();
PropertySetter setter = new PropertySetter(house);
setter.setComplexProperty("swimmingPool", pool);
assertEquals(pool, house.getSwimmingPool());
}
-
+
@Test
public void testDuration() {
House house = new House();
@@ -161,18 +181,18 @@
House house = new House();
PropertySetter setter = new PropertySetter(house);
setter.setProperty("fs", "2 kb");
- assertEquals(2*1024, house.getFs().getSize());
+ assertEquals(2 * 1024, house.getFs().getSize());
}
-
+
@Test
public void testFilterReply() {
- //test case reproducing bug #52
+ // test case reproducing bug #52
House house = new House();
PropertySetter setter = new PropertySetter(house);
setter.setProperty("filterReply", "ACCEPT");
assertEquals(FilterReply.ACCEPT, house.getFilterReply());
}
-
+
@Test
public void testEnum() {
House house = new House();
@@ -180,14 +200,21 @@
setter.setProperty("houseColor", "BLUE");
assertEquals(HouseColor.BLUE, house.getHouseColor());
}
-
-
+
@Test
public void testDefaultClassAnnonation() {
House house = new House();
PropertySetter setter = new PropertySetter(house);
- String spClassName = setter.getDefaultClassNameByAnnonation("SwimmingPool", AggregationType.AS_COMPLEX_PROPERTY);
- assertEquals(SwimmingPool.class.getName(), spClassName);
+ Method relevantMethod = setter.getRelevantMethod("SwimmingPool",
+ AggregationType.AS_COMPLEX_PROPERTY);
+ assertNotNull(relevantMethod);
+ String spClassName = setter.getDefaultClassNameByAnnonation("SwimmingPool",
+ relevantMethod);
+ assertEquals(SwimmingPoolImpl.class.getName(), spClassName);
+
+ String classNameViaImplicitRules = setter.getClassNameViaImplicitRules(
+ "SwimmingPool", AggregationType.AS_COMPLEX_PROPERTY);
+ assertEquals(SwimmingPoolImpl.class.getName(), classNameViaImplicitRules);
}
}
@@ -202,10 +229,10 @@
FileSize fs;
HouseColor houseColor;
FilterReply reply;
-
+
List<String> adjectiveList = new ArrayList<String>();
List<Window> windowList = new ArrayList<Window>();
-
+
public String getCamelCase() {
return camelCase;
}
@@ -245,20 +272,19 @@
public void setOpen(boolean open) {
this.open = open;
}
-
- @DefaultClass(SwimmingPool.class)
+
+ @DefaultClass(SwimmingPoolImpl.class)
public void setSwimmingPool(SwimmingPool pool) {
this.pool = pool;
}
-
+
public SwimmingPool getSwimmingPool() {
return pool;
}
-
+
public void addWindow(Window w) {
windowList.add(w);
}
-
public void addAdjective(String s) {
adjectiveList.add(s);
@@ -279,23 +305,23 @@
public void setFs(FileSize fs) {
this.fs = fs;
}
-
+
public void setHouseColor(HouseColor color) {
this.houseColor = color;
}
-
+
public HouseColor getHouseColor() {
return houseColor;
}
-
+
public void setFilterReply(FilterReply reply) {
this.reply = reply;
}
-
+
public FilterReply getFilterReply() {
return reply;
}
-
+
}
class Door {
@@ -306,7 +332,10 @@
int handle;
}
-class SwimmingPool {
+interface SwimmingPool {
+}
+
+class SwimmingPoolImpl implements SwimmingPool {
int length;
int width;
int depth;
More information about the logback-dev
mailing list