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> | this file. [Values = {yes|no}, Default=yes]</td> | ||||
<td align="center" valign="middle">no</td> | <td align="center" valign="middle">no</td> | ||||
</tr> | </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> | <tr> | ||||
<td valign="top">loglevel</td> | <td valign="top">loglevel</td> | ||||
<td valign="top">At what logging level should this recorder instance | <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 valign="top"><b>Description</b></td> | ||||
<td align="center" valign="top"><b>Required</b></td> | <td align="center" valign="top"><b>Required</b></td> | ||||
</tr> | </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> | <tr> | ||||
<td valign="top">listener</td> | <td valign="top">listener</td> | ||||
<td valign="top">A classname of a build listener to use from this point | <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> | </body> | ||||
</html> | </html> | ||||
@@ -71,7 +71,7 @@ public class DefaultLogger implements BuildLogger { | |||||
* Size of left-hand column for right-justified task name. | * Size of left-hand column for right-justified task name. | ||||
* @see #messageLogged(BuildEvent) | * @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 */ | /** PrintStream to write non-error messages to */ | ||||
protected PrintStream out; | protected PrintStream out; | ||||
@@ -75,7 +75,7 @@ import java.util.Hashtable; | |||||
* @see RecorderEntry | * @see RecorderEntry | ||||
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a> | * @author <a href="mailto:jayglanville@home.com">J D Glanville</a> | ||||
* @version 0.5 | * @version 0.5 | ||||
* | |||||
* @since Ant 1.4 | |||||
* @ant.task name="record" category="utility" | * @ant.task name="record" category="utility" | ||||
*/ | */ | ||||
public class Recorder extends Task { | public class Recorder extends Task { | ||||
@@ -95,6 +95,10 @@ public class Recorder extends Task { | |||||
private Boolean start = null; | private Boolean start = null; | ||||
/** The level to log at. A level of -1 means not initialized yet. */ | /** The level to log at. A level of -1 means not initialized yet. */ | ||||
private int loglevel = -1; | private int loglevel = -1; | ||||
/** | |||||
* Strip task banners if true. | |||||
*/ | |||||
private boolean emacsMode = false; | |||||
/** The list of recorder entries. */ | /** The list of recorder entries. */ | ||||
private static Hashtable recorderEntries = new Hashtable(); | private static Hashtable recorderEntries = new Hashtable(); | ||||
@@ -131,6 +135,10 @@ public class Recorder extends Task { | |||||
this.append = new Boolean(append); | this.append = new Boolean(append); | ||||
} | } | ||||
public void setEmacsMode(boolean emacsMode) { | |||||
this.emacsMode = emacsMode; | |||||
} | |||||
/** | /** | ||||
* Sets the level to which this recorder entry should log to. | * Sets the level to which this recorder entry should log to. | ||||
* @see VerbosityLevelChoices | * @see VerbosityLevelChoices | ||||
@@ -163,13 +171,14 @@ public class Recorder extends Task { | |||||
} | } | ||||
getProject().log( "setting a recorder for name " + filename, | getProject().log( "setting a recorder for name " + filename, | ||||
Project.MSG_DEBUG ); | |||||
Project.MSG_DEBUG ); | |||||
// get the recorder entry | // get the recorder entry | ||||
RecorderEntry recorder = getRecorder( filename, getProject() ); | RecorderEntry recorder = getRecorder( filename, getProject() ); | ||||
// set the values on the recorder | // set the values on the recorder | ||||
recorder.setMessageOutputLevel( loglevel ); | recorder.setMessageOutputLevel( loglevel ); | ||||
recorder.setRecordState( start ); | 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. | * Gets the recorder that's associated with the passed in name. | ||||
* If the recorder doesn't exist, then a new one is created. | * 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); | Object o = recorderEntries.get(name); | ||||
RecorderEntry entry; | RecorderEntry entry; | ||||
if ( o == null ) { | if ( o == null ) { | ||||
@@ -1,7 +1,7 @@ | |||||
/* | /* | ||||
* The Apache Software License, Version 1.1 | * 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. | * reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
@@ -55,6 +55,7 @@ | |||||
package org.apache.tools.ant.taskdefs; | package org.apache.tools.ant.taskdefs; | ||||
import org.apache.tools.ant.BuildLogger; | import org.apache.tools.ant.BuildLogger; | ||||
import org.apache.tools.ant.DefaultLogger; | |||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.BuildEvent; | import org.apache.tools.ant.BuildEvent; | ||||
import org.apache.tools.ant.util.StringUtils; | import org.apache.tools.ant.util.StringUtils; | ||||
@@ -67,7 +68,7 @@ import java.io.PrintStream; | |||||
* to the build process. | * to the build process. | ||||
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a> | * @author <a href="mailto:jayglanville@home.com">J D Glanville</a> | ||||
* @version 0.5 | * @version 0.5 | ||||
* | |||||
* @since Ant 1.4 | |||||
*/ | */ | ||||
public class RecorderEntry implements BuildLogger { | public class RecorderEntry implements BuildLogger { | ||||
@@ -94,6 +95,10 @@ public class RecorderEntry implements BuildLogger { | |||||
* The start time of the last know target. | * The start time of the last know target. | ||||
*/ | */ | ||||
private long targetStartTime = 0l; | private long targetStartTime = 0l; | ||||
/** | |||||
* Strip task banners if true. | |||||
*/ | |||||
private boolean emacsMode = false; | |||||
////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////// | ||||
// CONSTRUCTORS / INITIALIZERS | // CONSTRUCTORS / INITIALIZERS | ||||
@@ -137,7 +142,8 @@ public class RecorderEntry implements BuildLogger { | |||||
if (error == null) { | if (error == null) { | ||||
out.println(StringUtils.LINE_SEP + "BUILD SUCCESSFUL"); | out.println(StringUtils.LINE_SEP + "BUILD SUCCESSFUL"); | ||||
} else { | } else { | ||||
out.println(StringUtils.LINE_SEP + "BUILD FAILED" + StringUtils.LINE_SEP); | |||||
out.println(StringUtils.LINE_SEP + "BUILD FAILED" | |||||
+ StringUtils.LINE_SEP); | |||||
error.printStackTrace(out); | error.printStackTrace(out); | ||||
} | } | ||||
out.flush(); | out.flush(); | ||||
@@ -146,13 +152,14 @@ public class RecorderEntry implements BuildLogger { | |||||
public void targetStarted(BuildEvent event) { | public void targetStarted(BuildEvent event) { | ||||
log( ">> TARGET STARTED -- " + event.getTarget(), Project.MSG_DEBUG ); | 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(); | targetStartTime = System.currentTimeMillis(); | ||||
} | } | ||||
public void targetFinished(BuildEvent event) { | public void targetFinished(BuildEvent event) { | ||||
log( "<< TARGET FINISHED -- " + event.getTarget(), Project.MSG_DEBUG ); | 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 ); | log( event.getTarget() + ": duration " + time, Project.MSG_VERBOSE ); | ||||
out.flush(); | out.flush(); | ||||
} | } | ||||
@@ -171,12 +178,16 @@ public class RecorderEntry implements BuildLogger { | |||||
StringBuffer buf = new StringBuffer(); | StringBuffer buf = new StringBuffer(); | ||||
if ( event.getTask() != null ) { | 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 | } // if | ||||
buf.append( event.getMessage() ); | buf.append( event.getMessage() ); | ||||
@@ -190,7 +201,7 @@ public class RecorderEntry implements BuildLogger { | |||||
*/ | */ | ||||
private void log( String mesg, int level ) { | private void log( String mesg, int level ) { | ||||
if ( record && (level <= loglevel) ) { | if ( record && (level <= loglevel) ) { | ||||
out.println(mesg); | |||||
out.println(mesg); | |||||
} | } | ||||
} | } | ||||
@@ -205,7 +216,7 @@ public class RecorderEntry implements BuildLogger { | |||||
} | } | ||||
public void setEmacsMode(boolean emacsMode) { | public void setEmacsMode(boolean emacsMode) { | ||||
throw new java.lang.RuntimeException("Method setEmacsMode() not yet implemented."); | |||||
this.emacsMode = emacsMode; | |||||
} | } | ||||
public void setErrorPrintStream(PrintStream err) { | public void setErrorPrintStream(PrintStream err) { | ||||