Coverage Report - org.owasp.dependencycheck.ant.logging.AntLoggerAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
AntLoggerAdapter
37%
37/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
 28  
  * the delegate Ant task.
 29  
  *
 30  
  * @author colezlaw
 31  
  */
 32  
 public class AntLoggerAdapter extends MarkerIgnoringBase {
 33  
 
 34  
     /**
 35  
      * serialization UID.
 36  
      */
 37  
     private static final long serialVersionUID = -1337;
 38  
     /**
 39  
      * A reference to the Ant task used for logging.
 40  
      */
 41  
     private transient Task task;
 42  
 
 43  
     /**
 44  
      * Constructs an Ant Logger Adapter.
 45  
      *
 46  
      * @param task the Ant Task to use for logging
 47  
      */
 48  
     public AntLoggerAdapter(Task task) {
 49  13
         super();
 50  13
         this.task = task;
 51  13
     }
 52  
 
 53  
     /**
 54  
      * Sets the current Ant task to use for logging.
 55  
      *
 56  
      * @param task the Ant task to use for logging
 57  
      */
 58  
     public void setTask(Task task) {
 59  0
         this.task = task;
 60  0
     }
 61  
 
 62  
     @Override
 63  
     public boolean isTraceEnabled() {
 64  
         // Might be a more efficient way to do this, but Ant doesn't enable or disable
 65  
         // various levels globally - it just fires things at registered Listeners.
 66  0
         return true;
 67  
     }
 68  
 
 69  
     @Override
 70  
     public void trace(String msg) {
 71  32
         if (task != null) {
 72  27
             task.log(msg, Project.MSG_VERBOSE);
 73  
         }
 74  32
     }
 75  
 
 76  
     @Override
 77  
     public void trace(String format, Object arg) {
 78  29
         if (task != null) {
 79  21
             final FormattingTuple tp = MessageFormatter.format(format, arg);
 80  21
             task.log(tp.getMessage(), Project.MSG_VERBOSE);
 81  
         }
 82  29
     }
 83  
 
 84  
     @Override
 85  
     public void trace(String format, Object arg1, Object arg2) {
 86  0
         if (task != null) {
 87  0
             final FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
 88  0
             task.log(tp.getMessage(), Project.MSG_VERBOSE);
 89  
         }
 90  0
     }
 91  
 
 92  
     @Override
 93  
     public void trace(String format, Object... arguments) {
 94  0
         if (task != null) {
 95  0
             final FormattingTuple tp = MessageFormatter.format(format, arguments);
 96  0
             task.log(tp.getMessage(), Project.MSG_VERBOSE);
 97  
         }
 98  0
     }
 99  
 
 100  
     @Override
 101  
     public void trace(String msg, Throwable t) {
 102  0
         if (task != null) {
 103  0
             task.log(msg, t, Project.MSG_VERBOSE);
 104  
         }
 105  0
     }
 106  
 
 107  
     @Override
 108  
     public boolean isDebugEnabled() {
 109  92
         return true;
 110  
     }
 111  
 
 112  
     @Override
 113  
     public void debug(String msg) {
 114  269
         if (task != null) {
 115  174
             task.log(msg, Project.MSG_DEBUG);
 116  
         }
 117  269
     }
 118  
 
 119  
     @Override
 120  
     public void debug(String format, Object arg) {
 121  281
         if (task != null) {
 122  268
             final FormattingTuple tp = MessageFormatter.format(format, arg);
 123  268
             task.log(tp.getMessage(), Project.MSG_DEBUG);
 124  
         }
 125  281
     }
 126  
 
 127  
     @Override
 128  
     public void debug(String format, Object arg1, Object arg2) {
 129  119
         if (task != null) {
 130  112
             final FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
 131  112
             task.log(tp.getMessage(), Project.MSG_DEBUG);
 132  
         }
 133  118
     }
 134  
 
 135  
     @Override
 136  
     public void debug(String format, Object... arguments) {
 137  2
         if (task != null) {
 138  2
             final FormattingTuple tp = MessageFormatter.format(format, arguments);
 139  2
             task.log(tp.getMessage(), Project.MSG_DEBUG);
 140  
         }
 141  2
     }
 142  
 
 143  
     @Override
 144  
     public void debug(String msg, Throwable t) {
 145  0
         if (task != null) {
 146  0
             task.log(msg, t, Project.MSG_DEBUG);
 147  
         }
 148  0
     }
 149  
 
 150  
     @Override
 151  
     public boolean isInfoEnabled() {
 152  0
         return true;
 153  
     }
 154  
 
 155  
     @Override
 156  
     public void info(String msg) {
 157  3
         if (task != null) {
 158  3
             task.log(msg, Project.MSG_INFO);
 159  
         }
 160  3
     }
 161  
 
 162  
     @Override
 163  
     public void info(String format, Object arg) {
 164  6
         if (task != null) {
 165  6
             final FormattingTuple tp = MessageFormatter.format(format, arg);
 166  6
             task.log(tp.getMessage(), Project.MSG_INFO);
 167  
         }
 168  6
     }
 169  
 
 170  
     @Override
 171  
     public void info(String format, Object arg1, Object arg2) {
 172  45
         if (task != null) {
 173  45
             final FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
 174  45
             task.log(tp.getMessage(), Project.MSG_INFO);
 175  
         }
 176  45
     }
 177  
 
 178  
     @Override
 179  
     public void info(String format, Object... arguments) {
 180  0
         if (task != null) {
 181  0
             final FormattingTuple tp = MessageFormatter.format(format, arguments);
 182  0
             task.log(tp.getMessage(), Project.MSG_INFO);
 183  
         }
 184  0
     }
 185  
 
 186  
     @Override
 187  
     public void info(String msg, Throwable t) {
 188  0
         if (task != null) {
 189  0
             task.log(msg, t, Project.MSG_INFO);
 190  
         }
 191  0
     }
 192  
 
 193  
     @Override
 194  
     public boolean isWarnEnabled() {
 195  0
         return true;
 196  
     }
 197  
 
 198  
     @Override
 199  
     public void warn(String msg) {
 200  0
         if (task != null) {
 201  0
             task.log(msg, Project.MSG_WARN);
 202  
         }
 203  0
     }
 204  
 
 205  
     @Override
 206  
     public void warn(String format, Object arg) {
 207  0
         if (task != null) {
 208  0
             final FormattingTuple tp = MessageFormatter.format(format, arg);
 209  0
             task.log(tp.getMessage(), Project.MSG_WARN);
 210  
         }
 211  0
     }
 212  
 
 213  
     @Override
 214  
     public void warn(String format, Object... arguments) {
 215  0
         if (task != null) {
 216  0
             final FormattingTuple tp = MessageFormatter.format(format, arguments);
 217  0
             task.log(tp.getMessage(), Project.MSG_WARN);
 218  
         }
 219  0
     }
 220  
 
 221  
     @Override
 222  
     public void warn(String format, Object arg1, Object arg2) {
 223  0
         if (task != null) {
 224  0
             final FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
 225  0
             task.log(tp.getMessage(), Project.MSG_WARN);
 226  
         }
 227  0
     }
 228  
 
 229  
     @Override
 230  
     public void warn(String msg, Throwable t) {
 231  0
         if (task != null) {
 232  0
             task.log(msg, t, Project.MSG_WARN);
 233  
         }
 234  0
     }
 235  
 
 236  
     @Override
 237  
     public boolean isErrorEnabled() {
 238  0
         return true;
 239  
     }
 240  
 
 241  
     @Override
 242  
     public void error(String msg) {
 243  0
         if (task != null) {
 244  0
             task.log(msg, Project.MSG_ERR);
 245  
         }
 246  0
     }
 247  
 
 248  
     @Override
 249  
     public void error(String format, Object arg) {
 250  0
         if (task != null) {
 251  0
             final FormattingTuple tp = MessageFormatter.format(format, arg);
 252  0
             task.log(tp.getMessage(), Project.MSG_ERR);
 253  
         }
 254  0
     }
 255  
 
 256  
     @Override
 257  
     public void error(String format, Object arg1, Object arg2) {
 258  0
         if (task != null) {
 259  0
             final FormattingTuple tp = MessageFormatter.format(format, arg1, arg2);
 260  0
             task.log(tp.getMessage(), Project.MSG_ERR);
 261  
         }
 262  0
     }
 263  
 
 264  
     @Override
 265  
     public void error(String format, Object... arguments) {
 266  0
         if (task != null) {
 267  0
             final FormattingTuple tp = MessageFormatter.format(format, arguments);
 268  0
             task.log(tp.getMessage(), Project.MSG_ERR);
 269  
         }
 270  0
     }
 271  
 
 272  
     @Override
 273  
     public void error(String msg, Throwable t) {
 274  0
         if (task != null) {
 275  0
             task.log(msg, t, Project.MSG_ERR);
 276  
         }
 277  0
     }
 278  
 }