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 static final int DEBUG = 0; 030 static final int INFO = 1; 031 static final int WARN = 2; 032 static final int ERROR = 3; 033 034 private int level = INFO; 035 036 public void setLevel(int level) { 037 if (level < DEBUG || level > ERROR) { 038 throw new IllegalStateException("invalid level: " + level); 039 } 040 this.level = level; 041 } 042 043 private final PrintStream s; 044 045 StreamLog(PrintStream s) { 046 this.s = s; 047 } 048 049 public void debug(CharSequence content) { 050 if (isDebugEnabled()) { 051 s.println(content); 052 } 053 } 054 055 public void debug(CharSequence content, Throwable error) { 056 if (isDebugEnabled()) { 057 s.println(content); 058 } 059 } 060 061 public void debug(Throwable error) { 062 if (isDebugEnabled()) { 063 error.printStackTrace(s); 064 } 065 } 066 067 public void error(CharSequence content) { 068 if (isErrorEnabled()) { 069 s.println(content); 070 } 071 } 072 073 public void error(CharSequence content, Throwable error) { 074 error(content); 075 error(error); 076 } 077 078 public void error(Throwable error) { 079 if (isErrorEnabled()) { 080 error.printStackTrace(s); 081 } 082 } 083 084 public void info(CharSequence content) { 085 if (isInfoEnabled()) { 086 s.println(content); 087 } 088 } 089 090 public void info(CharSequence content, Throwable error) { 091 info(content); 092 info(error); 093 } 094 095 public void info(Throwable error) { 096 if (isInfoEnabled()) { 097 error.printStackTrace(s); 098 } 099 } 100 101 public boolean isDebugEnabled() { 102 return level >= DEBUG; 103 } 104 105 public boolean isErrorEnabled() { 106 return level >= ERROR; 107 } 108 109 public boolean isInfoEnabled() { 110 return level >= INFO; 111 } 112 113 public boolean isWarnEnabled() { 114 return level >= WARN; 115 } 116 117 public void warn(CharSequence content) { 118 if (isWarnEnabled()) { 119 s.println(content); 120 } 121 } 122 123 public void warn(CharSequence content, Throwable error) { 124 warn(content); 125 warn(error); 126 } 127 128 public void warn(Throwable error) { 129 if (isWarnEnabled()) { 130 error.printStackTrace(s); 131 } 132 } 133 }