View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.enforcer.internal;
20  
21  import java.util.Objects;
22  import java.util.function.Supplier;
23  
24  import org.apache.maven.enforcer.rule.api.EnforcerLogger;
25  import org.apache.maven.plugin.logging.Log;
26  
27  /**
28   * Base EnforcerLogger implementation
29   *
30   * @author Slawomir Jaranowski
31   * @since 3.2.0
32   */
33  public abstract class AbstractEnforcerLogger implements EnforcerLogger {
34  
35      protected final Log log;
36  
37      protected AbstractEnforcerLogger(Log log) {
38          this.log = Objects.requireNonNull(log, "log must be not null");
39      }
40  
41      @Override
42      public boolean isDebugEnabled() {
43          return log.isDebugEnabled();
44      }
45  
46      @Override
47      public void debug(CharSequence message) {
48          log.debug(message);
49      }
50  
51      @Override
52      public void debug(Supplier<CharSequence> messageSupplier) {
53          if (log.isDebugEnabled()) {
54              log.debug(messageSupplier.get());
55          }
56      }
57  
58      @Override
59      public boolean isInfoEnabled() {
60          return log.isInfoEnabled();
61      }
62  
63      @Override
64      public void info(CharSequence message) {
65          log.info(message);
66      }
67  
68      @Override
69      public void info(Supplier<CharSequence> messageSupplier) {
70          if (log.isInfoEnabled()) {
71              log.info(messageSupplier.get());
72          }
73      }
74  
75      @Override
76      public boolean isWarnEnabled() {
77          return log.isWarnEnabled();
78      }
79  
80      @Override
81      public void warn(CharSequence message) {
82          log.warn(message);
83      }
84  
85      @Override
86      public void warn(Supplier<CharSequence> messageSupplier) {
87          if (log.isWarnEnabled()) {
88              log.warn(messageSupplier.get());
89          }
90      }
91  
92      @Override
93      public boolean isErrorEnabled() {
94          return log.isErrorEnabled();
95      }
96  
97      @Override
98      public void error(CharSequence message) {
99          log.error(message);
100     }
101 
102     @Override
103     public void error(Supplier<CharSequence> messageSupplier) {
104         if (log.isErrorEnabled()) {
105             log.error(messageSupplier.get());
106         }
107     }
108 }