Coverage Report - org.owasp.dependencycheck.ant.logging.AntLoggerAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
AntLoggerAdapter
26%
26/99
18%
9/48
1.75
 
 1  
 /*
 2  
  * This file is part of dependency-check-ant.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  *
 16  
  * Copyright (c) 2015 The OWASP Foundation. All Rights Reserved.
 17  
  */
 18  
 package org.owasp.dependencycheck.ant.logging;
 19  
 
 20  
 import org.apache.tools.ant.Project;
 21  
 import org.apache.tools.ant.Task;
 22  
 import org.slf4j.helpers.FormattingTuple;
 23  
 import org.slf4j.helpers.MarkerIgnoringBase;
 24  
 import org.slf4j.helpers.MessageFormatter;
 25  
 
 26  
 /**
 27  
  * An instance of {@link org.slf4j.Logger} which simply calls the log method on the delegate Ant task
 28  
  *
 29  
  * @author colezlaw
 30  
  */
 31  
 public class AntLoggerAdapter extends MarkerIgnoringBase {
 32  
 
 33  
     /**
 34  
      * A reference to the Ant task used for logging.
 35  
      */
 36  
     private Task task;
 37  
 
 38  
     /**
 39  
      * Constructs an Ant Logger Adapter.
 40  
      *
 41  
      * @param task the Ant Task to use for logging
 42  
      */
 43  
     public AntLoggerAdapter(Task task) {
 44  40
         super();
 45  40
         this.task = task;
 46  40
     }
 47  
 
 48  
     /**
 49  
      * Sets the current Ant task to use for logging.
 50  
      *
 51  
      * @param task the Ant task to use for logging
 52  
      */
 53  
     public void setTask(Task task) {
 54  0
         this.task = task;
 55  0
     }
 56  
 
 57  
     @Override
 58  
     public boolean isTraceEnabled() {
 59  
         // Might be a more efficient way to do this, but Ant doesn't enable or disable
 60  
         // various levels globally - it just fires things at registered Listeners.
 61  0
         return true;
 62  
     }
 63  
 
 64  
     @Override
 65  
     public void trace(String msg) {
 66  216
         task.log(msg, Project.MSG_VERBOSE);
 67  216
     }
 68  
 
 69  
     @Override
 70  
     public void trace(String format, Object arg) {
 71  64
         if (task != null) {
 72  0
             final FormattingTuple tp = MessageFormatter.format(format, arg);
 73  0
             task.log(tp.getMessage(), Project.MSG_VERBOSE);
 74  
         }
 75  64
     }
 76  
 
 77  
     @Override
 78  
     public void trace(String format, Object arg1, Object arg2) {
 79  0
         if (task != null) {
 80  0
             final FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
 81  0
             task.log(tp.getMessage(), Project.MSG_VERBOSE);
 82  
         }
 83  0
     }
 84  
 
 85  
     @Override
 86  
     public void trace(String format, Object... arguments) {
 87  0
         if (task != null) {
 88  0
             final FormattingTuple tp = MessageFormatter.format(format, arguments);
 89  0
             task.log(tp.getMessage(), Project.MSG_VERBOSE);
 90  
         }
 91  0
     }
 92  
 
 93  
     @Override
 94  
     public void trace(String msg, Throwable t) {
 95  0
         if (task != null) {
 96  0
             task.log(msg, t, Project.MSG_VERBOSE);
 97  
         }
 98  0
     }
 99  
 
 100  
     @Override
 101  
     public boolean isDebugEnabled() {
 102  80
         return true;
 103  
     }
 104  
 
 105  
     @Override
 106  
     public void debug(String msg) {
 107  966
         if (task != null) {
 108  886
             task.log(msg, Project.MSG_DEBUG);
 109  
         }
 110  966
     }
 111  
 
 112  
     @Override
 113  
     public void debug(String format, Object arg) {
 114  2960
         if (task != null) {
 115  2856
             final FormattingTuple tp = MessageFormatter.format(format, arg);
 116  2856
             task.log(tp.getMessage(), Project.MSG_DEBUG);
 117  
         }
 118  2960
     }
 119  
 
 120  
     @Override
 121  
     public void debug(String format, Object arg1, Object arg2) {
 122  280
         if (task != null) {
 123  64
             final FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
 124  64
             task.log(tp.getMessage(), Project.MSG_DEBUG);
 125  
         }
 126  280
     }
 127  
 
 128  
     @Override
 129  
     public void debug(String format, Object... arguments) {
 130  16
         if (task != null) {
 131  16
             final FormattingTuple tp = MessageFormatter.format(format, arguments);
 132  16
             task.log(tp.getMessage(), Project.MSG_DEBUG);
 133  
         }
 134  16
     }
 135  
 
 136  
     @Override
 137  
     public void debug(String msg, Throwable t) {
 138  0
         if (task != null) {
 139  0
             task.log(msg, t, Project.MSG_DEBUG);
 140  
         }
 141  0
     }
 142  
 
 143  
     @Override
 144  
     public boolean isInfoEnabled() {
 145  0
         return true;
 146  
     }
 147  
 
 148  
     @Override
 149  
     public void info(String msg) {
 150  72
         if (task != null) {
 151  72
             task.log(msg, Project.MSG_INFO);
 152  
         }
 153  72
     }
 154  
 
 155  
     @Override
 156  
     public void info(String format, Object arg) {
 157  0
         if (task != null) {
 158  0
             final FormattingTuple tp = MessageFormatter.format(format, arg);
 159  0
             task.log(tp.getMessage(), Project.MSG_INFO);
 160  
         }
 161  0
     }
 162  
 
 163  
     @Override
 164  
     public void info(String format, Object arg1, Object arg2) {
 165  0
         if (task != null) {
 166  0
             final FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
 167  0
             task.log(tp.getMessage(), Project.MSG_INFO);
 168  
         }
 169  0
     }
 170  
 
 171  
     @Override
 172  
     public void info(String format, Object... arguments) {
 173  0
         if (task != null) {
 174  0
             final FormattingTuple tp = MessageFormatter.format(format, arguments);
 175  0
             task.log(tp.getMessage(), Project.MSG_INFO);
 176  
         }
 177  0
     }
 178  
 
 179  
     @Override
 180  
     public void info(String msg, Throwable t) {
 181  0
         if (task != null) {
 182  0
             task.log(msg, t, Project.MSG_INFO);
 183  
         }
 184  0
     }
 185  
 
 186  
     @Override
 187  
     public boolean isWarnEnabled() {
 188  0
         return true;
 189  
     }
 190  
 
 191  
     @Override
 192  
     public void warn(String msg) {
 193  0
         if (task != null) {
 194  0
             task.log(msg, Project.MSG_WARN);
 195  
         }
 196  0
     }
 197  
 
 198  
     @Override
 199  
     public void warn(String format, Object arg) {
 200  0
         if (task != null) {
 201  0
             final FormattingTuple tp = MessageFormatter.format(format, arg);
 202  0
             task.log(tp.getMessage(), Project.MSG_WARN);
 203  
         }
 204  0
     }
 205  
 
 206  
     @Override
 207  
     public void warn(String format, Object... arguments) {
 208  0
         if (task != null) {
 209  0
             final FormattingTuple tp = MessageFormatter.format(format, arguments);
 210  0
             task.log(tp.getMessage(), Project.MSG_WARN);
 211  
         }
 212  0
     }
 213  
 
 214  
     @Override
 215  
     public void warn(String format, Object arg1, Object arg2) {
 216  0
         if (task != null) {
 217  0
             final FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
 218  0
             task.log(tp.getMessage(), Project.MSG_WARN);
 219  
         }
 220  0
     }
 221  
 
 222  
     @Override
 223  
     public void warn(String msg, Throwable t) {
 224  0
         if (task != null) {
 225  0
             task.log(msg, t, Project.MSG_WARN);
 226  
         }
 227  0
     }
 228  
 
 229  
     @Override
 230  
     public boolean isErrorEnabled() {
 231  0
         return true;
 232  
     }
 233  
 
 234  
     @Override
 235  
     public void error(String msg) {
 236  0
         if (task != null) {
 237  0
             task.log(msg, Project.MSG_ERR);
 238  
         }
 239  0
     }
 240  
 
 241  
     @Override
 242  
     public void error(String format, Object arg) {
 243  0
         if (task != null) {
 244  0
             final FormattingTuple tp = MessageFormatter.format(format, arg);
 245  0
             task.log(tp.getMessage(), Project.MSG_ERR);
 246  
         }
 247  0
     }
 248  
 
 249  
     @Override
 250  
     public void error(String format, Object arg1, Object arg2) {
 251  0
         if (task != null) {
 252  0
             final FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
 253  0
             task.log(tp.getMessage(), Project.MSG_ERR);
 254  
         }
 255  0
     }
 256  
 
 257  
     @Override
 258  
     public void error(String format, Object... arguments) {
 259  0
         if (task != null) {
 260  0
             final FormattingTuple tp = MessageFormatter.format(format, arguments);
 261  0
             task.log(tp.getMessage(), Project.MSG_ERR);
 262  
         }
 263  0
     }
 264  
 
 265  
     @Override
 266  
     public void error(String msg, Throwable t) {
 267  0
         if (task != null) {
 268  0
             task.log(msg, t, Project.MSG_ERR);
 269  
         }
 270  0
     }
 271  
 }