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.maven.plugin.logging.Log;
21  import org.owasp.dependencycheck.maven.slf4j.MavenLoggerFactory;
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  public class StaticLoggerBinder implements LoggerFactoryBinder {
34  //CSON: FinalClass
35  
36      /**
37       * The unique instance of this class
38       */
39      private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
40  
41      /**
42       * Return the singleton of this class.
43       *
44       * @return the StaticLoggerBinder singleton
45       */
46      public static final StaticLoggerBinder getSingleton() {
47          return SINGLETON;
48      }
49  
50      /**
51       * Maven mojos have their own logger, so we'll use one of those.
52       */
53      private Log log = null;
54  
55      /**
56       * Set the Task which will this is to log through.
57       *
58       * @param log the task through which to log
59       */
60      public void setLog(Log log) {
61          this.log = log;
62          loggerFactory = new MavenLoggerFactory(log);
63      }
64  
65      /**
66       * Declare the version of the SLF4J API this implementation is compiled
67       * against. The value of this filed is usually modified with each release.
68       */
69      // to avoid constant folding by the compiler, this field must *not* be final
70      //CSOFF: StaticVariableName
71      //CSOFF: VisibilityModifier
72      public static String REQUESTED_API_VERSION = "1.7.12"; // final
73      //CSON: VisibilityModifier
74      //CSON: StaticVariableName
75  
76      /**
77       * The logger factory class string.
78       */
79      private static final String LOGGER_FACTORY_CLASS = MavenLoggerFactory.class.getName();
80  
81      /**
82       * The ILoggerFactory instance returned by the {@link #getLoggerFactory}
83       * method should always be the same object
84       */
85      private ILoggerFactory loggerFactory;
86  
87      /**
88       * Constructs the static logger factory.
89       */
90      private StaticLoggerBinder() {
91          loggerFactory = new MavenLoggerFactory(log);
92      }
93  
94      /**
95       * Returns the logger factory.
96       *
97       * @return the logger factory
98       */
99      @Override
100     public ILoggerFactory getLoggerFactory() {
101         return loggerFactory;
102     }
103 
104     /**
105      * Returns the logger factory class string.
106      *
107      * @return the logger factory class string
108      */
109     @Override
110     public String getLoggerFactoryClassStr() {
111         return LOGGER_FACTORY_CLASS;
112     }
113 }