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.surefire.report;
20  
21  import org.apache.maven.plugin.logging.Log;
22  import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
23  import org.apache.maven.shared.utils.logging.MessageBuilder;
24  
25  import static java.lang.Integer.numberOfLeadingZeros;
26  import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
27  
28  /**
29   * Wrapper logger of miscellaneous implementations of {@link Log}.
30   *
31   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
32   * @since 2.20
33   * @see ConsoleLogger
34   */
35  final class PluginConsoleLogger implements ConsoleLogger {
36      private final Log mojoLogger;
37  
38      PluginConsoleLogger(Log mojoLogger) {
39          this.mojoLogger = mojoLogger;
40      }
41  
42      @Override
43      public boolean isDebugEnabled() {
44          return mojoLogger.isDebugEnabled();
45      }
46  
47      @Override
48      public void debug(String message) {
49          mojoLogger.debug(createAnsiBuilder(message).a(message).toString());
50      }
51  
52      public void debug(CharSequence content, Throwable error) {
53          mojoLogger.debug(content, error);
54      }
55  
56      @Override
57      public boolean isInfoEnabled() {
58          return mojoLogger.isInfoEnabled();
59      }
60  
61      @Override
62      public void info(String message) {
63          mojoLogger.info(createAnsiBuilder(message).a(message).toString());
64      }
65  
66      @Override
67      public boolean isWarnEnabled() {
68          return mojoLogger.isWarnEnabled();
69      }
70  
71      @Override
72      public void warning(String message) {
73          mojoLogger.warn(createAnsiBuilder(message).warning(message).toString());
74      }
75  
76      public void warn(CharSequence content, Throwable error) {
77          mojoLogger.warn(content, error);
78      }
79  
80      @Override
81      public boolean isErrorEnabled() {
82          return mojoLogger.isErrorEnabled();
83      }
84  
85      @Override
86      public void error(String message) {
87          mojoLogger.error(createAnsiBuilder(message).failure(message).toString());
88      }
89  
90      @Override
91      public void error(String message, Throwable t) {
92          mojoLogger.error(message, t);
93      }
94  
95      @Override
96      public void error(Throwable t) {
97          mojoLogger.error(t);
98      }
99  
100     private static MessageBuilder createAnsiBuilder(CharSequence message) {
101         return buffer(bufferSize(message));
102     }
103 
104     private static int bufferSize(CharSequence message) {
105         return 32 - numberOfLeadingZeros(message.length());
106     }
107 }