View Javadoc
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  
20  import org.apache.tools.ant.Task;
21  import org.owasp.dependencycheck.ant.logging.AntLoggerFactory;
22  import org.slf4j.ILoggerFactory;
23  import org.slf4j.spi.LoggerFactoryBinder;
24  
25  /**
26   * The binding of org.slf4j.LoggerFactory class with an actual instance of
27   * org.slf4j.ILoggerFactory is performed using information returned by this
28   * class.
29   *
30   * @author colezlaw
31   */
32  //CSOFF: FinalClass
33  @SuppressWarnings({"squid:S1444", "squid:ClassVariableVisibilityCheck"})
34  public class StaticLoggerBinder implements LoggerFactoryBinder {
35  //CSON: FinalClass
36  
37      /**
38       * The unique instance of this class
39       */
40      private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
41      /**
42       * Ant tasks have the log method we actually want to call. So we hang onto
43       * the task as a delegate
44       */
45      private Task task = null;
46  
47      /**
48       * Declare the version of the SLF4J API this implementation is compiled
49       * against. The value of this filed is usually modified with each release.
50       */
51      // to avoid constant folding by the compiler, this field must *not* be final
52      //CSOFF: StaticVariableName
53      //CSOFF: VisibilityModifier
54      @SuppressWarnings("squid:S3008")
55      public static String REQUESTED_API_VERSION = "1.7.12"; // final
56      //CSON: VisibilityModifier
57      //CSON: StaticVariableName
58  
59      /**
60       * The logger factory class string.
61       */
62      private static final String LOGGER_FACTORY_CLASS = AntLoggerFactory.class.getName();
63  
64      /**
65       * The ILoggerFactory instance returned by the {@link #getLoggerFactory}
66       * method should always be the smae object
67       */
68      private ILoggerFactory loggerFactory;
69  
70      /**
71       * Return the singleton of this class.
72       *
73       * @return the StaticLoggerBinder singleton
74       */
75      public static StaticLoggerBinder getSingleton() {
76          return SINGLETON;
77      }
78  
79      /**
80       * Set the Task which will this is to log through.
81       *
82       * @param task the task through which to log
83       */
84      public void setTask(Task task) {
85          this.task = task;
86          loggerFactory = new AntLoggerFactory(task);
87      }
88  
89      /**
90       * Constructs a new static logger binder.
91       */
92      private StaticLoggerBinder() {
93          loggerFactory = new AntLoggerFactory(task);
94      }
95  
96      /**
97       * Returns the logger factory.
98       *
99       * @return the logger factory
100      */
101     @Override
102     public ILoggerFactory getLoggerFactory() {
103         return loggerFactory;
104     }
105 
106     /**
107      * Returns the logger factory class string.
108      *
109      * @return the logger factory class string
110      */
111     @Override
112     public String getLoggerFactoryClassStr() {
113         return LOGGER_FACTORY_CLASS;
114     }
115 }