View Javadoc
1   package com.simpligility.maven.plugins.android.phase01generatesources;
2   
3   import com.android.annotations.NonNull;
4   import com.android.annotations.Nullable;
5   import com.android.utils.ILogger;
6   import org.apache.maven.plugin.logging.Log;
7   
8   import java.util.Formatter;
9   
10  /**
11   * Adapter from the Android Utils ILogger interface to the Maven plugins log.
12   */
13  public class MavenILogger implements ILogger
14  {
15      private final Log log;
16      private final boolean verboseInfo;
17  
18      public MavenILogger( Log log, boolean verboseInfo )
19      {
20          this.log = log;
21          this.verboseInfo = verboseInfo;
22      }
23  
24      public MavenILogger( Log log )
25      {
26          this.log = log;
27          this.verboseInfo = false;
28      }
29  
30      @Override
31      public void error( @Nullable Throwable throwable, @Nullable String s, Object... objects )
32      {
33          if ( ( throwable != null ) && ( s != null ) )
34          {
35              final Formatter formatter = new Formatter();
36              log.error( formatter.format( s, objects ).out().toString(), throwable );
37          }
38          else if ( ( throwable == null ) && ( s == null ) )
39          {
40              // do nothing.
41          }
42          else if ( throwable != null )
43          {
44              log.error( throwable );
45          }
46          else
47          {
48              final Formatter formatter = new Formatter();
49              log.error( formatter.format( s, objects ).out().toString() );
50          }
51      }
52  
53      @Override
54      public void warning( @NonNull String s, Object... objects )
55      {
56          final Formatter formatter = new Formatter();
57          log.warn( formatter.format( s, objects ).out().toString() );
58      }
59  
60      @Override
61      public void info( @NonNull String s, Object... objects )
62      {
63          final Formatter formatter = new Formatter();
64          if ( verboseInfo )
65          {
66              log.debug( formatter.format( s, objects ).out().toString() );
67          }
68          else
69          {
70              log.info( formatter.format( s, objects ).out().toString() );
71          }
72          
73      }
74  
75      @Override
76      public void verbose( @NonNull String s, Object... objects )
77      {
78          final Formatter formatter = new Formatter();
79          log.debug( formatter.format( s, objects ).out().toString() );
80      }
81  }