ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject cvs commit: ant WHATSNEW
Date Tue, 16 Aug 2005 15:33:17 GMT
stevel      2005/08/16 08:33:17

  Modified:    docs/manual listeners.html
               src/main/org/apache/tools/ant/listener
                        CommonsLoggingListener.java Log4jListener.java
               src/main/org/apache/tools/ant DefaultLogger.java
               .        WHATSNEW
  Added:       src/main/org/apache/tools/ant/listener
                        TimestampedLogger.java
  Log:
  Because I got fed up of trying to remember when I last ran a build from a particular command
line. Did some constant extraction on the commons/log4j listener while I was in the directory.
  
  Revision  Changes    Path
  1.19      +22 -2     ant/docs/manual/listeners.html
  
  Index: listeners.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/listeners.html,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- listeners.html	2 May 2005 15:30:17 -0000	1.18
  +++ listeners.html	16 Aug 2005 15:33:16 -0000	1.19
  @@ -83,6 +83,12 @@
       <td width="33%">Writes the build information to an XML file.</td>
       <td width="34%">BuildLogger</td>
     </tr>
  +  <tr>
  +    <td width="33%"><code><a href="#TimestampedLogger">org.apache.tools.ant.TimestampedLogger</a></code></td>
  +    <td width="33%">Prints the time that a build finished</td>
  +    <td width="34%">BuildLogger</td>
  +  </tr>
  +
   </table>
   <h3><a name="DefaultLogger">DefaultLogger</a></h3>
   
  @@ -313,19 +319,33 @@
   this can be a relative or absolute file path, or an http URL.
   If you set the property to the empty string, "", no XSLT transform
   is declared at all.
  +</p>
  +
  +<blockquote>
  +
  +<p><code>ant -listener org.apache.tools.ant.XmlLogger</code><br>
  +<code>ant -logger org.apache.tools.ant.XmlLogger -verbose -logfile build_log.xml</code></p>
   
  +</blockquote>
   
   
  +<h3><a name="TimestampedLogger">TimestampedLogger</a></h3>
   
  +<p>
  +  Acts like the default logger, except that the final success/failure message also includes
  +  the time that the build completed. For example:
   </p>
  +<pre>
  +  BUILD SUCCESSFUL - at 16/08/05 16:24
  +</pre>
   
   <blockquote>
   
  -<p><code>ant -listener org.apache.tools.ant.XmlLogger</code><br>
  -<code>ant -logger org.apache.tools.ant.XmlLogger -verbose -logfile build_log.xml</code></p>
  +<code>ant  -logger org.apache.tools.ant.listener.TimestampedLogger</code>
   
   </blockquote>
   
  +
   <h2><a name="dev">Writing your own</a></h2>
   
   <p>See the <a href="develop.html#buildevents">Build Events</a> section
for
  
  
  
  1.14      +15 -6     ant/src/main/org/apache/tools/ant/listener/CommonsLoggingListener.java
  
  Index: CommonsLoggingListener.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/listener/CommonsLoggingListener.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- CommonsLoggingListener.java	11 Mar 2005 11:15:27 -0000	1.13
  +++ CommonsLoggingListener.java	16 Aug 2005 15:33:16 -0000	1.14
  @@ -58,6 +58,15 @@
       private LogFactory logFactory;
   
       /**
  +     * name of the category under which target events are logged
  +     */
  +    public static final String TARGET_LOG = "org.apache.tools.ant.Target";
  +    /**
  +     * name of the category under which project events are logged
  +     */
  +    public static final String PROJECT_LOG = "org.apache.tools.ant.Project";
  +
  +    /**
        * Construct the listener and make sure that a LogFactory
        * can be obtained.
        */
  @@ -95,7 +104,7 @@
        * @see BuildListener#buildStarted
        */
       public void buildStarted(BuildEvent event) {
  -        String categoryString = "org.apache.tools.ant.Project";
  +        String categoryString = PROJECT_LOG;
           Log log = getLog(categoryString, null);
   
           if (initialized) {
  @@ -108,7 +117,7 @@
        */
       public void buildFinished(BuildEvent event) {
           if (initialized) {
  -            String categoryString = "org.apache.tools.ant.Project";
  +            String categoryString = PROJECT_LOG;
               Log log = getLog(categoryString, event.getProject().getName());
   
               if (event.getException() == null) {
  @@ -125,7 +134,7 @@
        */
       public void targetStarted(BuildEvent event) {
           if (initialized) {
  -            Log log = getLog("org.apache.tools.ant.Target",
  +            Log log = getLog(TARGET_LOG,
                       event.getTarget().getName());
               // Since task log category includes target, we don't really
               // need this message
  @@ -140,7 +149,7 @@
       public void targetFinished(BuildEvent event) {
           if (initialized) {
               String targetName = event.getTarget().getName();
  -            Log log = getLog("org.apache.tools.ant.Target",
  +            Log log = getLog(TARGET_LOG,
                       event.getTarget().getName());
               if (event.getException() == null) {
                   realLog(log, "Target end: " + targetName, Project.MSG_DEBUG, null);
  @@ -214,10 +223,10 @@
                   categoryObject = event.getTarget();
                   if (categoryObject == null) {
                       categoryObject = event.getProject();
  -                    categoryString = "org.apache.tools.ant.Project";
  +                    categoryString = PROJECT_LOG;
                       categoryDetail = event.getProject().getName();
                   } else {
  -                    categoryString = "org.apache.tools.ant.Target";
  +                    categoryString = TARGET_LOG;
                       categoryDetail = event.getTarget().getName();
                   }
               } else {
  
  
  
  1.18      +6 -1      ant/src/main/org/apache/tools/ant/listener/Log4jListener.java
  
  Index: Log4jListener.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/listener/Log4jListener.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Log4jListener.java	29 Oct 2004 08:54:33 -0000	1.17
  +++ Log4jListener.java	16 Aug 2005 15:33:16 -0000	1.18
  @@ -36,11 +36,16 @@
       private boolean initialized = false;
   
       /**
  +     * log category we log into
  +     */
  +    public static final String LOG_ANT = "org.apache.tools.ant";
  +
  +    /**
        * Construct the listener and make sure there is a valid appender.
        */
       public Log4jListener() {
           initialized = false;
  -        Logger log = Logger.getLogger("org.apache.tools.ant");
  +        Logger log = Logger.getLogger(LOG_ANT);
           Logger rootLog = Logger.getRootLogger();
           if (!(rootLog.getAllAppenders() instanceof NullEnumeration)) {
               initialized = true;
  
  
  
  1.1                  ant/src/main/org/apache/tools/ant/listener/TimestampedLogger.java
  
  Index: TimestampedLogger.java
  ===================================================================
  package org.apache.tools.ant.listener;
  
  import org.apache.tools.ant.DefaultLogger;
  
  import java.util.Date;
  import java.text.DateFormat;
  
  /**
   * Like a normal logger, except with timed outputs
   */
  public class TimestampedLogger extends DefaultLogger {
  
      /**
       * what appears between the old message and the new
       */
      private static final String SPACER = " - at ";
  
  
      /**
       * This is an override point: the message that indicates whether a build failed.
       * Subclasses can change/enhance the message.
       *
       * @return The classic "BUILD FAILED"
       */
      protected String getBuildFailedMessage() {
          return super.getBuildFailedMessage() + SPACER + getTimestamp();
      }
  
      /**
       * This is an override point: the message that indicates that a build succeeded.
       * Subclasses can change/enhance the message.
       *
       * @return The classic "BUILD SUCCESSFUL"
       */
      protected String getBuildSuccessfulMessage() {
          return super.getBuildSuccessfulMessage()+SPACER +getTimestamp();
      }
  
      protected String getTimestamp() {
          Date date = new Date(System.currentTimeMillis());
          DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
          String finishTime = formatter.format(date);
          return finishTime;
      }
  }
  
  
  
  1.49      +22 -8     ant/src/main/org/apache/tools/ant/DefaultLogger.java
  
  Index: DefaultLogger.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/DefaultLogger.java,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- DefaultLogger.java	9 Mar 2004 16:47:59 -0000	1.48
  +++ DefaultLogger.java	16 Aug 2005 15:33:16 -0000	1.49
  @@ -21,6 +21,7 @@
   import java.io.IOException;
   import java.io.PrintStream;
   import java.io.StringReader;
  +
   import org.apache.tools.ant.util.DateUtils;
   import org.apache.tools.ant.util.StringUtils;
   
  @@ -131,24 +132,19 @@
       public void buildFinished(BuildEvent event) {
           Throwable error = event.getException();
           StringBuffer message = new StringBuffer();
  -
           if (error == null) {
               message.append(StringUtils.LINE_SEP);
  -            message.append("BUILD SUCCESSFUL");
  +            message.append(getBuildSuccessfulMessage());
           } else {
               message.append(StringUtils.LINE_SEP);
  -            message.append("BUILD FAILED");
  +            message.append(getBuildFailedMessage());
               message.append(StringUtils.LINE_SEP);
   
               if (Project.MSG_VERBOSE <= msgOutputLevel
                   || !(error instanceof BuildException)) {
                   message.append(StringUtils.getStackTrace(error));
               } else {
  -                if (error instanceof BuildException) {
  -                    message.append(error.toString()).append(lSep);
  -                } else {
  -                    message.append(error.getMessage()).append(lSep);
  -                }
  +                message.append(error.toString()).append(lSep);
               }
           }
           message.append(StringUtils.LINE_SEP);
  @@ -165,6 +161,24 @@
       }
   
       /**
  +     * This is an override point: the message that indicates whether a build failed.
  +     * Subclasses can change/enhance the message.
  +     * @return The classic "BUILD FAILED"
  +     */
  +    protected String getBuildFailedMessage() {
  +        return "BUILD FAILED";
  +    }
  +
  +    /**
  +     * This is an override point: the message that indicates that a build succeeded.
  +     * Subclasses can change/enhance the message.
  +     * @return The classic "BUILD SUCCESSFUL"
  +     */
  +    protected String getBuildSuccessfulMessage() {
  +        return "BUILD SUCCESSFUL";
  +    }
  +
  +    /**
        * Logs a message to say that the target has started if this
        * logger allows information-level messages.
        *
  
  
  
  1.848     +3 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.847
  retrieving revision 1.848
  diff -u -r1.847 -r1.848
  --- WHATSNEW	22 Jul 2005 15:54:16 -0000	1.847
  +++ WHATSNEW	16 Aug 2005 15:33:16 -0000	1.848
  @@ -256,6 +256,9 @@
   * <javadoc> now supports -breakiterator for custom doclets if Ant is
     running on JSE 5.0 or higher.  Bugzilla Report: 34580.
   
  +* New logger, TimestampedLogger, that prints the wall time that a build finished/failed
  +  Use with  -logger org.apache.tools.ant.listener.TimestampedLogger
  +
   Changes from Ant 1.6.4 to Ant 1.6.5
   ===================================
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message