Clover coverage report - Cactus 1.5 for J2EE API 1.2
Coverage timestamp: Wed Feb 18 2004 09:04:33 EST
file stats: LOC: 468   Methods: 40
NCLOC: 180   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AntLog.java 0% 0% 2.5% 1.2%
coverage coverage
 1   
 /*
 2   
  * ====================================================================
 3   
  *
 4   
  * The Apache Software License, Version 1.1
 5   
  *
 6   
  * Copyright (c) 2003 The Apache Software Foundation.  All rights
 7   
  * reserved.
 8   
  *
 9   
  * Redistribution and use in source and binary forms, with or without
 10   
  * modification, are permitted provided that the following conditions
 11   
  * are met:
 12   
  *
 13   
  * 1. Redistributions of source code must retain the above copyright
 14   
  *    notice, this list of conditions and the following disclaimer.
 15   
  *
 16   
  * 2. Redistributions in binary form must reproduce the above copyright
 17   
  *    notice, this list of conditions and the following disclaimer in
 18   
  *    the documentation and/or other materials provided with the
 19   
  *    distribution.
 20   
  *
 21   
  * 3. The end-user documentation included with the redistribution, if
 22   
  *    any, must include the following acknowlegement:
 23   
  *       "This product includes software developed by the
 24   
  *        Apache Software Foundation (http://www.apache.org/)."
 25   
  *    Alternately, this acknowlegement may appear in the software itself,
 26   
  *    if and wherever such third-party acknowlegements normally appear.
 27   
  *
 28   
  * 4. The names "The Jakarta Project", "Cactus" and "Apache Software
 29   
  *    Foundation" must not be used to endorse or promote products
 30   
  *    derived from this software without prior written permission. For
 31   
  *    written permission, please contact apache@apache.org.
 32   
  *
 33   
  * 5. Products derived from this software may not be called "Apache"
 34   
  *    nor may "Apache" appear in their names without prior written
 35   
  *    permission of the Apache Group.
 36   
  *
 37   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 38   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 39   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 40   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 41   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 42   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 43   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 44   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 45   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 46   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 47   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 48   
  * SUCH DAMAGE.
 49   
  * ====================================================================
 50   
  *
 51   
  * This software consists of voluntary contributions made by many
 52   
  * individuals on behalf of the Apache Software Foundation.  For more
 53   
  * information on the Apache Software Foundation, please see
 54   
  * <http://www.apache.org/>.
 55   
  *
 56   
  */
 57   
 package org.apache.cactus.integration.ant.util;
 58   
 
 59   
 import org.apache.commons.logging.Log;
 60   
 import org.apache.tools.ant.Project;
 61   
 import org.apache.tools.ant.Target;
 62   
 import org.apache.tools.ant.Task;
 63   
 
 64   
 /**
 65   
  * Support class that lets classes log to Ant using the Commons Logging API. 
 66   
  * 
 67   
  * This is not intended to be a general solution, rather as a thin separation
 68   
  * layer to not have to pass around full-blown Ant <code>Project</code>, 
 69   
  * <code>Target</code> or <code>Task</code> objects just to enable logging.
 70   
  * 
 71   
  * Note that as there is no log level in Commons-Logging that corresponds to
 72   
  * Ant's <em>VERBOSE</em> level (the level between <em>INFO</em> and
 73   
  * <em>DEBUG</em>), the <em>TRACE</em> level of Commons-Logging gets mapped to
 74   
  * <em>VERBOSE</em>, which is probably inappropriate for components that do not
 75   
  * know they are using the <code>AntLog</code> class. 
 76   
  * 
 77   
  * @author <a href="mailto:cmlenz@apache.org">Christopher Lenz</a>
 78   
  *
 79   
  * @version $Id: AntLog.java,v 1.4 2003/06/11 16:18:33 cmlenz Exp $
 80   
  */
 81   
 public final class AntLog implements Log
 82   
 {
 83   
 
 84   
     // Constants ---------------------------------------------------------------
 85   
 
 86   
     /**
 87   
      * Singleton log implementation that simply ignores all log requests.
 88   
      */
 89   
     public static final Log NULL = new Log()
 90   
     {
 91   
 
 92   
         // Log Implementation --------------------------------------------------
 93   
 
 94   
         /**
 95   
          * @see org.apache.commons.logging.Log#isFatalEnabled()
 96   
          */
 97  0
         public boolean isFatalEnabled()
 98   
         {
 99  0
             return false;
 100   
         }
 101   
 
 102   
         /**
 103   
          * @see org.apache.commons.logging.Log#fatal(Object)
 104   
          */
 105  0
         public void fatal(Object theMessage)
 106   
         {
 107   
             // do nothing
 108   
         }
 109   
 
 110   
         /**
 111   
          * @see org.apache.commons.logging.Log#fatal(Object, Throwable)
 112   
          */
 113  0
         public void fatal(Object theMessage, Throwable theThrowable)
 114   
         {
 115   
             // do nothing
 116   
         }
 117   
 
 118   
         /**
 119   
          * @see org.apache.commons.logging.Log#isErrorEnabled()
 120   
          */
 121  0
         public boolean isErrorEnabled()
 122   
         {
 123  0
             return false;
 124   
         }
 125   
 
 126   
         /**
 127   
          * @see org.apache.commons.logging.Log#error(Object)
 128   
          */
 129  0
         public void error(Object theMessage)
 130   
         {
 131   
             // do nothing
 132   
         }
 133   
 
 134   
         /**
 135   
          * @see org.apache.commons.logging.Log#error(Object, Throwable)
 136   
          */
 137  0
         public void error(Object theMessage, Throwable theThrowable)
 138   
         {
 139   
             // do nothing
 140   
         }
 141   
 
 142   
         /**
 143   
          * @see org.apache.commons.logging.Log#isWarnEnabled()
 144   
          */
 145  0
         public boolean isWarnEnabled()
 146   
         {
 147  0
             return false;
 148   
         }
 149   
 
 150   
         /**
 151   
          * @see org.apache.commons.logging.Log#warn(Object)
 152   
          */
 153  0
         public void warn(Object theMessage)
 154   
         {
 155   
             // do nothing
 156   
         }
 157   
 
 158   
         /**
 159   
          * @see org.apache.commons.logging.Log#warn(Object, Throwable)
 160   
          */
 161  0
         public void warn(Object theMessage, Throwable theThrowable)
 162   
         {
 163   
             // do nothing
 164   
         }
 165   
 
 166   
         /**
 167   
          * @see org.apache.commons.logging.Log#isInfoEnabled()
 168   
          */
 169  0
         public boolean isInfoEnabled()
 170   
         {
 171  0
             return false;
 172   
         }
 173   
 
 174   
         /**
 175   
          * @see org.apache.commons.logging.Log#info(Object)
 176   
          */
 177  0
         public void info(Object theMessage)
 178   
         {
 179   
             // do nothing
 180   
         }
 181   
 
 182   
         /**
 183   
          * @see org.apache.commons.logging.Log#info(Object, Throwable)
 184   
          */
 185  0
         public void info(Object theMessage, Throwable theThrowable)
 186   
         {
 187   
             // do nothing
 188   
         }
 189   
 
 190   
         /**
 191   
          * @see org.apache.commons.logging.Log#isDebugEnabled()
 192   
          */
 193  0
         public boolean isDebugEnabled()
 194   
         {
 195  0
             return false;
 196   
         }
 197   
 
 198   
         /**
 199   
          * @see org.apache.commons.logging.Log#debug(Object)
 200   
          */
 201  0
         public void debug(Object theMessage)
 202   
         {
 203   
             // do nothing
 204   
         }
 205   
 
 206   
         /**
 207   
          * @see org.apache.commons.logging.Log#debug(Object, Throwable)
 208   
          */
 209  0
         public void debug(Object theMessage, Throwable theThrowable)
 210   
         {
 211   
             // do nothing
 212   
         }
 213   
 
 214   
         /**
 215   
          * @see org.apache.commons.logging.Log#isTraceEnabled()
 216   
          */
 217  0
         public boolean isTraceEnabled()
 218   
         {
 219  0
             return false;
 220   
         }
 221   
 
 222   
         /**
 223   
          * @see org.apache.commons.logging.Log#trace(Object)
 224   
          */
 225  18
         public void trace(Object theMessage)
 226   
         {
 227   
             // do nothing
 228   
         }
 229   
 
 230   
         /**
 231   
          * @see org.apache.commons.logging.Log#trace(Object, Throwable)
 232   
          */
 233  0
         public void trace(Object theMessage, Throwable theThrowable)
 234   
         {
 235   
             // do nothing
 236   
         }
 237   
 
 238   
     };
 239   
 
 240   
     // Instance Variables ------------------------------------------------------
 241   
 
 242   
     /**
 243   
      * The Ant project.
 244   
      */
 245   
     private Project project;
 246   
 
 247   
     /**
 248   
      * The current target, or <code>null</code> if used outside of a target.
 249   
      */
 250   
     private Target target;
 251   
 
 252   
     /**
 253   
      * The task, or <code>null</code> if not used by a task.
 254   
      */
 255   
     private Task task;
 256   
 
 257   
     // Constructors ------------------------------------------------------------
 258   
 
 259   
     /**
 260   
      * Constructor.
 261   
      * 
 262   
      * @param theTask The Ant task
 263   
      */
 264  0
     public AntLog(Task theTask)
 265   
     {
 266  0
         this.project = theTask.getProject();
 267  0
         this.task = theTask;
 268   
     }
 269   
 
 270   
     /**
 271   
      * Constructor.
 272   
      * 
 273   
      * @param theTarget The current target
 274   
      */
 275  0
     public AntLog(Target theTarget)
 276   
     {
 277  0
         this.project = theTarget.getProject();
 278  0
         this.target = theTarget;
 279   
     }
 280   
 
 281   
     /**
 282   
      * Constructor.
 283   
      * 
 284   
      * @param theProject The Ant project
 285   
      */
 286  0
     public AntLog(Project theProject)
 287   
     {
 288  0
         this.project = theProject;
 289   
     }
 290   
 
 291   
     // Log Implementation ------------------------------------------------------
 292   
 
 293   
     /**
 294   
      * @see org.apache.commons.logging.Log#isFatalEnabled()
 295   
      */
 296  0
     public boolean isFatalEnabled()
 297   
     {
 298  0
         return true;
 299   
     }
 300   
 
 301   
     /**
 302   
      * @see org.apache.commons.logging.Log#fatal(Object)
 303   
      */
 304  0
     public void fatal(Object theMessage)
 305   
     {
 306  0
         log(theMessage, null, Project.MSG_ERR);
 307   
     }
 308   
 
 309   
     /**
 310   
      * @see org.apache.commons.logging.Log#fatal(Object, Throwable)
 311   
      */
 312  0
     public void fatal(Object theMessage, Throwable theThrowable)
 313   
     {
 314  0
         log(theMessage, theThrowable, Project.MSG_ERR);
 315   
     }
 316   
 
 317   
     /**
 318   
      * @see org.apache.commons.logging.Log#isErrorEnabled()
 319   
      */
 320  0
     public boolean isErrorEnabled()
 321   
     {
 322  0
         return true;
 323   
     }
 324   
 
 325   
     /**
 326   
      * @see org.apache.commons.logging.Log#error(Object)
 327   
      */
 328  0
     public void error(Object theMessage)
 329   
     {
 330  0
         log(theMessage, null, Project.MSG_ERR);
 331   
     }
 332   
 
 333   
     /**
 334   
      * @see org.apache.commons.logging.Log#error(Object, Throwable)
 335   
      */
 336  0
     public void error(Object theMessage, Throwable theThrowable)
 337   
     {
 338  0
         log(theMessage, theThrowable, Project.MSG_ERR);
 339   
     }
 340   
 
 341   
     /**
 342   
      * @see org.apache.commons.logging.Log#isWarnEnabled()
 343   
      */
 344  0
     public boolean isWarnEnabled()
 345   
     {
 346  0
         return true;
 347   
     }
 348   
 
 349   
     /**
 350   
      * @see org.apache.commons.logging.Log#warn(Object)
 351   
      */
 352  0
     public void warn(Object theMessage)
 353   
     {
 354  0
         log(theMessage, null, Project.MSG_WARN);
 355   
     }
 356   
 
 357   
     /**
 358   
      * @see org.apache.commons.logging.Log#warn(Object, Throwable)
 359   
      */
 360  0
     public void warn(Object theMessage, Throwable theThrowable)
 361   
     {
 362  0
         log(theMessage, theThrowable, Project.MSG_WARN);
 363   
     }
 364   
 
 365   
     /**
 366   
      * @see org.apache.commons.logging.Log#isInfoEnabled()
 367   
      */
 368  0
     public boolean isInfoEnabled()
 369   
     {
 370  0
         return true;
 371   
     }
 372   
 
 373   
     /**
 374   
      * @see org.apache.commons.logging.Log#info(Object)
 375   
      */
 376  0
     public void info(Object theMessage)
 377   
     {
 378  0
         log(theMessage, null, Project.MSG_INFO);
 379   
     }
 380   
 
 381   
     /**
 382   
      * @see org.apache.commons.logging.Log#info(Object, Throwable)
 383   
      */
 384  0
     public void info(Object theMessage, Throwable theThrowable)
 385   
     {
 386  0
         log(theMessage, theThrowable, Project.MSG_INFO);
 387   
     }
 388   
 
 389   
     /**
 390   
      * @see org.apache.commons.logging.Log#isDebugEnabled()
 391   
      */
 392  0
     public boolean isDebugEnabled()
 393   
     {
 394  0
         return true;
 395   
     }
 396   
 
 397   
     /**
 398   
      * @see org.apache.commons.logging.Log#debug(Object)
 399   
      */
 400  0
     public void debug(Object theMessage)
 401   
     {
 402  0
         log(theMessage, null, Project.MSG_DEBUG);
 403   
     }
 404   
 
 405   
     /**
 406   
      * @see org.apache.commons.logging.Log#debug(Object, Throwable)
 407   
      */
 408  0
     public void debug(Object theMessage, Throwable theThrowable)
 409   
     {
 410  0
         log(theMessage, theThrowable, Project.MSG_DEBUG);
 411   
     }
 412   
 
 413   
     /**
 414   
      * @see org.apache.commons.logging.Log#isTraceEnabled()
 415   
      */
 416  0
     public boolean isTraceEnabled()
 417   
     {
 418  0
         return true;
 419   
     }
 420   
 
 421   
     /**
 422   
      * @see org.apache.commons.logging.Log#trace(Object)
 423   
      */
 424  0
     public void trace(Object theMessage)
 425   
     {
 426  0
         log(theMessage, null, Project.MSG_VERBOSE);
 427   
     }
 428   
 
 429   
     /**
 430   
      * @see org.apache.commons.logging.Log#trace(Object, Throwable)
 431   
      */
 432  0
     public void trace(Object theMessage, Throwable theThrowable)
 433   
     {
 434  0
         log(theMessage, theThrowable, Project.MSG_VERBOSE);
 435   
     }
 436   
 
 437   
     // Private Methods ---------------------------------------------------------
 438   
 
 439   
     /**
 440   
      * Helper method to log to a certain Ant log level.
 441   
      * 
 442   
      * @param theMessage The log message
 443   
      * @param theThrowable The excecption to be logged, or <code>null</code>
 444   
      * @param theLogLevel The Ant log level
 445   
      */
 446  0
     private void log(Object theMessage, Throwable theThrowable, int theLogLevel)
 447   
     {
 448  0
         String message = String.valueOf(theMessage);
 449  0
         if (theThrowable != null)
 450   
         {
 451  0
             message += " (" + theThrowable.getMessage() + ")";
 452   
         }
 453  0
         if (this.task != null)
 454   
         {
 455  0
             this.project.log(this.task, message, theLogLevel);
 456   
         }
 457  0
         else if (this.target != null)
 458   
         {
 459  0
             this.project.log(this.target, message, theLogLevel);
 460   
         }
 461   
         else
 462   
         {
 463  0
             this.project.log(message, theLogLevel);
 464   
         }
 465   
     }
 466   
 
 467   
 }
 468