Made implementation of AvalonLogger more robust (avoiding NPEs when nulls are passed in) together with a testcase. Improved build by compiling tests for only those optional components whose dependencies are present. Submitted by Neeme Praks.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@138983 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
52
build.xml
52
build.xml
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<!--
|
<!--
|
||||||
"Logging" component of the Jakarta Commons Subproject
|
"Logging" component of the Jakarta Commons Subproject
|
||||||
$Id: build.xml,v 1.36 2003/05/07 16:02:20 rdonkin Exp $
|
$Id: build.xml,v 1.37 2003/05/14 11:12:58 rdonkin Exp $
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
|
||||||
@@ -264,6 +264,39 @@
|
|||||||
</jar>
|
</jar>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
<target name='compile.jdk1.4.tests' if='jdk.1.4.present'>
|
||||||
|
<javac srcdir="${test.home}"
|
||||||
|
destdir="${build.home}/tests"
|
||||||
|
debug="${compile.debug}"
|
||||||
|
deprecation="${compile.deprecation}"
|
||||||
|
optimize="${compile.optimize}">
|
||||||
|
<classpath refid="test.classpath"/>
|
||||||
|
<include name='**/jdk14/**'/>
|
||||||
|
</javac>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name='compile.log4j.tests' if='log4j.present'>
|
||||||
|
<javac srcdir="${test.home}"
|
||||||
|
destdir="${build.home}/tests"
|
||||||
|
debug="${compile.debug}"
|
||||||
|
deprecation="${compile.deprecation}"
|
||||||
|
optimize="${compile.optimize}">
|
||||||
|
<classpath refid="test.classpath"/>
|
||||||
|
<include name='**/log4j/**'/>
|
||||||
|
</javac>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
<target name='compile.avalon.tests' if='avalon-framework.present'>
|
||||||
|
<javac srcdir="${test.home}"
|
||||||
|
destdir="${build.home}/tests"
|
||||||
|
debug="${compile.debug}"
|
||||||
|
deprecation="${compile.deprecation}"
|
||||||
|
optimize="${compile.optimize}">
|
||||||
|
<classpath refid="test.classpath"/>
|
||||||
|
<include name='**/avalon/**'/>
|
||||||
|
</javac>
|
||||||
|
</target>
|
||||||
|
|
||||||
<target name="compile.tests" depends="compile"
|
<target name="compile.tests" depends="compile"
|
||||||
description="Compile unit test cases">
|
description="Compile unit test cases">
|
||||||
@@ -273,7 +306,13 @@
|
|||||||
deprecation="${compile.deprecation}"
|
deprecation="${compile.deprecation}"
|
||||||
optimize="${compile.optimize}">
|
optimize="${compile.optimize}">
|
||||||
<classpath refid="test.classpath"/>
|
<classpath refid="test.classpath"/>
|
||||||
|
<exclude name='**/jdk14/**'/>
|
||||||
|
<exclude name='**/log4j/**'/>
|
||||||
|
<exclude name='**/avalon/**'/>
|
||||||
</javac>
|
</javac>
|
||||||
|
<antcall target='compile.log4j.tests'/>
|
||||||
|
<antcall target='compile.jdk1.4.tests'/>
|
||||||
|
<antcall target='compile.avalon.tests'/>
|
||||||
<copy todir="${build.home}/tests" filtering="on">
|
<copy todir="${build.home}/tests" filtering="on">
|
||||||
<fileset dir="${test.home}" excludes="**/*.java"/>
|
<fileset dir="${test.home}" excludes="**/*.java"/>
|
||||||
</copy>
|
</copy>
|
||||||
@@ -355,7 +394,7 @@
|
|||||||
<!-- ========== Unit Test Targets ========================================= -->
|
<!-- ========== Unit Test Targets ========================================= -->
|
||||||
|
|
||||||
|
|
||||||
<target name="test" depends="compile.tests,test.jdk14,test.log4j
|
<target name="test" depends="compile.tests,test.jdk14,test.log4j,test.avalon
|
||||||
" if="test.entry"
|
" if="test.entry"
|
||||||
description="Run all unit test cases">
|
description="Run all unit test cases">
|
||||||
<java classname="${test.runner}" fork="yes" failonerror="${test.failonerror}">
|
<java classname="${test.runner}" fork="yes" failonerror="${test.failonerror}">
|
||||||
@@ -605,5 +644,14 @@
|
|||||||
|
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
<target name="test.avalon" depends="compile.tests" if="avalon-framework.present"
|
||||||
|
description="Run unit tests specific to Avalon (Framework) logging">
|
||||||
|
|
||||||
|
<echo message="Avalon Tests"/>
|
||||||
|
<java classname="${test.runner}" fork="yes" failonerror="${test.failonerror}">
|
||||||
|
<arg value="org.apache.commons.logging.avalon.AvalonLoggerTest"/>
|
||||||
|
<classpath refid="test.classpath"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/avalon/src/java/org/apache/commons/jelly/avalon/JellyService.java,v 1.1 2003/01/22 09:19:30 jstrachan Exp
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/impl/AvalonLogger.java,v 1.2 2003/05/14 11:12:58 rdonkin Exp $
|
||||||
* 1.1
|
* $Revision: 1.2 $
|
||||||
* 2003/01/22 09:19:30
|
* $Date: 2003/05/14 11:12:58 $
|
||||||
*
|
*
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
@@ -57,7 +57,6 @@
|
|||||||
* information on the Apache Software Foundation, please see
|
* information on the Apache Software Foundation, please see
|
||||||
* <http://www.apache.org/>.
|
* <http://www.apache.org/>.
|
||||||
*
|
*
|
||||||
* JellyServiceImpl.java,v 1.1 2003/01/22 09:19:30 jstrachan Exp
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.commons.logging.impl;
|
package org.apache.commons.logging.impl;
|
||||||
@@ -70,6 +69,7 @@ import org.apache.commons.logging.Log;
|
|||||||
* logging calls to Avalon logging abstraction: the Logger interface.
|
* logging calls to Avalon logging abstraction: the Logger interface.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
|
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
|
||||||
|
* @version $Revision: 1.2 $ $Date: 2003/05/14 11:12:58 $
|
||||||
*/
|
*/
|
||||||
public class AvalonLogger implements Log {
|
public class AvalonLogger implements Log {
|
||||||
|
|
||||||
@@ -87,6 +87,8 @@ public class AvalonLogger implements Log {
|
|||||||
* @param logger the avalon logger implementation to delegate to
|
* @param logger the avalon logger implementation to delegate to
|
||||||
*/
|
*/
|
||||||
public AvalonLogger(String name) {
|
public AvalonLogger(String name) {
|
||||||
|
if (defaultLogger == null)
|
||||||
|
throw new NullPointerException("default logger has to be specified if this constructor is used!");
|
||||||
this.logger = defaultLogger.getChildLogger(name);
|
this.logger = defaultLogger.getChildLogger(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,56 +110,56 @@ public class AvalonLogger implements Log {
|
|||||||
* @see org.apache.commons.logging.Log#debug(java.lang.Object, java.lang.Throwable)
|
* @see org.apache.commons.logging.Log#debug(java.lang.Object, java.lang.Throwable)
|
||||||
*/
|
*/
|
||||||
public void debug(Object o, Throwable t) {
|
public void debug(Object o, Throwable t) {
|
||||||
if (this.logger.isDebugEnabled()) this.logger.debug(o.toString(), t);
|
if (this.logger.isDebugEnabled()) this.logger.debug(String.valueOf(o), t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.apache.commons.logging.Log#debug(java.lang.Object)
|
* @see org.apache.commons.logging.Log#debug(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
public void debug(Object o) {
|
public void debug(Object o) {
|
||||||
if (this.logger.isDebugEnabled()) this.logger.debug(o.toString());
|
if (this.logger.isDebugEnabled()) this.logger.debug(String.valueOf(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.apache.commons.logging.Log#error(java.lang.Object, java.lang.Throwable)
|
* @see org.apache.commons.logging.Log#error(java.lang.Object, java.lang.Throwable)
|
||||||
*/
|
*/
|
||||||
public void error(Object o, Throwable t) {
|
public void error(Object o, Throwable t) {
|
||||||
if (this.logger.isErrorEnabled()) this.logger.error(o.toString(), t);
|
if (this.logger.isErrorEnabled()) this.logger.error(String.valueOf(o), t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.apache.commons.logging.Log#error(java.lang.Object)
|
* @see org.apache.commons.logging.Log#error(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
public void error(Object o) {
|
public void error(Object o) {
|
||||||
if (this.logger.isErrorEnabled()) this.logger.error(o.toString());
|
if (this.logger.isErrorEnabled()) this.logger.error(String.valueOf(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.apache.commons.logging.Log#fatal(java.lang.Object, java.lang.Throwable)
|
* @see org.apache.commons.logging.Log#fatal(java.lang.Object, java.lang.Throwable)
|
||||||
*/
|
*/
|
||||||
public void fatal(Object o, Throwable t) {
|
public void fatal(Object o, Throwable t) {
|
||||||
if (this.logger.isFatalErrorEnabled()) this.logger.fatalError(o.toString(), t);
|
if (this.logger.isFatalErrorEnabled()) this.logger.fatalError(String.valueOf(o), t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.apache.commons.logging.Log#fatal(java.lang.Object)
|
* @see org.apache.commons.logging.Log#fatal(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
public void fatal(Object o) {
|
public void fatal(Object o) {
|
||||||
if (this.logger.isFatalErrorEnabled()) this.logger.fatalError(o.toString());
|
if (this.logger.isFatalErrorEnabled()) this.logger.fatalError(String.valueOf(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.apache.commons.logging.Log#info(java.lang.Object, java.lang.Throwable)
|
* @see org.apache.commons.logging.Log#info(java.lang.Object, java.lang.Throwable)
|
||||||
*/
|
*/
|
||||||
public void info(Object o, Throwable t) {
|
public void info(Object o, Throwable t) {
|
||||||
if (this.logger.isInfoEnabled()) this.logger.info(o.toString(), t);
|
if (this.logger.isInfoEnabled()) this.logger.info(String.valueOf(o), t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.apache.commons.logging.Log#info(java.lang.Object)
|
* @see org.apache.commons.logging.Log#info(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
public void info(Object o) {
|
public void info(Object o) {
|
||||||
if (this.logger.isInfoEnabled()) this.logger.info(o.toString());
|
if (this.logger.isInfoEnabled()) this.logger.info(String.valueOf(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,28 +208,28 @@ public class AvalonLogger implements Log {
|
|||||||
* @see org.apache.commons.logging.Log#trace(java.lang.Object, java.lang.Throwable)
|
* @see org.apache.commons.logging.Log#trace(java.lang.Object, java.lang.Throwable)
|
||||||
*/
|
*/
|
||||||
public void trace(Object o, Throwable t) {
|
public void trace(Object o, Throwable t) {
|
||||||
if (this.logger.isDebugEnabled()) this.logger.debug(o.toString(), t);
|
if (this.logger.isDebugEnabled()) this.logger.debug(String.valueOf(o), t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.apache.commons.logging.Log#trace(java.lang.Object)
|
* @see org.apache.commons.logging.Log#trace(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
public void trace(Object o) {
|
public void trace(Object o) {
|
||||||
if (this.logger.isDebugEnabled()) this.logger.debug(o.toString());
|
if (this.logger.isDebugEnabled()) this.logger.debug(String.valueOf(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.apache.commons.logging.Log#warn(java.lang.Object, java.lang.Throwable)
|
* @see org.apache.commons.logging.Log#warn(java.lang.Object, java.lang.Throwable)
|
||||||
*/
|
*/
|
||||||
public void warn(Object o, Throwable t) {
|
public void warn(Object o, Throwable t) {
|
||||||
if (this.logger.isWarnEnabled()) this.logger.warn(o.toString(), t);
|
if (this.logger.isWarnEnabled()) this.logger.warn(String.valueOf(o), t);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.apache.commons.logging.Log#warn(java.lang.Object)
|
* @see org.apache.commons.logging.Log#warn(java.lang.Object)
|
||||||
*/
|
*/
|
||||||
public void warn(Object o) {
|
public void warn(Object o) {
|
||||||
if (this.logger.isWarnEnabled()) this.logger.warn(o.toString());
|
if (this.logger.isWarnEnabled()) this.logger.warn(String.valueOf(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/test/org/apache/commons/logging/avalon/AvalonLoggerTest.java,v 1.1 2003/05/14 11:14:24 rdonkin Exp $
|
||||||
|
* $Revision: 1.1 $
|
||||||
|
* $Date: 2003/05/14 11:14:24 $
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* The Apache Software License, Version 1.1
|
||||||
|
*
|
||||||
|
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
|
||||||
|
* reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
*
|
||||||
|
* 3. The end-user documentation included with the redistribution, if
|
||||||
|
* any, must include the following acknowlegement:
|
||||||
|
* "This product includes software developed by the
|
||||||
|
* Apache Software Foundation (http://www.apache.org/)."
|
||||||
|
* Alternately, this acknowlegement may appear in the software itself,
|
||||||
|
* if and wherever such third-party acknowlegements normally appear.
|
||||||
|
*
|
||||||
|
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
|
||||||
|
* Foundation" must not be used to endorse or promote products derived
|
||||||
|
* from this software without prior written permission. For written
|
||||||
|
* permission, please contact apache@apache.org.
|
||||||
|
*
|
||||||
|
* 5. Products derived from this software may not be called "Apache"
|
||||||
|
* nor may "Apache" appear in their names without prior written
|
||||||
|
* permission of the Apache Group.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||||
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||||
|
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||||
|
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
* ====================================================================
|
||||||
|
*
|
||||||
|
* This software consists of voluntary contributions made by many
|
||||||
|
* individuals on behalf of the Apache Software Foundation. For more
|
||||||
|
* information on the Apache Software Foundation, please see
|
||||||
|
* <http://www.apache.org/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.apache.commons.logging.avalon;
|
||||||
|
|
||||||
|
import org.apache.avalon.framework.logger.ConsoleLogger;
|
||||||
|
import org.apache.commons.logging.impl.AvalonLogger;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.AbstractLogTest;
|
||||||
|
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
|
||||||
|
* @version $Revision: 1.1 $ $Date: 2003/05/14 11:14:24 $
|
||||||
|
*/
|
||||||
|
public class AvalonLoggerTest extends AbstractLogTest {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String[] testCaseName = { AvalonLoggerTest.class.getName() };
|
||||||
|
junit.textui.TestRunner.main(testCaseName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite() {
|
||||||
|
TestSuite suite = new TestSuite();
|
||||||
|
suite.addTestSuite(AvalonLoggerTest.class);
|
||||||
|
return suite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AvalonLoggerTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Log getLogObject() {
|
||||||
|
Log log = new AvalonLogger(new ConsoleLogger());
|
||||||
|
return log;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user