Coverage Report - org.owasp.dependencycheck.ant.logging.AntLoggerAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
AntLoggerAdapter
35%
35/100
28%
14/50
1.781
 
 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  13
         super();
 45  13
         this.task = task;
 46  13
     }
 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  31
         if (task != null) {
 67  27
             task.log(msg, Project.MSG_VERBOSE);
 68  
         }
 69  31
     }
 70  
 
 71  
     @Override
 72  
     public void trace(String format, Object arg) {
 73  29
         if (task != null) {
 74  21
             final FormattingTuple tp = MessageFormatter.format(format, arg);
 75  21
             task.log(tp.getMessage(), Project.MSG_VERBOSE);
 76  
         }
 77  29
     }
 78  
 
 79  
     @Override
 80  
     public void trace(String format, Object arg1, Object arg2) {
 81  13
         if (task != null) {
 82  0
             final FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
 83  0
             task.log(tp.getMessage(), Project.MSG_VERBOSE);
 84  
         }
 85  13
     }
 86  
 
 87  
     @Override
 88  
     public void trace(String format, Object... arguments) {
 89  0
         if (task != null) {
 90  0
             final FormattingTuple tp = MessageFormatter.format(format, arguments);
 91  0
             task.log(tp.getMessage(), Project.MSG_VERBOSE);
 92  
         }
 93  0
     }
 94  
 
 95  
     @Override
 96  
     public void trace(String msg, Throwable t) {
 97  0
         if (task != null) {
 98  0
             task.log(msg, t, Project.MSG_VERBOSE);
 99  
         }
 100  0
     }
 101  
 
 102  
     @Override
 103  
     public boolean isDebugEnabled() {
 104  10
         return true;
 105  
     }
 106  
 
 107  
     @Override
 108  
     public void debug(String msg) {
 109  134
         if (task != null) {
 110  116
             task.log(msg, Project.MSG_DEBUG);
 111  
         }
 112  134
     }
 113  
 
 114  
     @Override
 115  
     public void debug(String format, Object arg) {
 116  382
         if (task != null) {
 117  369
             final FormattingTuple tp = MessageFormatter.format(format, arg);
 118  369
             task.log(tp.getMessage(), Project.MSG_DEBUG);
 119  
         }
 120  382
     }
 121  
 
 122  
     @Override
 123  
     public void debug(String format, Object arg1, Object arg2) {
 124  25
         if (task != null) {
 125  19
             final FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
 126  19
             task.log(tp.getMessage(), Project.MSG_DEBUG);
 127  
         }
 128  25
     }
 129  
 
 130  
     @Override
 131  
     public void debug(String format, Object... arguments) {
 132  2
         if (task != null) {
 133  2
             final FormattingTuple tp = MessageFormatter.format(format, arguments);
 134  2
             task.log(tp.getMessage(), Project.MSG_DEBUG);
 135  
         }
 136  2
     }
 137  
 
 138  
     @Override
 139  
     public void debug(String msg, Throwable t) {
 140  0
         if (task != null) {
 141  0
             task.log(msg, t, Project.MSG_DEBUG);
 142  
         }
 143  0
     }
 144  
 
 145  
     @Override
 146  
     public boolean isInfoEnabled() {
 147  0
         return true;
 148  
     }
 149  
 
 150  
     @Override
 151  
     public void info(String msg) {
 152  6
         if (task != null) {
 153  6
             task.log(msg, Project.MSG_INFO);
 154  
         }
 155  6
     }
 156  
 
 157  
     @Override
 158  
     public void info(String format, Object arg) {
 159  6
         if (task != null) {
 160  6
             final FormattingTuple tp = MessageFormatter.format(format, arg);
 161  6
             task.log(tp.getMessage(), Project.MSG_INFO);
 162  
         }
 163  6
     }
 164  
 
 165  
     @Override
 166  
     public void info(String format, Object arg1, Object arg2) {
 167  0
         if (task != null) {
 168  0
             final FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
 169  0
             task.log(tp.getMessage(), Project.MSG_INFO);
 170  
         }
 171  0
     }
 172  
 
 173  
     @Override
 174  
     public void info(String format, Object... arguments) {
 175  0
         if (task != null) {
 176  0
             final FormattingTuple tp = MessageFormatter.format(format, arguments);
 177  0
             task.log(tp.getMessage(), Project.MSG_INFO);
 178  
         }
 179  0
     }
 180  
 
 181  
     @Override
 182  
     public void info(String msg, Throwable t) {
 183  0
         if (task != null) {
 184  0
             task.log(msg, t, Project.MSG_INFO);
 185  
         }
 186  0
     }
 187  
 
 188  
     @Override
 189  
     public boolean isWarnEnabled() {
 190  0
         return true;
 191  
     }
 192  
 
 193  
     @Override
 194  
     public void warn(String msg) {
 195  0
         if (task != null) {
 196  0
             task.log(msg, Project.MSG_WARN);
 197  
         }
 198  0
     }
 199  
 
 200  
     @Override
 201  
     public void warn(String format, Object arg) {
 202  0
         if (task != null) {
 203  0
             final FormattingTuple tp = MessageFormatter.format(format, arg);
 204  0
             task.log(tp.getMessage(), Project.MSG_WARN);
 205  
         }
 206  0
     }
 207  
 
 208  
     @Override
 209  
     public void warn(String format, Object... arguments) {
 210  0
         if (task != null) {
 211  0
             final FormattingTuple tp = MessageFormatter.format(format, arguments);
 212  0
             task.log(tp.getMessage(), Project.MSG_WARN);
 213  
         }
 214  0
     }
 215  
 
 216  
     @Override
 217  
     public void warn(String format, Object arg1, Object arg2) {
 218  0
         if (task != null) {
 219  0
             final FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
 220  0
             task.log(tp.getMessage(), Project.MSG_WARN);
 221  
         }
 222  0
     }
 223  
 
 224  
     @Override
 225  
     public void warn(String msg, Throwable t) {
 226  0
         if (task != null) {
 227  0
             task.log(msg, t, Project.MSG_WARN);
 228  
         }
 229  0
     }
 230  
 
 231  
     @Override
 232  
     public boolean isErrorEnabled() {
 233  0
         return true;
 234  
     }
 235  
 
 236  
     @Override
 237  
     public void error(String msg) {
 238  0
         if (task != null) {
 239  0
             task.log(msg, Project.MSG_ERR);
 240  
         }
 241  0
     }
 242  
 
 243  
     @Override
 244  
     public void error(String format, Object arg) {
 245  0
         if (task != null) {
 246  0
             final FormattingTuple tp = MessageFormatter.format(format, arg);
 247  0
             task.log(tp.getMessage(), Project.MSG_ERR);
 248  
         }
 249  0
     }
 250  
 
 251  
     @Override
 252  
     public void error(String format, Object arg1, Object arg2) {
 253  0
         if (task != null) {
 254  0
             final FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
 255  0
             task.log(tp.getMessage(), Project.MSG_ERR);
 256  
         }
 257  0
     }
 258  
 
 259  
     @Override
 260  
     public void error(String format, Object... arguments) {
 261  0
         if (task != null) {
 262  0
             final FormattingTuple tp = MessageFormatter.format(format, arguments);
 263  0
             task.log(tp.getMessage(), Project.MSG_ERR);
 264  
         }
 265  0
     }
 266  
 
 267  
     @Override
 268  
     public void error(String msg, Throwable t) {
 269  0
         if (task != null) {
 270  0
             task.log(msg, t, Project.MSG_ERR);
 271  
         }
 272  0
     }
 273  
 }