View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.geronimo.genesis.logging;
21  
22  import org.apache.maven.plugin.Mojo;
23  import org.apache.commons.logging.Log;
24  
25  /**
26   * Bridge from the Maven plugin Log to a JCL Log.
27   *
28   * @version $Rev: 470159 $ $Date: 2006-11-01 17:19:16 -0800 (Wed, 01 Nov 2006) $
29   */
30  public class MavenPluginLog
31      implements Log
32  {
33      private static Mojo mojo;
34  
35      public static void setMojo(final Mojo mojo) {
36          assert mojo != null;
37  
38          MavenPluginLog.mojo = mojo;
39      }
40  
41      private String name;
42  
43      public MavenPluginLog(final String name) {
44          assert name != null;
45  
46          this.name = name;
47      }
48  
49      private org.apache.maven.plugin.logging.Log getLog() {
50          if (mojo == null) {
51              throw new RuntimeException("Mojo not set; can not delegate logging");
52          }
53  
54          return mojo.getLog();
55      }
56  
57      public boolean isDebugEnabled() {
58          return getLog().isDebugEnabled();
59      }
60  
61      public boolean isErrorEnabled() {
62          return getLog().isErrorEnabled();
63      }
64  
65      public boolean isFatalEnabled() {
66          return getLog().isErrorEnabled();
67      }
68  
69      public boolean isInfoEnabled() {
70          return getLog().isInfoEnabled();
71      }
72  
73      public boolean isTraceEnabled() {
74          // return getLog().isDebugEnabled();
75          return false;
76      }
77  
78      public boolean isWarnEnabled() {
79          return getLog().isWarnEnabled();
80      }
81  
82      private String createMessage(final Object object) {
83          if (isDebugEnabled()) {
84              return "(" + name + ") " + object;
85          }
86          else {
87              return String.valueOf(object);
88          }
89      }
90  
91      public void trace(final Object object) {
92          if (isTraceEnabled()) {
93              debug(object);
94          }
95      }
96  
97      public void trace(final Object object, final Throwable throwable) {
98          if (isTraceEnabled()) {
99              debug(object, throwable);
100         }
101     }
102 
103     public void debug(final Object object) {
104         getLog().debug(createMessage(object));
105     }
106 
107     public void debug(final Object object, final Throwable throwable) {
108         getLog().debug(createMessage(object), throwable);
109     }
110 
111     public void info(final Object object) {
112         getLog().info(createMessage(object));
113     }
114 
115     public void info(final Object object, final Throwable throwable) {
116         getLog().info(createMessage(object), throwable);
117     }
118 
119     public void warn(final Object object) {
120         getLog().warn(createMessage(object));
121     }
122 
123     public void warn(final Object object, final Throwable throwable) {
124         getLog().warn(createMessage(object), throwable);
125     }
126 
127     public void error(final Object object) {
128         getLog().error(createMessage(object));
129     }
130 
131     public void error(final Object object, final Throwable throwable) {
132         getLog().error(createMessage(object), throwable);
133     }
134 
135     public void fatal(final Object object) {
136         error(object);
137     }
138 
139     public void fatal(final Object object, final Throwable throwable) {
140         error(object, throwable);
141     }
142 }