2011/08/05 - Jakarta Cactus has been retired.

For more information, please explore the Attic.

Clover coverage report - Cactus 1.8dev for J2EE API 1.3
Coverage timestamp: Sun Mar 26 2006 18:50:18 BRT
file stats: LOC: 429   Methods: 40
NCLOC: 180   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
AntLog.java 0% 0% 2.5% 1.2%
coverage coverage
 1   
 /* 
 2   
  * ========================================================================
 3   
  * 
 4   
  * Copyright 2003 The Apache Software Foundation.
 5   
  *
 6   
  * Licensed under the Apache License, Version 2.0 (the "License");
 7   
  * you may not use this file except in compliance with the License.
 8   
  * You may obtain a copy of the License at
 9   
  * 
 10   
  *   http://www.apache.org/licenses/LICENSE-2.0
 11   
  * 
 12   
  * Unless required by applicable law or agreed to in writing, software
 13   
  * distributed under the License is distributed on an "AS IS" BASIS,
 14   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15   
  * See the License for the specific language governing permissions and
 16   
  * limitations under the License.
 17   
  * 
 18   
  * ========================================================================
 19   
  */
 20   
 package org.apache.cactus.integration.ant.util;
 21   
 
 22   
 import org.apache.commons.logging.Log;
 23   
 import org.apache.tools.ant.Project;
 24   
 import org.apache.tools.ant.Target;
 25   
 import org.apache.tools.ant.Task;
 26   
 
 27   
 /**
 28   
  * Support class that lets classes log to Ant using the Commons Logging API. 
 29   
  * 
 30   
  * This is not intended to be a general solution, rather as a thin separation
 31   
  * layer to not have to pass around full-blown Ant <code>Project</code>, 
 32   
  * <code>Target</code> or <code>Task</code> objects just to enable logging.
 33   
  * 
 34   
  * Note that as there is no log level in Commons-Logging that corresponds to
 35   
  * Ant's <em>VERBOSE</em> level (the level between <em>INFO</em> and
 36   
  * <em>DEBUG</em>), the <em>TRACE</em> level of Commons-Logging gets mapped to
 37   
  * <em>VERBOSE</em>, which is probably inappropriate for components that do not
 38   
  * know they are using the <code>AntLog</code> class. 
 39   
  * 
 40   
  * @version $Id: AntLog.java 238812 2004-02-29 10:21:34Z vmassol $
 41   
  */
 42   
 public final class AntLog implements Log
 43   
 {
 44   
 
 45   
     // Constants ---------------------------------------------------------------
 46   
 
 47   
     /**
 48   
      * Singleton log implementation that simply ignores all log requests.
 49   
      */
 50   
     public static final Log NULL = new Log()
 51   
     {
 52   
 
 53   
         // Log Implementation --------------------------------------------------
 54   
 
 55   
         /**
 56   
          * @see org.apache.commons.logging.Log#isFatalEnabled()
 57   
          */
 58  0
         public boolean isFatalEnabled()
 59   
         {
 60  0
             return false;
 61   
         }
 62   
 
 63   
         /**
 64   
          * @see org.apache.commons.logging.Log#fatal(Object)
 65   
          */
 66  0
         public void fatal(Object theMessage)
 67   
         {
 68   
             // do nothing
 69   
         }
 70   
 
 71   
         /**
 72   
          * @see org.apache.commons.logging.Log#fatal(Object, Throwable)
 73   
          */
 74  0
         public void fatal(Object theMessage, Throwable theThrowable)
 75   
         {
 76   
             // do nothing
 77   
         }
 78   
 
 79   
         /**
 80   
          * @see org.apache.commons.logging.Log#isErrorEnabled()
 81   
          */
 82  0
         public boolean isErrorEnabled()
 83   
         {
 84  0
             return false;
 85   
         }
 86   
 
 87   
         /**
 88   
          * @see org.apache.commons.logging.Log#error(Object)
 89   
          */
 90  0
         public void error(Object theMessage)
 91   
         {
 92   
             // do nothing
 93   
         }
 94   
 
 95   
         /**
 96   
          * @see org.apache.commons.logging.Log#error(Object, Throwable)
 97   
          */
 98  0
         public void error(Object theMessage, Throwable theThrowable)
 99   
         {
 100   
             // do nothing
 101   
         }
 102   
 
 103   
         /**
 104   
          * @see org.apache.commons.logging.Log#isWarnEnabled()
 105   
          */
 106  0
         public boolean isWarnEnabled()
 107   
         {
 108  0
             return false;
 109   
         }
 110   
 
 111   
         /**
 112   
          * @see org.apache.commons.logging.Log#warn(Object)
 113   
          */
 114  0
         public void warn(Object theMessage)
 115   
         {
 116   
             // do nothing
 117   
         }
 118   
 
 119   
         /**
 120   
          * @see org.apache.commons.logging.Log#warn(Object, Throwable)
 121   
          */
 122  0
         public void warn(Object theMessage, Throwable theThrowable)
 123   
         {
 124   
             // do nothing
 125   
         }
 126   
 
 127   
         /**
 128   
          * @see org.apache.commons.logging.Log#isInfoEnabled()
 129   
          */
 130  0
         public boolean isInfoEnabled()
 131   
         {
 132  0
             return false;
 133   
         }
 134   
 
 135   
         /**
 136   
          * @see org.apache.commons.logging.Log#info(Object)
 137   
          */
 138  0
         public void info(Object theMessage)
 139   
         {
 140   
             // do nothing
 141   
         }
 142   
 
 143   
         /**
 144   
          * @see org.apache.commons.logging.Log#info(Object, Throwable)
 145   
          */
 146  0
         public void info(Object theMessage, Throwable theThrowable)
 147   
         {
 148   
             // do nothing
 149   
         }
 150   
 
 151   
         /**
 152   
          * @see org.apache.commons.logging.Log#isDebugEnabled()
 153   
          */
 154  0
         public boolean isDebugEnabled()
 155   
         {
 156  0
             return false;
 157   
         }
 158   
 
 159   
         /**
 160   
          * @see org.apache.commons.logging.Log#debug(Object)
 161   
          */
 162  0
         public void debug(Object theMessage)
 163   
         {
 164   
             // do nothing
 165   
         }
 166   
 
 167   
         /**
 168   
          * @see org.apache.commons.logging.Log#debug(Object, Throwable)
 169   
          */
 170  0
         public void debug(Object theMessage, Throwable theThrowable)
 171   
         {
 172   
             // do nothing
 173   
         }
 174   
 
 175   
         /**
 176   
          * @see org.apache.commons.logging.Log#isTraceEnabled()
 177   
          */
 178  0
         public boolean isTraceEnabled()
 179   
         {
 180  0
             return false;
 181   
         }
 182   
 
 183   
         /**
 184   
          * @see org.apache.commons.logging.Log#trace(Object)
 185   
          */
 186  21
         public void trace(Object theMessage)
 187   
         {
 188   
             // do nothing
 189   
         }
 190   
 
 191   
         /**
 192   
          * @see org.apache.commons.logging.Log#trace(Object, Throwable)
 193   
          */
 194  0
         public void trace(Object theMessage, Throwable theThrowable)
 195   
         {
 196   
             // do nothing
 197   
         }
 198   
 
 199   
     };
 200   
 
 201   
     // Instance Variables ------------------------------------------------------
 202   
 
 203   
     /**
 204   
      * The Ant project.
 205   
      */
 206   
     private Project project;
 207   
 
 208   
     /**
 209   
      * The current target, or <code>null</code> if used outside of a target.
 210   
      */
 211   
     private Target target;
 212   
 
 213   
     /**
 214   
      * The task, or <code>null</code> if not used by a task.
 215   
      */
 216   
     private Task task;
 217   
 
 218   
     // Constructors ------------------------------------------------------------
 219   
 
 220   
     /**
 221   
      * Constructor.
 222   
      * 
 223   
      * @param theTask The Ant task
 224   
      */
 225  0
     public AntLog(Task theTask)
 226   
     {
 227  0
         this.project = theTask.getProject();
 228  0
         this.task = theTask;
 229   
     }
 230   
 
 231   
     /**
 232   
      * Constructor.
 233   
      * 
 234   
      * @param theTarget The current target
 235   
      */
 236  0
     public AntLog(Target theTarget)
 237   
     {
 238  0
         this.project = theTarget.getProject();
 239  0
         this.target = theTarget;
 240   
     }
 241   
 
 242   
     /**
 243   
      * Constructor.
 244   
      * 
 245   
      * @param theProject The Ant project
 246   
      */
 247  0
     public AntLog(Project theProject)
 248   
     {
 249  0
         this.project = theProject;
 250   
     }
 251   
 
 252   
     // Log Implementation ------------------------------------------------------
 253   
 
 254   
     /**
 255   
      * @see org.apache.commons.logging.Log#isFatalEnabled()
 256   
      */
 257  0
     public boolean isFatalEnabled()
 258   
     {
 259  0
         return true;
 260   
     }
 261   
 
 262   
     /**
 263   
      * @see org.apache.commons.logging.Log#fatal(Object)
 264   
      */
 265  0
     public void fatal(Object theMessage)
 266   
     {
 267  0
         log(theMessage, null, Project.MSG_ERR);
 268   
     }
 269   
 
 270   
     /**
 271   
      * @see org.apache.commons.logging.Log#fatal(Object, Throwable)
 272   
      */
 273  0
     public void fatal(Object theMessage, Throwable theThrowable)
 274   
     {
 275  0
         log(theMessage, theThrowable, Project.MSG_ERR);
 276   
     }
 277   
 
 278   
     /**
 279   
      * @see org.apache.commons.logging.Log#isErrorEnabled()
 280   
      */
 281  0
     public boolean isErrorEnabled()
 282   
     {
 283  0
         return true;
 284   
     }
 285   
 
 286   
     /**
 287   
      * @see org.apache.commons.logging.Log#error(Object)
 288   
      */
 289  0
     public void error(Object theMessage)
 290   
     {
 291  0
         log(theMessage, null, Project.MSG_ERR);
 292   
     }
 293   
 
 294   
     /**
 295   
      * @see org.apache.commons.logging.Log#error(Object, Throwable)
 296   
      */
 297  0
     public void error(Object theMessage, Throwable theThrowable)
 298   
     {
 299  0
         log(theMessage, theThrowable, Project.MSG_ERR);
 300   
     }
 301   
 
 302   
     /**
 303   
      * @see org.apache.commons.logging.Log#isWarnEnabled()
 304   
      */
 305  0
     public boolean isWarnEnabled()
 306   
     {
 307  0
         return true;
 308   
     }
 309   
 
 310   
     /**
 311   
      * @see org.apache.commons.logging.Log#warn(Object)
 312   
      */
 313  0
     public void warn(Object theMessage)
 314   
     {
 315  0
         log(theMessage, null, Project.MSG_WARN);
 316   
     }
 317   
 
 318   
     /**
 319   
      * @see org.apache.commons.logging.Log#warn(Object, Throwable)
 320   
      */
 321  0
     public void warn(Object theMessage, Throwable theThrowable)
 322   
     {
 323  0
         log(theMessage, theThrowable, Project.MSG_WARN);
 324   
     }
 325   
 
 326   
     /**
 327   
      * @see org.apache.commons.logging.Log#isInfoEnabled()
 328   
      */
 329  0
     public boolean isInfoEnabled()
 330   
     {
 331  0
         return true;
 332   
     }
 333   
 
 334   
     /**
 335   
      * @see org.apache.commons.logging.Log#info(Object)
 336   
      */
 337  0
     public void info(Object theMessage)
 338   
     {
 339  0
         log(theMessage, null, Project.MSG_INFO);
 340   
     }
 341   
 
 342   
     /**
 343   
      * @see org.apache.commons.logging.Log#info(Object, Throwable)
 344   
      */
 345  0
     public void info(Object theMessage, Throwable theThrowable)
 346   
     {
 347  0
         log(theMessage, theThrowable, Project.MSG_INFO);
 348   
     }
 349   
 
 350   
     /**
 351   
      * @see org.apache.commons.logging.Log#isDebugEnabled()
 352   
      */
 353  0
     public boolean isDebugEnabled()
 354   
     {
 355  0
         return true;
 356   
     }
 357   
 
 358   
     /**
 359   
      * @see org.apache.commons.logging.Log#debug(Object)
 360   
      */
 361  0
     public void debug(Object theMessage)
 362   
     {
 363  0
         log(theMessage, null, Project.MSG_DEBUG);
 364   
     }
 365   
 
 366   
     /**
 367   
      * @see org.apache.commons.logging.Log#debug(Object, Throwable)
 368   
      */
 369  0
     public void debug(Object theMessage, Throwable theThrowable)
 370   
     {
 371  0
         log(theMessage, theThrowable, Project.MSG_DEBUG);
 372   
     }
 373   
 
 374   
     /**
 375   
      * @see org.apache.commons.logging.Log#isTraceEnabled()
 376   
      */
 377  0
     public boolean isTraceEnabled()
 378   
     {
 379  0
         return true;
 380   
     }
 381   
 
 382   
     /**
 383   
      * @see org.apache.commons.logging.Log#trace(Object)
 384   
      */
 385  0
     public void trace(Object theMessage)
 386   
     {
 387  0
         log(theMessage, null, Project.MSG_VERBOSE);
 388   
     }
 389   
 
 390   
     /**
 391   
      * @see org.apache.commons.logging.Log#trace(Object, Throwable)
 392   
      */
 393  0
     public void trace(Object theMessage, Throwable theThrowable)
 394   
     {
 395  0
         log(theMessage, theThrowable, Project.MSG_VERBOSE);
 396   
     }
 397   
 
 398   
     // Private Methods ---------------------------------------------------------
 399   
 
 400   
     /**
 401   
      * Helper method to log to a certain Ant log level.
 402   
      * 
 403   
      * @param theMessage The log message
 404   
      * @param theThrowable The excecption to be logged, or <code>null</code>
 405   
      * @param theLogLevel The Ant log level
 406   
      */
 407  0
     private void log(Object theMessage, Throwable theThrowable, int theLogLevel)
 408   
     {
 409  0
         String message = String.valueOf(theMessage);
 410  0
         if (theThrowable != null)
 411   
         {
 412  0
             message += " (" + theThrowable.getMessage() + ")";
 413   
         }
 414  0
         if (this.task != null)
 415   
         {
 416  0
             this.project.log(this.task, message, theLogLevel);
 417   
         }
 418  0
         else if (this.target != null)
 419   
         {
 420  0
             this.project.log(this.target, message, theLogLevel);
 421   
         }
 422   
         else
 423   
         {
 424  0
             this.project.log(message, theLogLevel);
 425   
         }
 426   
     }
 427   
 
 428   
 }
 429