StaticLoggerBinder.java

  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.slf4j.impl;

  19. import org.apache.tools.ant.Task;
  20. import org.owasp.dependencycheck.ant.logging.AntLoggerFactory;
  21. import org.slf4j.ILoggerFactory;
  22. import org.slf4j.spi.LoggerFactoryBinder;

  23. /**
  24.  * The binding of org.slf4j.LoggerFactory class with an actual instance of
  25.  * org.slf4j.ILoggerFactory is performed using information returned by this
  26.  * class.
  27.  *
  28.  * @author colezlaw
  29.  */
  30. //CSOFF: FinalClass
  31. @SuppressWarnings({"squid:S1444", "squid:ClassVariableVisibilityCheck"})
  32. public class StaticLoggerBinder implements LoggerFactoryBinder {
  33. //CSON: FinalClass

  34.     /**
  35.      * The unique instance of this class
  36.      */
  37.     private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
  38.     /**
  39.      * Ant tasks have the log method we actually want to call. So we hang onto
  40.      * the task as a delegate
  41.      */
  42.     private Task task = null;

  43.     /**
  44.      * Declare the version of the SLF4J API this implementation is compiled
  45.      * against. The value of this filed is usually modified with each release.
  46.      */
  47.     // to avoid constant folding by the compiler, this field must *not* be final
  48.     //CSOFF: StaticVariableName
  49.     //CSOFF: VisibilityModifier
  50.     @SuppressWarnings("squid:S3008")
  51.     public static String REQUESTED_API_VERSION = "1.7.12"; // final
  52.     //CSON: VisibilityModifier
  53.     //CSON: StaticVariableName

  54.     /**
  55.      * The logger factory class string.
  56.      */
  57.     private static final String LOGGER_FACTORY_CLASS = AntLoggerFactory.class.getName();

  58.     /**
  59.      * The ILoggerFactory instance returned by the {@link #getLoggerFactory}
  60.      * method should always be the smae object
  61.      */
  62.     private ILoggerFactory loggerFactory;

  63.     /**
  64.      * Return the singleton of this class.
  65.      *
  66.      * @return the StaticLoggerBinder singleton
  67.      */
  68.     public static StaticLoggerBinder getSingleton() {
  69.         return SINGLETON;
  70.     }

  71.     /**
  72.      * Set the Task which will this is to log through.
  73.      *
  74.      * @param task the task through which to log
  75.      */
  76.     public void setTask(Task task) {
  77.         this.task = task;
  78.         loggerFactory = new AntLoggerFactory(task);
  79.     }

  80.     /**
  81.      * Constructs a new static logger binder.
  82.      */
  83.     private StaticLoggerBinder() {
  84.         loggerFactory = new AntLoggerFactory(task);
  85.     }

  86.     /**
  87.      * Returns the logger factory.
  88.      *
  89.      * @return the logger factory
  90.      */
  91.     @Override
  92.     public ILoggerFactory getLoggerFactory() {
  93.         return loggerFactory;
  94.     }

  95.     /**
  96.      * Returns the logger factory class string.
  97.      *
  98.      * @return the logger factory class string
  99.      */
  100.     @Override
  101.     public String getLoggerFactoryClassStr() {
  102.         return LOGGER_FACTORY_CLASS;
  103.     }
  104. }