Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 205   Methods: 8
NCLOC: 107   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Log4jListener.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   
 
 55   
 package org.apache.tools.ant.listener;
 56   
 
 57   
 import org.apache.log4j.Category;
 58   
 import org.apache.log4j.helpers.NullEnumeration;
 59   
 import org.apache.tools.ant.BuildEvent;
 60   
 import org.apache.tools.ant.BuildListener;
 61   
 import org.apache.tools.ant.Project;
 62   
 import org.apache.tools.ant.Target;
 63   
 import org.apache.tools.ant.Task;
 64   
 
 65   
 
 66   
 /**
 67   
  *  Listener which sends events to Log4j logging system
 68   
  *
 69   
  * @author Conor MacNeill
 70   
  */
 71   
 public class Log4jListener implements BuildListener {
 72   
 
 73   
     /** Indicates if the listener was initialized. */
 74   
     private boolean initialized = false;
 75   
 
 76   
     /** 
 77   
      * Construct the listener and make sure there is a valid appender.
 78   
      */
 79  0
     public Log4jListener() {
 80  0
         initialized = false;
 81  0
         Category cat = Category.getInstance("org.apache.tools.ant");
 82  0
         Category rootCat = Category.getRoot();
 83  0
         if (!(rootCat.getAllAppenders() instanceof NullEnumeration)) {
 84  0
             initialized = true;
 85   
         } else {
 86  0
             cat.error("No log4j.properties in build area");
 87   
         }
 88   
     }
 89   
 
 90   
     /**
 91   
      * @see BuildListener#buildStarted
 92   
      */
 93  0
     public void buildStarted(BuildEvent event) {
 94  0
         if (initialized) {
 95  0
             Category cat = Category.getInstance(Project.class.getName());
 96  0
             cat.info("Build started.");
 97   
         }
 98   
     }
 99   
 
 100   
     /**
 101   
      * @see BuildListener#buildFinished
 102   
      */
 103  0
     public void buildFinished(BuildEvent event) {
 104  0
         if (initialized) {
 105  0
             Category cat = Category.getInstance(Project.class.getName());
 106  0
             if (event.getException() == null) {
 107  0
                 cat.info("Build finished.");
 108   
             } else {
 109  0
                 cat.error("Build finished with error.", event.getException());
 110   
             }
 111   
         }
 112   
     }
 113   
 
 114   
     /**
 115   
      * @see BuildListener#targetStarted
 116   
      */
 117  0
     public void targetStarted(BuildEvent event) {
 118  0
         if (initialized) {
 119  0
             Category cat = Category.getInstance(Target.class.getName());
 120  0
             cat.info("Target \"" + event.getTarget().getName() + "\" started.");
 121   
         }
 122   
     }
 123   
 
 124   
     /**
 125   
      * @see BuildListener#targetFinished
 126   
      */
 127  0
     public void targetFinished(BuildEvent event) {
 128  0
         if (initialized) {
 129  0
             String targetName = event.getTarget().getName();
 130  0
             Category cat = Category.getInstance(Target.class.getName());
 131  0
             if (event.getException() == null) {
 132  0
                 cat.info("Target \"" + targetName + "\" finished.");
 133   
             } else {
 134  0
                 cat.error("Target \"" + targetName 
 135   
                     + "\" finished with error.", event.getException());
 136   
             }
 137   
         }
 138   
     }
 139   
 
 140   
     /**
 141   
      * @see BuildListener#taskStarted
 142   
      */
 143  0
     public void taskStarted(BuildEvent event) {
 144  0
         if (initialized) {
 145  0
             Task task = event.getTask();
 146  0
             Category cat = Category.getInstance(task.getClass().getName());
 147  0
             cat.info("Task \"" + task.getTaskName() + "\" started.");
 148   
         }
 149   
     }
 150   
 
 151   
     /**
 152   
      * @see BuildListener#taskFinished
 153   
      */
 154  0
     public void taskFinished(BuildEvent event) {
 155  0
         if (initialized) {
 156  0
             Task task = event.getTask();
 157  0
             Category cat = Category.getInstance(task.getClass().getName());
 158  0
             if (event.getException() == null) {
 159  0
                 cat.info("Task \"" + task.getTaskName() + "\" finished.");
 160   
             } else {
 161  0
                 cat.error("Task \"" + task.getTaskName() 
 162   
                     + "\" finished with error.", event.getException());
 163   
             }
 164   
         }
 165   
     }
 166   
 
 167   
     /**
 168   
      * @see BuildListener#messageLogged
 169   
      */
 170  0
     public void messageLogged(BuildEvent event) {
 171  0
         if (initialized) {
 172  0
             Object categoryObject = event.getTask();
 173  0
             if (categoryObject == null) {
 174  0
                 categoryObject = event.getTarget();
 175  0
                 if (categoryObject == null) {
 176  0
                     categoryObject = event.getProject();
 177   
                 }
 178   
             }
 179   
 
 180  0
             Category cat 
 181   
                 = Category.getInstance(categoryObject.getClass().getName());
 182  0
             switch (event.getPriority()) {
 183   
                 case Project.MSG_ERR:
 184  0
                     cat.error(event.getMessage());
 185  0
                     break;
 186   
                 case Project.MSG_WARN:
 187  0
                     cat.warn(event.getMessage());
 188  0
                     break;
 189   
                 case Project.MSG_INFO:
 190  0
                     cat.info(event.getMessage());
 191  0
                     break;
 192   
                 case Project.MSG_VERBOSE:
 193  0
                     cat.debug(event.getMessage());
 194  0
                     break;
 195   
                 case Project.MSG_DEBUG:
 196  0
                     cat.debug(event.getMessage());
 197  0
                     break;
 198   
                 default:
 199  0
                     cat.error(event.getMessage());
 200  0
                     break;
 201   
             }
 202   
         }
 203   
     }
 204   
 }
 205