Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 250   Methods: 16
NCLOC: 110   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
RecorderEntry.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 package org.apache.tools.ant.taskdefs;
 55   
 
 56   
 import java.io.PrintStream;
 57   
 import org.apache.tools.ant.BuildEvent;
 58   
 import org.apache.tools.ant.BuildLogger;
 59   
 import org.apache.tools.ant.DefaultLogger;
 60   
 import org.apache.tools.ant.Project;
 61   
 import org.apache.tools.ant.util.StringUtils;
 62   
 
 63   
 /**
 64   
  * This is a class that represents a recorder. This is the listener to the
 65   
  * build process.
 66   
  *
 67   
  * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
 68   
  * @version 0.5
 69   
  * @since Ant 1.4
 70   
  */
 71   
 public class RecorderEntry implements BuildLogger {
 72   
 
 73   
     //////////////////////////////////////////////////////////////////////
 74   
     // ATTRIBUTES
 75   
 
 76   
     /** The name of the file associated with this recorder entry.  */
 77   
     private String filename = null;
 78   
     /** The state of the recorder (recorder on or off).  */
 79   
     private boolean record = true;
 80   
     /** The current verbosity level to record at.  */
 81   
     private int loglevel = Project.MSG_INFO;
 82   
     /** The output PrintStream to record to.  */
 83   
     private PrintStream out = null;
 84   
     /** The start time of the last know target.  */
 85   
     private long targetStartTime = 0l;
 86   
     /** Strip task banners if true.  */
 87   
     private boolean emacsMode = false;
 88   
 
 89   
     //////////////////////////////////////////////////////////////////////
 90   
     // CONSTRUCTORS / INITIALIZERS
 91   
 
 92   
     /**
 93   
      * @param name The name of this recorder (used as the filename).
 94   
      */
 95  0
     protected RecorderEntry(String name) {
 96  0
         filename = name;
 97   
     }
 98   
 
 99   
     //////////////////////////////////////////////////////////////////////
 100   
     // ACCESSOR METHODS
 101   
 
 102   
     /**
 103   
      * @return the name of the file the output is sent to.
 104   
      */
 105  0
     public String getFilename() {
 106  0
         return filename;
 107   
     }
 108   
 
 109   
 
 110   
     /**
 111   
      * Turns off or on this recorder.
 112   
      *
 113   
      * @param state true for on, false for off, null for no change.
 114   
      */
 115  0
     public void setRecordState(Boolean state) {
 116  0
         if (state != null) {
 117  0
             record = state.booleanValue();
 118   
         }
 119   
     }
 120   
 
 121   
 
 122  0
     public void buildStarted(BuildEvent event) {
 123  0
         log("> BUILD STARTED", Project.MSG_DEBUG);
 124   
     }
 125   
 
 126   
 
 127  0
     public void buildFinished(BuildEvent event) {
 128  0
         log("< BUILD FINISHED", Project.MSG_DEBUG);
 129   
 
 130  0
         Throwable error = event.getException();
 131   
 
 132  0
         if (error == null) {
 133  0
             out.println(StringUtils.LINE_SEP + "BUILD SUCCESSFUL");
 134   
         } else {
 135  0
             out.println(StringUtils.LINE_SEP + "BUILD FAILED"
 136   
                  + StringUtils.LINE_SEP);
 137  0
             error.printStackTrace(out);
 138   
         }
 139  0
         out.flush();
 140  0
         out.close();
 141   
     }
 142   
 
 143   
 
 144  0
     public void targetStarted(BuildEvent event) {
 145  0
         log(">> TARGET STARTED -- " + event.getTarget(), Project.MSG_DEBUG);
 146  0
         log(StringUtils.LINE_SEP + event.getTarget().getName() + ":",
 147   
             Project.MSG_INFO);
 148  0
         targetStartTime = System.currentTimeMillis();
 149   
     }
 150   
 
 151   
 
 152  0
     public void targetFinished(BuildEvent event) {
 153  0
         log("<< TARGET FINISHED -- " + event.getTarget(), Project.MSG_DEBUG);
 154   
 
 155  0
         String time = formatTime(System.currentTimeMillis() - targetStartTime);
 156   
 
 157  0
         log(event.getTarget() + ":  duration " + time, Project.MSG_VERBOSE);
 158  0
         out.flush();
 159   
     }
 160   
 
 161   
 
 162  0
     public void taskStarted(BuildEvent event) {
 163  0
         log(">>> TASK STARTED -- " + event.getTask(), Project.MSG_DEBUG);
 164   
     }
 165   
 
 166   
 
 167  0
     public void taskFinished(BuildEvent event) {
 168  0
         log("<<< TASK FINISHED -- " + event.getTask(), Project.MSG_DEBUG);
 169  0
         out.flush();
 170   
     }
 171   
 
 172   
 
 173  0
     public void messageLogged(BuildEvent event) {
 174  0
         log("--- MESSAGE LOGGED", Project.MSG_DEBUG);
 175   
 
 176  0
         StringBuffer buf = new StringBuffer();
 177   
 
 178  0
         if (event.getTask() != null) {
 179  0
             String name = event.getTask().getTaskName();
 180   
 
 181  0
             if (!emacsMode) {
 182  0
                 String label = "[" + name + "] ";
 183  0
                 int size = DefaultLogger.LEFT_COLUMN_SIZE - label.length();
 184   
 
 185  0
                 for (int i = 0; i < size; i++) {
 186  0
                     buf.append(" ");
 187   
                 }// for
 188  0
                 buf.append(label);
 189   
             }// if
 190   
         }// if
 191  0
         buf.append(event.getMessage());
 192   
 
 193  0
         log(buf.toString(), event.getPriority());
 194   
     }
 195   
 
 196   
 
 197   
     /**
 198   
      * The thing that actually sends the information to the output.
 199   
      *
 200   
      * @param mesg The message to log.
 201   
      * @param level The verbosity level of the message.
 202   
      */
 203  0
     private void log(String mesg, int level) {
 204  0
         if (record && (level <= loglevel)) {
 205  0
             out.println(mesg);
 206   
         }
 207   
     }
 208   
 
 209   
 
 210  0
     public void setMessageOutputLevel(int level) {
 211  0
         if (level >= Project.MSG_ERR && level <= Project.MSG_DEBUG) {
 212  0
             loglevel = level;
 213   
         }
 214   
     }
 215   
 
 216   
 
 217  0
     public void setOutputPrintStream(PrintStream output) {
 218  0
         out = output;
 219   
     }
 220   
 
 221   
 
 222  0
     public void setEmacsMode(boolean emacsMode) {
 223  0
         this.emacsMode = emacsMode;
 224   
     }
 225   
 
 226   
 
 227  0
     public void setErrorPrintStream(PrintStream err) {
 228  0
         out = err;
 229   
     }
 230   
 
 231   
 
 232  0
     private static String formatTime(long millis) {
 233  0
         long seconds = millis / 1000;
 234  0
         long minutes = seconds / 60;
 235   
 
 236   
 
 237  0
         if (minutes > 0) {
 238  0
             return Long.toString(minutes) + " minute"
 239   
                  + (minutes == 1 ? " " : "s ")
 240   
                  + Long.toString(seconds % 60) + " second"
 241   
                  + (seconds % 60 == 1 ? "" : "s");
 242   
         } else {
 243  0
             return Long.toString(seconds) + " second"
 244   
                  + (seconds % 60 == 1 ? "" : "s");
 245   
         }
 246   
 
 247   
     }
 248   
 }
 249   
 
 250