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      @Override
49      public void debug( String message )
50      {
51          if ( mojoLogger.isDebugEnabled() )
52          {
53              mojoLogger.debug( message );
54          }
55      }
56  
57      public void debug( CharSequence content, Throwable error )
58      {
59          if ( mojoLogger.isDebugEnabled() )
60          {
61              mojoLogger.debug( content, error );
62          }
63      }
64  
65      public boolean isInfoEnabled()
66      {
67          return mojoLogger.isInfoEnabled();
68      }
69  
70      @Override
71      public void info( String message )
72      {
73          if ( mojoLogger.isInfoEnabled() )
74          {
75              mojoLogger.info( message );
76          }
77      }
78  
79      public boolean isWarnEnabled()
80      {
81          return mojoLogger.isWarnEnabled();
82      }
83  
84      @Override
85      public void warning( String message )
86      {
87          if ( mojoLogger.isWarnEnabled() )
88          {
89              mojoLogger.warn( message );
90          }
91      }
92  
93      public void warning( CharSequence content, Throwable error )
94      {
95          if ( mojoLogger.isWarnEnabled() )
96          {
97              mojoLogger.warn( content, error );
98          }
99      }
100 
101     public boolean isErrorEnabled()
102     {
103         return mojoLogger.isErrorEnabled();
104     }
105 
106     @Override
107     public void error( String message )
108     {
109         if ( mojoLogger.isErrorEnabled() )
110         {
111             mojoLogger.error( message );
112         }
113     }
114 
115     @Override
116     public void error( String message, Throwable t )
117     {
118         if ( mojoLogger.isErrorEnabled() )
119         {
120             mojoLogger.error( message, t );
121         }
122     }
123 
124     @Override
125     public void error( Throwable t )
126     {
127         if ( mojoLogger.isErrorEnabled() )
128         {
129             mojoLogger.error( t );
130         }
131     }
132 }