Coverage Report - org.codehaus.mojo.exec.StreamLog
 
Classes in this File Line Coverage Branch Coverage Complexity
StreamLog
0%
0/48
0%
0/30
1.667
 
 1  
 package org.codehaus.mojo.exec;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *     http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.PrintStream;
 23  
 import org.apache.maven.plugin.logging.Log;
 24  
 
 25  
 /**
 26  
  * a Simple Maven Log that outputs to a Stream
 27  
  */
 28  
 class StreamLog implements Log {
 29  
     static final int DEBUG = 0;
 30  
     static final int INFO = 1;
 31  
     static final int WARN = 2;
 32  
     static final int ERROR = 3;
 33  
 
 34  0
     private int level = INFO;
 35  
 
 36  
     public void setLevel(int level) {
 37  0
         if (level < DEBUG || level > ERROR) {
 38  0
             throw new IllegalStateException("invalid level: " + level);
 39  
         }
 40  0
         this.level = level;
 41  0
     }
 42  
 
 43  
     private final PrintStream s;
 44  
 
 45  0
     StreamLog(PrintStream s) {
 46  0
         this.s = s;
 47  0
     }
 48  
 
 49  
     public void debug(CharSequence content) {
 50  0
         if (isDebugEnabled()) {
 51  0
             s.println(content);
 52  
         }
 53  0
     }
 54  
 
 55  
     public void debug(CharSequence content, Throwable error) {
 56  0
         if (isDebugEnabled()) {
 57  0
             s.println(content);
 58  
         }
 59  0
     }
 60  
 
 61  
     public void debug(Throwable error) {
 62  0
         if (isDebugEnabled()) {
 63  0
             error.printStackTrace(s);
 64  
         }
 65  0
     }
 66  
 
 67  
     public void error(CharSequence content) {
 68  0
         if (isErrorEnabled()) {
 69  0
             s.println(content);
 70  
         }
 71  0
     }
 72  
 
 73  
     public void error(CharSequence content, Throwable error) {
 74  0
         error(content);
 75  0
         error(error);
 76  0
     }
 77  
 
 78  
     public void error(Throwable error) {
 79  0
         if (isErrorEnabled()) {
 80  0
             error.printStackTrace(s);
 81  
         }
 82  0
     }
 83  
 
 84  
     public void info(CharSequence content) {
 85  0
         if (isInfoEnabled()) {
 86  0
             s.println(content);
 87  
         }
 88  0
     }
 89  
 
 90  
     public void info(CharSequence content, Throwable error) {
 91  0
         info(content);
 92  0
         info(error);
 93  0
     }
 94  
 
 95  
     public void info(Throwable error) {
 96  0
         if (isInfoEnabled()) {
 97  0
             error.printStackTrace(s);
 98  
         }
 99  0
     }
 100  
 
 101  
     public boolean isDebugEnabled() {
 102  0
         return level >= DEBUG;
 103  
     }
 104  
 
 105  
     public boolean isErrorEnabled() {
 106  0
         return level >= ERROR;
 107  
     }
 108  
 
 109  
     public boolean isInfoEnabled() {
 110  0
         return level >= INFO;
 111  
     }
 112  
 
 113  
     public boolean isWarnEnabled() {
 114  0
         return level >= WARN;
 115  
     }
 116  
 
 117  
     public void warn(CharSequence content) {
 118  0
         if (isWarnEnabled()) {
 119  0
             s.println(content);
 120  
         }
 121  0
     }
 122  
 
 123  
     public void warn(CharSequence content, Throwable error) {
 124  0
         warn(content);
 125  0
         warn(error);
 126  0
     }
 127  
 
 128  
     public void warn(Throwable error) {
 129  0
         if (isWarnEnabled()) {
 130  0
             error.printStackTrace(s);
 131  
         }
 132  0
     }
 133  
 }