From 497fb70fe8e13236643e154c47145cb0f84e2078 Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Sun, 16 Dec 2001 05:26:26 +0000 Subject: [PATCH] Update Listeners so that the default listener is like the NoBannerLogger from Ant1.x while the classic is like ants current default. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270203 13f79535-47bb-0310-9956-ffa450edef68 --- .../listeners/ClassicProjectListener.java | 92 +++++++++++++++++++ .../listeners/DefaultProjectListener.java | 9 +- .../src/manifest/builtin-ant-descriptor.xml | 1 + 3 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 proposal/myrmidon/src/java/org/apache/myrmidon/listeners/ClassicProjectListener.java diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/listeners/ClassicProjectListener.java b/proposal/myrmidon/src/java/org/apache/myrmidon/listeners/ClassicProjectListener.java new file mode 100644 index 000000000..3d3e5436f --- /dev/null +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/listeners/ClassicProjectListener.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) The Apache Software Foundation. All rights reserved. + * + * This software is published under the terms of the Apache Software License + * version 1.1, a copy of which has been included with this distribution in + * the LICENSE file. + */ +package org.apache.myrmidon.listeners; + +import org.apache.avalon.framework.ExceptionUtil; + +/** + * Default listener that emulates the old ant listener notifications. + * + * @author Peter Donald + */ +public class ClassicProjectListener + extends AbstractProjectListener +{ + private String m_prefix; + + /** + * Notify listener of targetStarted event. + * + * @param targetName the name of target + */ + public void targetStarted( final String targetName ) + { + output( targetName + ":\n" ); + } + + /** + * Notify listener of taskStarted event. + * + * @param taskName the name of task + */ + public void taskStarted( final String taskName ) + { + setPrefix( taskName ); + } + + /** + * Notify listener of taskFinished event. + */ + public void taskFinished() + { + setPrefix( null ); + } + + /** + * Notify listener of log message event. + * + * @param message the message + */ + public void log( String message ) + { + output( message ); + } + + /** + * Notify listener of log message event. + * + * @param message the message + * @param throwable the throwable + */ + public void log( String message, Throwable throwable ) + { + output( message + "\n" + ExceptionUtil.printStackTrace( throwable, 5, true ) ); + } + + /** + * Utility class to output data. + * Overide in sub-classes to direct to a different destination. + * + * @param data the data + */ + protected void output( final String data ) + { + if( null != getPrefix() ) System.out.println( "\t[" + getPrefix() + "] " + data ); + else System.out.println( data ); + } + + protected final String getPrefix() + { + return m_prefix; + } + + protected final void setPrefix( final String prefix ) + { + m_prefix = prefix; + } +} diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/listeners/DefaultProjectListener.java b/proposal/myrmidon/src/java/org/apache/myrmidon/listeners/DefaultProjectListener.java index d498982fd..bc91dec87 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/listeners/DefaultProjectListener.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/listeners/DefaultProjectListener.java @@ -18,6 +18,7 @@ public class DefaultProjectListener extends AbstractProjectListener { private String m_prefix; + private String m_targetName; /** * Notify listener of targetStarted event. @@ -26,7 +27,7 @@ public class DefaultProjectListener */ public void targetStarted( final String targetName ) { - output( targetName + ":\n" ); + m_targetName = targetName; } /** @@ -76,6 +77,12 @@ public class DefaultProjectListener */ protected void output( final String data ) { + if( null != m_targetName ) + { + output( m_targetName + ":\n" ); + m_targetName = null; + } + if( null != getPrefix() ) System.out.println( "\t[" + getPrefix() + "] " + data ); else System.out.println( data ); } diff --git a/proposal/myrmidon/src/manifest/builtin-ant-descriptor.xml b/proposal/myrmidon/src/manifest/builtin-ant-descriptor.xml index 8674d021e..b4a893f33 100644 --- a/proposal/myrmidon/src/manifest/builtin-ant-descriptor.xml +++ b/proposal/myrmidon/src/manifest/builtin-ant-descriptor.xml @@ -3,6 +3,7 @@ +