View Javadoc
1   package org.apache.maven.plugin.internal;
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.slf4j.Logger;
24  
25  import static java.util.Objects.requireNonNull;
26  
27  /**
28   * @author jdcasey
29   */
30  public class MojoLogWrapper
31      implements Log
32  {
33      private final Logger logger;
34  
35      public MojoLogWrapper( Logger logger )
36      {
37          this.logger = requireNonNull( logger );
38      }
39  
40      public void debug( CharSequence content )
41      {
42          logger.debug( toString( content ) );
43      }
44  
45      private String toString( CharSequence content )
46      {
47          if ( content == null )
48          {
49              return "";
50          }
51          else
52          {
53              return content.toString();
54          }
55      }
56  
57      @Override
58      public void debug( CharSequence content, Throwable error )
59      {
60          logger.debug( toString( content ), error );
61      }
62  
63      @Override
64      public void debug( Throwable error )
65      {
66          logger.debug( "", error );
67      }
68  
69      @Override
70      public void info( CharSequence content )
71      {
72          logger.info( toString( content ) );
73      }
74  
75      @Override
76      public void info( CharSequence content, Throwable error )
77      {
78          logger.info( toString( content ), error );
79      }
80  
81      @Override
82      public void info( Throwable error )
83      {
84          logger.info( "", error );
85      }
86  
87      @Override
88      public void warn( CharSequence content )
89      {
90          logger.warn( toString( content ) );
91      }
92  
93      @Override
94      public void warn( CharSequence content, Throwable error )
95      {
96          logger.warn( toString( content ), error );
97      }
98  
99      @Override
100     public void warn( Throwable error )
101     {
102         logger.warn( "", error );
103     }
104 
105     @Override
106     public void error( CharSequence content )
107     {
108         logger.error( toString( content ) );
109     }
110 
111     @Override
112     public void error( CharSequence content, Throwable error )
113     {
114         logger.error( toString( content ), error );
115     }
116 
117     @Override
118     public void error( Throwable error )
119     {
120         logger.error( "", error );
121     }
122 
123     @Override
124     public boolean isDebugEnabled()
125     {
126         return logger.isDebugEnabled();
127     }
128 
129     @Override
130     public boolean isInfoEnabled()
131     {
132         return logger.isInfoEnabled();
133     }
134 
135     @Override
136     public boolean isWarnEnabled()
137     {
138         return logger.isWarnEnabled();
139     }
140 
141     @Override
142     public boolean isErrorEnabled()
143     {
144         return logger.isErrorEnabled();
145     }
146 }