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.plugin.testing;
20  
21  import org.apache.maven.plugin.logging.Log;
22  import org.slf4j.Logger;
23  
24  import static java.util.Objects.requireNonNull;
25  
26  /**
27   * @author jdcasey
28   *
29   * @deprecated As of version 3.4.0, it is advised to work with JUnit5 tests which do not
30   * use this class but {@link  javax.inject.Inject} to inject a Log instance
31   * instead.
32   *
33   */
34  @Deprecated
35  public class MojoLogWrapper implements Log {
36      private final Logger logger;
37  
38      public MojoLogWrapper(Logger logger) {
39          this.logger = requireNonNull(logger);
40      }
41  
42      public void debug(CharSequence content) {
43          logger.debug(toString(content));
44      }
45  
46      private String toString(CharSequence content) {
47          if (content == null) {
48              return "";
49          } else {
50              return content.toString();
51          }
52      }
53  
54      @Override
55      public void debug(CharSequence content, Throwable error) {
56          logger.debug(toString(content), error);
57      }
58  
59      @Override
60      public void debug(Throwable error) {
61          logger.debug("", error);
62      }
63  
64      @Override
65      public void info(CharSequence content) {
66          logger.info(toString(content));
67      }
68  
69      @Override
70      public void info(CharSequence content, Throwable error) {
71          logger.info(toString(content), error);
72      }
73  
74      @Override
75      public void info(Throwable error) {
76          logger.info("", error);
77      }
78  
79      @Override
80      public void warn(CharSequence content) {
81          logger.warn(toString(content));
82      }
83  
84      @Override
85      public void warn(CharSequence content, Throwable error) {
86          logger.warn(toString(content), error);
87      }
88  
89      @Override
90      public void warn(Throwable error) {
91          logger.warn("", error);
92      }
93  
94      @Override
95      public void error(CharSequence content) {
96          logger.error(toString(content));
97      }
98  
99      @Override
100     public void error(CharSequence content, Throwable error) {
101         logger.error(toString(content), error);
102     }
103 
104     @Override
105     public void error(Throwable error) {
106         logger.error("", error);
107     }
108 
109     @Override
110     public boolean isDebugEnabled() {
111         return logger.isDebugEnabled();
112     }
113 
114     @Override
115     public boolean isInfoEnabled() {
116         return logger.isInfoEnabled();
117     }
118 
119     @Override
120     public boolean isWarnEnabled() {
121         return logger.isWarnEnabled();
122     }
123 
124     @Override
125     public boolean isErrorEnabled() {
126         return logger.isErrorEnabled();
127     }
128 }