From 771de95aa4ce93462d8b7ea33a95b0875834f239 Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Tue, 12 Mar 2002 08:41:37 +0000 Subject: [PATCH] Move the generic log() methods back into LogLevel. The reason for this is to remove yet another Avalon dependency from the api package. I also think that usage of the log() methods except in really rare circumstances leads to poor programming idioms. Hopefully there will only be a handful of tasks that use it (like ) and thus it is not universal enough to be in the TaskContext. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271821 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/java/org/apache/antlib/core/Log.java | 2 +- .../org/apache/myrmidon/api/LogLevel.java | 58 +++++++++++++++++ .../org/apache/myrmidon/api/TaskContext.java | 17 ----- .../workspace/DefaultTaskContext.java | 64 +------------------ 4 files changed, 60 insertions(+), 81 deletions(-) diff --git a/proposal/myrmidon/src/java/org/apache/antlib/core/Log.java b/proposal/myrmidon/src/java/org/apache/antlib/core/Log.java index 8b55511ad..2ab41ea08 100644 --- a/proposal/myrmidon/src/java/org/apache/antlib/core/Log.java +++ b/proposal/myrmidon/src/java/org/apache/antlib/core/Log.java @@ -65,7 +65,7 @@ public class Log public void execute() throws TaskException { - getContext().log( m_level, m_message ); + LogLevel.log( getContext(), m_level, m_message ); } /** diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/api/LogLevel.java b/proposal/myrmidon/src/java/org/apache/myrmidon/api/LogLevel.java index eb45c842f..7f19ec803 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/api/LogLevel.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/api/LogLevel.java @@ -53,6 +53,64 @@ public final class LogLevel return (String[])keys.toArray( new String[ keys.size() ] ); } + /** + * Log a message. + * + * @param level the level to write the log message at. + * @param message the message to write. + */ + public static void log( final TaskContext context, + final LogLevel level, + final String message ) + { + if( LogLevel.ERROR == level ) + { + context.error( message ); + } + else if( LogLevel.WARN == level ) + { + context.warn( message ); + } + else if( LogLevel.INFO == level ) + { + context.info( message ); + } + else + { + context.debug( message ); + } + } + + /** + * Log a message. + * + * @param level the level to write the log message at. + * @param message the message to write. + * @param throwable the throwable. + */ + public static void log( final TaskContext context, + final LogLevel level, + final String message, + final Throwable throwable ) + { + if( LogLevel.ERROR == level ) + { + context.error( message, throwable ); + } + else if( LogLevel.WARN == level ) + { + context.warn( message, throwable ); + } + else if( LogLevel.INFO == level ) + { + context.info( message, throwable ); + } + else + { + context.debug( message, throwable ); + } + } + /** * Private constructor so no instance except here can be defined. * diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/api/TaskContext.java b/proposal/myrmidon/src/java/org/apache/myrmidon/api/TaskContext.java index 77230a276..4bb1296b7 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/api/TaskContext.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/api/TaskContext.java @@ -100,23 +100,6 @@ public interface TaskContext void setProperty( String name, Object value ) throws TaskException; - /** - * Log a message. - * - * @param level the level to write the log message at. - * @param message the message to write. - */ - void log( LogLevel level, String message ); - - /** - * Log a message. - * - * @param level the level to write the log message at. - * @param message the message to write. - * @param throwable the throwable - */ - void log( LogLevel level, String message, Throwable throwable ); - /** * Log a debug message. * diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java b/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java index 3a2b0d229..f4467d8a1 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/components/workspace/DefaultTaskContext.java @@ -18,7 +18,6 @@ import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.logger.Logger; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; -import org.apache.myrmidon.api.LogLevel; import org.apache.myrmidon.api.TaskContext; import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.interfaces.model.DefaultNameValidator; @@ -38,6 +37,7 @@ public class DefaultTaskContext // Property name validator allows digits, but no internal whitespace. private static DefaultNameValidator m_propertyNameValidator = new DefaultNameValidator(); + static { m_propertyNameValidator.setAllowInternalWhitespace( false ); @@ -146,7 +146,6 @@ public class DefaultTaskContext public Object resolveValue( final String value ) throws TaskException { - try { // Lazy lookup of the PropertyResolver @@ -213,67 +212,6 @@ public class DefaultTaskContext m_contextData.put( name, value ); } - /** - * Log a message. - * - * @param level the level to write the log message at. - * @param message the message to write. - */ - public void log( LogLevel level, String message ) - { - if( LogLevel.FATAL_ERROR == level ) - { - m_logger.fatalError( message ); - } - else if( LogLevel.ERROR == level ) - { - m_logger.error( message ); - } - else if( LogLevel.WARN == level ) - { - m_logger.warn( message ); - } - else if( LogLevel.INFO == level ) - { - m_logger.info( message ); - } - else - { - m_logger.debug( message ); - } - } - - /** - * Log a message. - * - * @param level the level to write the log message at. - * @param message the message to write. - * @param throwable the throwable. - */ - public void log( LogLevel level, String message, Throwable throwable ) - { - if( LogLevel.FATAL_ERROR == level ) - { - m_logger.fatalError( message, throwable ); - } - else if( LogLevel.ERROR == level ) - { - m_logger.error( message, throwable ); - } - else if( LogLevel.WARN == level ) - { - m_logger.warn( message, throwable ); - } - else if( LogLevel.INFO == level ) - { - m_logger.info( message, throwable ); - } - else - { - m_logger.debug( message, throwable ); - } - } - /** * Log a debug message. *