PR: 7432 <recorder> is a difficult beast with regard to bug 7552 as it holds state in a static Hashtable - at least it won't create multiple loggers for the same files, so it should be relatively save. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272397 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -53,6 +53,13 @@ a buildFinished event.</p> | |||
| this file. [Values = {yes|no}, Default=yes]</td> | |||
| <td align="center" valign="middle">no</td> | |||
| </tr> | |||
| <tr> | |||
| <td valign="top">emacsmode</td> | |||
| <td valign="top">Removes <code>[task]</code> banners like Ant's | |||
| <code>-emacs</code> command line switch if set to | |||
| <em>true</em>.</td> | |||
| <td align="center" valign="middle">no, default is <em>false</em></td> | |||
| </tr> | |||
| <tr> | |||
| <td valign="top">loglevel</td> | |||
| <td valign="top">At what logging level should this recorder instance | |||
| @@ -97,14 +104,6 @@ future. They include things like the following:</p> | |||
| <td valign="top"><b>Description</b></td> | |||
| <td align="center" valign="top"><b>Required</b></td> | |||
| </tr> | |||
| <tr> | |||
| <td valign="top">messageprefix</td> | |||
| <td valign="top">Whether or not to include the message prefixes (things | |||
| like the name of the tasks or targets, etc). This has the same effect as | |||
| the <code>-emacs</code> command line parameter does to the screen output. | |||
| [yes|no]</td> | |||
| <td align="center" valign="middle">no</td> | |||
| </tr> | |||
| <tr> | |||
| <td valign="top">listener</td> | |||
| <td valign="top">A classname of a build listener to use from this point | |||
| @@ -150,9 +149,8 @@ future. They include things like the following:</p> | |||
| <hr><p align="center">Copyright © 2001 Apache Software Foundation. All rights | |||
| Reserved.</p> | |||
| <hr><p align="center">Copyright © 2001-2002 Apache Software | |||
| Foundation. All rights Reserved.</p> | |||
| </body> | |||
| </html> | |||
| @@ -71,7 +71,7 @@ public class DefaultLogger implements BuildLogger { | |||
| * Size of left-hand column for right-justified task name. | |||
| * @see #messageLogged(BuildEvent) | |||
| */ | |||
| private static final int LEFT_COLUMN_SIZE = 12; | |||
| public static final int LEFT_COLUMN_SIZE = 12; | |||
| /** PrintStream to write non-error messages to */ | |||
| protected PrintStream out; | |||
| @@ -75,7 +75,7 @@ import java.util.Hashtable; | |||
| * @see RecorderEntry | |||
| * @author <a href="mailto:jayglanville@home.com">J D Glanville</a> | |||
| * @version 0.5 | |||
| * | |||
| * @since Ant 1.4 | |||
| * @ant.task name="record" category="utility" | |||
| */ | |||
| public class Recorder extends Task { | |||
| @@ -95,6 +95,10 @@ public class Recorder extends Task { | |||
| private Boolean start = null; | |||
| /** The level to log at. A level of -1 means not initialized yet. */ | |||
| private int loglevel = -1; | |||
| /** | |||
| * Strip task banners if true. | |||
| */ | |||
| private boolean emacsMode = false; | |||
| /** The list of recorder entries. */ | |||
| private static Hashtable recorderEntries = new Hashtable(); | |||
| @@ -131,6 +135,10 @@ public class Recorder extends Task { | |||
| this.append = new Boolean(append); | |||
| } | |||
| public void setEmacsMode(boolean emacsMode) { | |||
| this.emacsMode = emacsMode; | |||
| } | |||
| /** | |||
| * Sets the level to which this recorder entry should log to. | |||
| * @see VerbosityLevelChoices | |||
| @@ -163,13 +171,14 @@ public class Recorder extends Task { | |||
| } | |||
| getProject().log( "setting a recorder for name " + filename, | |||
| Project.MSG_DEBUG ); | |||
| Project.MSG_DEBUG ); | |||
| // get the recorder entry | |||
| RecorderEntry recorder = getRecorder( filename, getProject() ); | |||
| // set the values on the recorder | |||
| recorder.setMessageOutputLevel( loglevel ); | |||
| recorder.setRecordState( start ); | |||
| recorder.setEmacsMode( emacsMode ); | |||
| } | |||
| ////////////////////////////////////////////////////////////////////// | |||
| @@ -202,7 +211,8 @@ public class Recorder extends Task { | |||
| * Gets the recorder that's associated with the passed in name. | |||
| * If the recorder doesn't exist, then a new one is created. | |||
| */ | |||
| protected RecorderEntry getRecorder( String name, Project proj ) throws BuildException { | |||
| protected RecorderEntry getRecorder( String name, Project proj ) | |||
| throws BuildException { | |||
| Object o = recorderEntries.get(name); | |||
| RecorderEntry entry; | |||
| if ( o == null ) { | |||
| @@ -1,7 +1,7 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2001 The Apache Software Foundation. All rights | |||
| * Copyright (c) 2001-2002 The Apache Software Foundation. All rights | |||
| * reserved. | |||
| * | |||
| * Redistribution and use in source and binary forms, with or without | |||
| @@ -55,6 +55,7 @@ | |||
| package org.apache.tools.ant.taskdefs; | |||
| import org.apache.tools.ant.BuildLogger; | |||
| import org.apache.tools.ant.DefaultLogger; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.BuildEvent; | |||
| import org.apache.tools.ant.util.StringUtils; | |||
| @@ -67,7 +68,7 @@ import java.io.PrintStream; | |||
| * to the build process. | |||
| * @author <a href="mailto:jayglanville@home.com">J D Glanville</a> | |||
| * @version 0.5 | |||
| * | |||
| * @since Ant 1.4 | |||
| */ | |||
| public class RecorderEntry implements BuildLogger { | |||
| @@ -94,6 +95,10 @@ public class RecorderEntry implements BuildLogger { | |||
| * The start time of the last know target. | |||
| */ | |||
| private long targetStartTime = 0l; | |||
| /** | |||
| * Strip task banners if true. | |||
| */ | |||
| private boolean emacsMode = false; | |||
| ////////////////////////////////////////////////////////////////////// | |||
| // CONSTRUCTORS / INITIALIZERS | |||
| @@ -137,7 +142,8 @@ public class RecorderEntry implements BuildLogger { | |||
| if (error == null) { | |||
| out.println(StringUtils.LINE_SEP + "BUILD SUCCESSFUL"); | |||
| } else { | |||
| out.println(StringUtils.LINE_SEP + "BUILD FAILED" + StringUtils.LINE_SEP); | |||
| out.println(StringUtils.LINE_SEP + "BUILD FAILED" | |||
| + StringUtils.LINE_SEP); | |||
| error.printStackTrace(out); | |||
| } | |||
| out.flush(); | |||
| @@ -146,13 +152,14 @@ public class RecorderEntry implements BuildLogger { | |||
| public void targetStarted(BuildEvent event) { | |||
| log( ">> TARGET STARTED -- " + event.getTarget(), Project.MSG_DEBUG ); | |||
| log( StringUtils.LINE_SEP + event.getTarget().getName() + ":", Project.MSG_INFO ); | |||
| log( StringUtils.LINE_SEP + event.getTarget().getName() + ":", | |||
| Project.MSG_INFO ); | |||
| targetStartTime = System.currentTimeMillis(); | |||
| } | |||
| public void targetFinished(BuildEvent event) { | |||
| log( "<< TARGET FINISHED -- " + event.getTarget(), Project.MSG_DEBUG ); | |||
| String time = formatTime( System.currentTimeMillis() - targetStartTime ); | |||
| String time = formatTime(System.currentTimeMillis() - targetStartTime); | |||
| log( event.getTarget() + ": duration " + time, Project.MSG_VERBOSE ); | |||
| out.flush(); | |||
| } | |||
| @@ -171,12 +178,16 @@ public class RecorderEntry implements BuildLogger { | |||
| StringBuffer buf = new StringBuffer(); | |||
| if ( event.getTask() != null ) { | |||
| String name = "[" + event.getTask().getTaskName() + "]"; | |||
| /** @todo replace 12 with DefaultLogger.LEFT_COLUMN_SIZE */ | |||
| for ( int i = 0; i < (12 - name.length()); i++ ) { | |||
| buf.append( " " ); | |||
| } // for | |||
| buf.append( name ); | |||
| String name = event.getTask().getTaskName(); | |||
| if (!emacsMode) { | |||
| String label = "[" + name + "] "; | |||
| int size = DefaultLogger.LEFT_COLUMN_SIZE - label.length(); | |||
| for (int i = 0; i < size; i++) { | |||
| buf.append(" "); | |||
| } // for | |||
| buf.append(label); | |||
| } // if | |||
| } // if | |||
| buf.append( event.getMessage() ); | |||
| @@ -190,7 +201,7 @@ public class RecorderEntry implements BuildLogger { | |||
| */ | |||
| private void log( String mesg, int level ) { | |||
| if ( record && (level <= loglevel) ) { | |||
| out.println(mesg); | |||
| out.println(mesg); | |||
| } | |||
| } | |||
| @@ -205,7 +216,7 @@ public class RecorderEntry implements BuildLogger { | |||
| } | |||
| public void setEmacsMode(boolean emacsMode) { | |||
| throw new java.lang.RuntimeException("Method setEmacsMode() not yet implemented."); | |||
| this.emacsMode = emacsMode; | |||
| } | |||
| public void setErrorPrintStream(PrintStream err) { | |||