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