incubator-depot-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: rev 9947 - in incubator/depot/trunk: common/src/java/org/apache/depot/common/log common/src/test/org/apache/depot/common/util/dom update/src/test/org/apache/depot/update/ant/task version/src/test/java/org/apache/depot/version/util version/src/test/java/org/apache/depot/version/util/dom
Date Fri, 09 Apr 2004 18:37:08 GMT
Author: ajack
Date: Fri Apr  9 11:37:06 2004
New Revision: 9947

Added:
   incubator/depot/trunk/version/src/test/java/org/apache/depot/version/util/
   incubator/depot/trunk/version/src/test/java/org/apache/depot/version/util/dom/
      - copied from rev 9940, incubator/depot/trunk/common/src/test/org/apache/depot/common/util/dom/
Removed:
   incubator/depot/trunk/common/src/test/org/apache/depot/common/util/dom/
Modified:
   incubator/depot/trunk/common/src/java/org/apache/depot/common/log/Logger.java
   incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/task/AntTasksTests.java
Log:
Move so we can do some real testing, on real objects,
without circ dep.


Modified: incubator/depot/trunk/common/src/java/org/apache/depot/common/log/Logger.java
==============================================================================
--- incubator/depot/trunk/common/src/java/org/apache/depot/common/log/Logger.java	(original)
+++ incubator/depot/trunk/common/src/java/org/apache/depot/common/log/Logger.java	Fri Apr
 9 11:37:06 2004
@@ -13,107 +13,99 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.depot.common.log;
-
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Stack;
-
 import org.apache.depot.common.util.debug.DebugUtils;
-
 /**
  * @author anou_mana
  */
-public class Logger {
-
+public class Logger
+{
 	// Listener Tables...
 	private List m_debugListeners = null;
 	private List m_infoListeners = null;
 	private List m_verboseListeners = null;
 	private List m_warnListeners = null;
 	private List m_errorListeners = null;
-
 	//	Chaining...
 	private Logger m_next = null;
-
-	//	Quick check 
+	//	Quick check
 	//:TODO: Make it switchable later
 	public static boolean g_loggingOn = true;
-	
 	//	The root singleton instance
 	private static Logger l_logger = null;
-
-
-	class LoggingContext {
+	class LoggingContext
+	{
 		//
 		// The context
 		//
 		Logger m_currentLogger = null;
 		Stack m_stack = null;
 
-		LoggingContext(Logger currentLogger) {
+		LoggingContext(Logger currentLogger)
+		{
 			m_stack = new Stack();
 			push(currentLogger);
 		}
 
-		public void push(Logger currentLogger) {
+		public void push(Logger currentLogger)
+		{
 			m_stack.push(currentLogger);
 			m_currentLogger = (Logger) m_stack.peek();
 		}
 
-		public void pop(Logger currentLogger) {
+		public void pop(Logger currentLogger)
+		{
 			Logger currentTop = (Logger) m_stack.pop();
 			// Set current
 			m_currentLogger = (Logger) m_stack.peek();
 			if (currentTop != currentLogger)
-				m_currentLogger.warn(
-					"Popped a bad logging context ["
-						+ currentLogger
-						+ "] != ["
-						+ currentTop
-						+ "]");
-
+				m_currentLogger.warn("Popped a bad logging context ["
+						+ currentLogger + "] != [" + currentTop + "]");
 		}
 
-		public Logger getCurrentLogger() {
+		public Logger getCurrentLogger()
+		{
 			return m_currentLogger;
 		}
 	}
-
 	//
 	// One per thread...
 	//
 	private static ThreadLocal l_context = null;
-
 	//:TODO: Store a Stack/Current Logger object in a ThreadLocal
 	// variable, so can have high level code push a "context" and
 	// lower level code will respect it (transparently)
 	// Push a logger which chains (next) the current logger, to
 	// get nested context...
-
-	static {
+	static
+	{
 		l_logger = new Logger();
-
 		l_context = new ThreadLocal() {
-			protected synchronized Object initialValue() {
+			protected synchronized Object initialValue()
+			{
 				return l_logger.new LoggingContext(l_logger);
 			}
 		};
 	}
 
-	public Logger(Logger next) {
+	public Logger(Logger next)
+	{
 		initClass();
 		m_next = next;
 	}
 
-	public Logger() {
+	public Logger()
+	{
 		initClass();
 		m_next = null;
 	}
 
-	private void initClass() {
+	private void initClass()
+	{
 		m_debugListeners = new ArrayList();
 		m_infoListeners = new ArrayList();
 		m_verboseListeners = new ArrayList();
@@ -121,39 +113,47 @@
 		m_errorListeners = new ArrayList();
 	}
 
-	public static Logger getLogger() {
+	public static Logger getLogger()
+	{
 		return ((LoggingContext) l_context.get()).getCurrentLogger();
 	}
 
-	public static Logger pushContext(ILogger listener) {
+	public static Logger pushContext(ILogger listener)
+	{
 		return pushContext(LogConstants.DEBUG, listener);
 	}
 
-	public static Logger pushContext(int level, ILogger listener) {
+	public static Logger pushContext(int level, ILogger listener)
+	{
 		Logger newLogger = pushContext();
 		// :TODO: Fix level, ask listener what they want...
 		newLogger.addListener(level, listener);
 		return newLogger;
 	}
 
-	public static Logger pushContext() {
+	public static Logger pushContext()
+	{
 		LoggingContext context = ((LoggingContext) l_context.get());
 		Logger newLogger = new Logger(context.getCurrentLogger());
 		context.push(newLogger);
 		return newLogger;
 	}
 
-	public static Logger pushContext(Logger newContext) {
+	public static Logger pushContext(Logger newContext)
+	{
 		((LoggingContext) l_context.get()).push(newContext);
 		return newContext;
 	}
 
-	public static void popContext(Logger expectedLogger) {
+	public static void popContext(Logger expectedLogger)
+	{
 		((LoggingContext) l_context.get()).pop(expectedLogger);
 	}
 
-	public void addListener(int listenerType, ILogger listener) {
-		switch (listenerType) {
+	public void addListener(int listenerType, ILogger listener)
+	{
+		switch (listenerType)
+		{
 			default :
 			case LogConstants.DEBUG :
 				{
@@ -183,21 +183,21 @@
 		}
 	}
 
-	public void removeListener(int listenerType, ILogger listener) {
-		switch (listenerType) {
+	public void removeListener(int listenerType, ILogger listener)
+	{
+		switch (listenerType)
+		{
 			default :
 			case LogConstants.DEBUG :
 				{
 					m_debugListeners.remove(listener);
 					// Note: Falls through to VERBOSE...
 				}
-
 			case LogConstants.VERBOSE :
 				{
 					m_infoListeners.remove(listener);
 					// Note: Falls through to INFO...
 				}
-
 			case LogConstants.INFO :
 				{
 					m_infoListeners.remove(listener);
@@ -207,7 +207,6 @@
 				{
 					m_warnListeners.remove(listener);
 					// Note: Falls through to ERROR...
-
 				}
 			case LogConstants.ERROR :
 				{
@@ -218,95 +217,117 @@
 	}
 
 	// DEBUG
-	public boolean isDebug() {
+	public boolean isDebug()
+	{
 		return !m_debugListeners.isEmpty();
 	}
 
-	public void debug(Object message) {
+	public void debug(Object message)
+	{
 		notify(m_debugListeners, LogConstants.DEBUG, message, null);
 		if (null != m_next)
 			m_next.debug(message);
 	}
 
-	public void debug(Object message, Throwable thrower) {
+	public void debug(Object message, Throwable thrower)
+	{
 		notify(m_debugListeners, LogConstants.DEBUG, message, thrower);
 		if (null != m_next)
 			m_next.debug(message, thrower);
 	}
 
 	// VERBOSE
-	public boolean isVerbose() {
+	public boolean isVerbose()
+	{
 		return !m_verboseListeners.isEmpty();
 	}
 
-	public void verbose(Object message) {
+	public void verbose(Object message)
+	{
 		notify(m_verboseListeners, LogConstants.VERBOSE, message, null);
 		if (null != m_next)
 			m_next.verbose(message);
 	}
-	public void verbose(Object message, Throwable thrower) {
+
+	public void verbose(Object message, Throwable thrower)
+	{
 		notify(m_verboseListeners, LogConstants.VERBOSE, message, thrower);
 		if (null != m_next)
 			m_next.verbose(message, thrower);
 	}
 
 	// INFO
-	public void info(Object message) {
+	public void info(Object message)
+	{
 		notify(m_infoListeners, LogConstants.INFO, message, null);
 		if (null != m_next)
 			m_next.info(message);
 	}
-	public void info(Object message, Throwable thrower) {
+
+	public void info(Object message, Throwable thrower)
+	{
 		notify(m_infoListeners, LogConstants.INFO, message, thrower);
 		if (null != m_next)
 			m_next.info(message, thrower);
 	}
 
 	// WARN
-	public void warn(Object message) {
+	public void warn(Object message)
+	{
 		notify(m_warnListeners, LogConstants.WARN, message, null);
 		if (null != m_next)
 			m_next.warn(message);
 	}
-	public void warn(Object message, Throwable thrower) {
+
+	public void warn(Object message, Throwable thrower)
+	{
 		notify(m_warnListeners, LogConstants.WARN, message, thrower);
 		if (null != m_next)
 			m_next.warn(message, thrower);
 	}
 
 	// ERROR
-	public void error(Object message) {
+	public void error(Object message)
+	{
 		notify(m_errorListeners, LogConstants.ERROR, message, null);
 		if (null != m_next)
 			m_next.error(message);
 	}
-	public void error(Object message, Throwable thrower) {
+
+	public void error(Object message, Throwable thrower)
+	{
 		notify(m_errorListeners, LogConstants.ERROR, message, thrower);
 		if (null != m_next)
 			m_next.error(message, thrower);
 	}
 
-	private void notify(
-		List listeners,
-		int severity,
-		Object message,
-		Throwable thrower) {
-
-		for (Iterator i = listeners.iterator(); i.hasNext();) {
-			try {
+	private void notify(List listeners, int severity, Object message,
+			Throwable thrower)
+	{
+		for (Iterator i = listeners.iterator(); i.hasNext();)
+		{
+			try
+			{
 				((ILogger) i.next()).log(severity, message, thrower);
-			}
-			catch (Throwable t) {
+			} catch (Throwable t)
+			{
 				// Their problems are not ours...
 			}
 		}
 	}
 
-	public static void testInit() {
+	public static void testInit()
+	{
 		DebugUtils.enableCommonsLogging();
-
-		getLogger().addListener(
-			LogConstants.DEBUG,
-			new StandardLogListener());
+		
+		// If we don't have a decent listener, yet
+		// (and above doesn't add one, but this might not be
+		// the first call to thie method) then add one.
+		if (!getLogger().isDebug())
+		{
+			getLogger().addListener(LogConstants.DEBUG,
+					new StandardLogListener());
+			getLogger().debug("Test logging enabled.");
+		}
 	}
 }

Modified: incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/task/AntTasksTests.java
==============================================================================
--- incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/task/AntTasksTests.java
(original)
+++ incubator/depot/trunk/update/src/test/org/apache/depot/update/ant/task/AntTasksTests.java
Fri Apr  9 11:37:06 2004
@@ -38,7 +38,7 @@
 	}
 
 	public void setUp() {
-		configureProject("src/test/org/apache/depot/update/ant/task/anttasks.xml");
+		configureProject("update/src/test/org/apache/depot/update/ant/task/anttasks.xml");
 	}
 
 	public void test1() {

Mime
View raw message