View Javadoc
1   package org.apache.maven.plugin.surefire.log;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.plugin.logging.Log;
23  import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
24  
25  /**
26   * Wrapper logger of miscellaneous (Maven 2.2.1 or 3.1) implementations of {@link Log}.
27   * Calling {@link Log#isInfoEnabled()} before {@link Log#info(CharSequence)} due to Maven 2.2.1.
28   *
29   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
30   * @since 2.20
31   * @see ConsoleLogger
32   */
33  public final class PluginConsoleLogger
34      implements ConsoleLogger
35  {
36      private final Log mojoLogger;
37  
38      public PluginConsoleLogger( Log mojoLogger )
39      {
40          this.mojoLogger = mojoLogger;
41      }
42  
43      public boolean isDebugEnabled()
44      {
45          return mojoLogger.isDebugEnabled();
46      }
47  
48      public void debug( String message )
49      {
50          if ( mojoLogger.isDebugEnabled() )
51          {
52              mojoLogger.debug( message );
53          }
54      }
55  
56      public void debug( CharSequence content, Throwable error )
57      {
58          if ( mojoLogger.isDebugEnabled() )
59          {
60              mojoLogger.debug( content, error );
61          }
62      }
63  
64      public boolean isInfoEnabled()
65      {
66          return mojoLogger.isInfoEnabled();
67      }
68  
69      public void info( String message )
70      {
71          if ( mojoLogger.isInfoEnabled() )
72          {
73              mojoLogger.info( message );
74          }
75      }
76  
77      public boolean isWarnEnabled()
78      {
79          return mojoLogger.isWarnEnabled();
80      }
81  
82      public void warning( String message )
83      {
84          if ( mojoLogger.isWarnEnabled() )
85          {
86              mojoLogger.warn( message );
87          }
88      }
89  
90      public void warning( CharSequence content, Throwable error )
91      {
92          if ( mojoLogger.isWarnEnabled() )
93          {
94              mojoLogger.warn( content, error );
95          }
96      }
97  
98      public boolean isErrorEnabled()
99      {
100         return mojoLogger.isErrorEnabled();
101     }
102 
103     public void error( String message )
104     {
105         if ( mojoLogger.isErrorEnabled() )
106         {
107             mojoLogger.error( message );
108         }
109     }
110 
111     public void error( String message, Throwable t )
112     {
113         if ( mojoLogger.isErrorEnabled() )
114         {
115             mojoLogger.error( message, t );
116         }
117     }
118 
119     public void error( Throwable t )
120     {
121         if ( mojoLogger.isErrorEnabled() )
122         {
123             mojoLogger.error( t );
124         }
125     }
126 }