View Javadoc
1   package org.codehaus.mojo.clirr;
2   
3   /*
4    * Copyright 2006 The Codehaus
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import net.sf.clirr.core.ApiDifference;
20  import net.sf.clirr.core.DiffListenerAdapter;
21  import net.sf.clirr.core.MessageTranslator;
22  import net.sf.clirr.core.Severity;
23  import org.apache.maven.plugin.logging.Log;
24  
25  /**
26   * Log messages to the console as they are processed.
27   *
28   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
29   */
30  public class LogDiffListener
31      extends DiffListenerAdapter
32  {
33      private final Log log;
34  
35      private final MessageTranslator messageTranslator;
36  
37      public LogDiffListener( Log log )
38      {
39          this.log = log;
40  
41          this.messageTranslator = new MessageTranslator();
42      }
43  
44      public void reportDiff( ApiDifference apiDifference )
45      {
46          String message = apiDifference.getMessage().getId() + ": " + apiDifference.getAffectedClass() + ": " +
47              apiDifference.getReport( messageTranslator );
48  
49          Severity severity = apiDifference.getMaximumSeverity();
50          if ( severity.equals( Severity.INFO ) )
51          {
52              log.info( message );
53          }
54          else if ( severity.equals( Severity.WARNING ) )
55          {
56              log.warn( message );
57          }
58          else if ( severity.equals( Severity.ERROR ) )
59          {
60              log.error( message );
61          }
62      }
63  }