001 package org.codehaus.mojo.exec; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 import java.io.PrintStream; 023 import org.apache.maven.plugin.logging.Log; 024 025 /** 026 * a Simple Maven Log that outputs to a Stream 027 */ 028 class StreamLog implements Log 029 { 030 static final int DEBUG = 0; 031 static final int INFO = 1; 032 static final int WARN = 2; 033 static final int ERROR = 3; 034 035 private int level = INFO; 036 037 public void setLevel( int level ) 038 { 039 if ( level < DEBUG || level > ERROR ) 040 { 041 throw new IllegalStateException( "invalid level: " + level ); 042 } 043 this.level = level; 044 } 045 046 private final PrintStream s; 047 048 StreamLog( PrintStream s ) 049 { 050 this.s = s; 051 } 052 053 public void debug( CharSequence content ) 054 { 055 if ( isDebugEnabled() ) 056 { 057 s.println( content ); 058 } 059 } 060 061 public void debug( CharSequence content, Throwable error ) 062 { 063 if ( isDebugEnabled() ) 064 { 065 s.println( content ); 066 } 067 } 068 069 public void debug( Throwable error ) 070 { 071 if ( isDebugEnabled() ) 072 { 073 error.printStackTrace( s ); 074 } 075 } 076 077 public void error( CharSequence content ) 078 { 079 if ( isErrorEnabled() ) 080 { 081 s.println( content ); 082 } 083 } 084 085 public void error( CharSequence content, Throwable error ) 086 { 087 error( content ); 088 error( error ); 089 } 090 091 public void error( Throwable error ) 092 { 093 if ( isErrorEnabled() ) 094 { 095 error.printStackTrace( s ); 096 } 097 } 098 099 public void info( CharSequence content ) 100 { 101 if ( isInfoEnabled() ) 102 { 103 s.println( content ); 104 } 105 } 106 107 public void info( CharSequence content, Throwable error ) 108 { 109 info( content ); 110 info( error ); 111 } 112 113 public void info( Throwable error ) 114 { 115 if ( isInfoEnabled() ) 116 { 117 error.printStackTrace( s ); 118 } 119 } 120 121 public boolean isDebugEnabled() 122 { 123 return level >= DEBUG; 124 } 125 126 public boolean isErrorEnabled() 127 { 128 return level >= ERROR; 129 } 130 131 public boolean isInfoEnabled() 132 { 133 return level >= INFO; 134 } 135 136 public boolean isWarnEnabled() 137 { 138 return level >= WARN; 139 } 140 141 public void warn( CharSequence content ) 142 { 143 if ( isWarnEnabled() ) 144 { 145 s.println( content ); 146 } 147 } 148 149 public void warn( CharSequence content, Throwable error ) 150 { 151 warn( content ); 152 warn( error ); 153 } 154 155 public void warn( Throwable error ) 156 { 157 if ( isWarnEnabled() ) 158 { 159 error.printStackTrace( s ); 160 } 161 } 162 }