001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 package org.apache.geronimo.genesis.logging; 021 022 import org.apache.maven.plugin.Mojo; 023 import org.apache.commons.logging.Log; 024 025 /** 026 * Bridge from the Maven plugin Log to a JCL Log. 027 * 028 * @version $Rev: 470159 $ $Date: 2006-11-01 17:19:16 -0800 (Wed, 01 Nov 2006) $ 029 */ 030 public class MavenPluginLog 031 implements Log 032 { 033 private static Mojo mojo; 034 035 public static void setMojo(final Mojo mojo) { 036 assert mojo != null; 037 038 MavenPluginLog.mojo = mojo; 039 } 040 041 private String name; 042 043 public MavenPluginLog(final String name) { 044 assert name != null; 045 046 this.name = name; 047 } 048 049 private org.apache.maven.plugin.logging.Log getLog() { 050 if (mojo == null) { 051 throw new RuntimeException("Mojo not set; can not delegate logging"); 052 } 053 054 return mojo.getLog(); 055 } 056 057 public boolean isDebugEnabled() { 058 return getLog().isDebugEnabled(); 059 } 060 061 public boolean isErrorEnabled() { 062 return getLog().isErrorEnabled(); 063 } 064 065 public boolean isFatalEnabled() { 066 return getLog().isErrorEnabled(); 067 } 068 069 public boolean isInfoEnabled() { 070 return getLog().isInfoEnabled(); 071 } 072 073 public boolean isTraceEnabled() { 074 // return getLog().isDebugEnabled(); 075 return false; 076 } 077 078 public boolean isWarnEnabled() { 079 return getLog().isWarnEnabled(); 080 } 081 082 private String createMessage(final Object object) { 083 if (isDebugEnabled()) { 084 return "(" + name + ") " + object; 085 } 086 else { 087 return String.valueOf(object); 088 } 089 } 090 091 public void trace(final Object object) { 092 if (isTraceEnabled()) { 093 debug(object); 094 } 095 } 096 097 public void trace(final Object object, final Throwable throwable) { 098 if (isTraceEnabled()) { 099 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 }