View Javadoc
1   package org.apache.maven.doxia.tools;
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.doxia.logging.Log;
23  
24  /**
25   * Wrap a Mojo logger into a Doxia logger.
26   *
27   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
28   * @version $Id: MojoLogWrapper.html 1018749 2017-09-26 18:39:07Z rfscholte $
29   * @since 1.1
30   * @see org.apache.maven.plugin.logging.Log
31   */
32  public class MojoLogWrapper
33      implements Log
34  {
35      private final org.apache.maven.plugin.logging.Log mojoLog;
36  
37      /**
38       * @param log a Mojo log
39       */
40      public MojoLogWrapper( org.apache.maven.plugin.logging.Log log )
41      {
42          this.mojoLog = log;
43      }
44  
45      /** {@inheritDoc} */
46      public void setLogLevel( int level )
47      {
48          // nop
49      }
50  
51      /** {@inheritDoc} */
52      public void debug( CharSequence content )
53      {
54          mojoLog.debug( toString( content ) );
55      }
56  
57      /** {@inheritDoc} */
58      public void debug( CharSequence content, Throwable error )
59      {
60          mojoLog.debug( toString( content ), error );
61      }
62  
63      /** {@inheritDoc} */
64      public void debug( Throwable error )
65      {
66          mojoLog.debug( "", error );
67      }
68  
69      /** {@inheritDoc} */
70      public void info( CharSequence content )
71      {
72          mojoLog.info( toString( content ) );
73      }
74  
75      /** {@inheritDoc} */
76      public void info( CharSequence content, Throwable error )
77      {
78          mojoLog.info( toString( content ), error );
79      }
80  
81      /** {@inheritDoc} */
82      public void info( Throwable error )
83      {
84          mojoLog.info( "", error );
85      }
86  
87      /** {@inheritDoc} */
88      public void warn( CharSequence content )
89      {
90          mojoLog.warn( toString( content ) );
91      }
92  
93      /** {@inheritDoc} */
94      public void warn( CharSequence content, Throwable error )
95      {
96          mojoLog.warn( toString( content ), error );
97      }
98  
99      /** {@inheritDoc} */
100     public void warn( Throwable error )
101     {
102         mojoLog.warn( "", error );
103     }
104 
105     /** {@inheritDoc} */
106     public void error( CharSequence content )
107     {
108         mojoLog.error( toString( content ) );
109     }
110 
111     /** {@inheritDoc} */
112     public void error( CharSequence content, Throwable error )
113     {
114         mojoLog.error( toString( content ), error );
115     }
116 
117     /** {@inheritDoc} */
118     public void error( Throwable error )
119     {
120         mojoLog.error( "", error );
121     }
122 
123     /** {@inheritDoc} */
124     public boolean isDebugEnabled()
125     {
126         return mojoLog.isDebugEnabled();
127     }
128 
129     /** {@inheritDoc} */
130     public boolean isInfoEnabled()
131     {
132         return mojoLog.isInfoEnabled();
133     }
134 
135     /** {@inheritDoc} */
136     public boolean isWarnEnabled()
137     {
138         return mojoLog.isWarnEnabled();
139     }
140 
141     /** {@inheritDoc} */
142     public boolean isErrorEnabled()
143     {
144         return mojoLog.isErrorEnabled();
145     }
146 
147     // ----------------------------------------------------------------------
148     // Private methods
149     // ----------------------------------------------------------------------
150 
151     private String toString( CharSequence content )
152     {
153         if ( content == null )
154         {
155             return "";
156         }
157 
158         return content.toString();
159     }
160 }