Coverage Report - org.apache.maven.shared.release.ReleaseResult
 
Classes in this File Line Coverage Branch Coverage Complexity
ReleaseResult
71%
28/39
N/A
1
 
 1  
 package org.apache.maven.shared.release;
 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.ByteArrayOutputStream;
 23  
 import java.io.PrintStream;
 24  
 
 25  
 /**
 26  
  * @author Edwin Punzalan
 27  
  */
 28  1032
 public class ReleaseResult
 29  
 {
 30  
     public static final int UNDEFINED = -1, SUCCESS = 0, ERROR = 1;
 31  
 
 32  1032
     private StringBuilder stdOut = new StringBuilder();
 33  
 
 34  1032
     private int resultCode = UNDEFINED;
 35  
 
 36  
     private long startTime;
 37  
 
 38  
     private long endTime;
 39  
 
 40  2
     private static final String LS = System.getProperty( "line.separator" );
 41  
 
 42  
     public void appendInfo( String message )
 43  
     {
 44  1344
         stdOut.append( "[INFO] " ).append( message ).append( LS );
 45  1344
     }
 46  
 
 47  
     public void appendWarn( String message )
 48  
     {
 49  16
         stdOut.append( "[WARN] " ).append( message ).append( LS );
 50  16
     }
 51  
 
 52  
     public void appendDebug( String message )
 53  
     {
 54  46
         stdOut.append( "[DEBUG] " ).append( message ).append( LS );
 55  46
     }
 56  
 
 57  
     public void appendDebug( String message, Exception e )
 58  
     {
 59  4
         appendDebug( message );
 60  
 
 61  4
         stdOut.append( getStackTrace( e ) ).append( LS );
 62  4
     }
 63  
 
 64  
     public void appendError( String message )
 65  
     {
 66  0
         stdOut.append( "[ERROR] " ).append( message ).append( LS );
 67  
 
 68  0
         setResultCode( ERROR );
 69  0
     }
 70  
 
 71  
     public void appendError( Exception e )
 72  
     {
 73  0
         appendError( getStackTrace( e ) );
 74  0
     }
 75  
 
 76  
     public void appendError( String message, Exception e )
 77  
     {
 78  0
         appendError( message );
 79  
 
 80  0
         stdOut.append( getStackTrace( e ) ).append( LS );
 81  0
     }
 82  
 
 83  
     public void appendOutput( String message )
 84  
     {
 85  60
         stdOut.append( message );
 86  60
     }
 87  
 
 88  
     public String getOutput()
 89  
     {
 90  52
         return stdOut.toString();
 91  
     }
 92  
 
 93  
     public int getResultCode()
 94  
     {
 95  8
         return resultCode;
 96  
     }
 97  
 
 98  
     public void setResultCode( int resultCode )
 99  
     {
 100  740
         this.resultCode = resultCode;
 101  740
     }
 102  
 
 103  
     public long getStartTime()
 104  
     {
 105  0
         return startTime;
 106  
     }
 107  
 
 108  
     public void setStartTime( long startTime )
 109  
     {
 110  2
         this.startTime = startTime;
 111  2
     }
 112  
 
 113  
     public long getEndTime()
 114  
     {
 115  0
         return endTime;
 116  
     }
 117  
 
 118  
     public void setEndTime( long endTime )
 119  
     {
 120  2
         this.endTime = endTime;
 121  2
     }
 122  
 
 123  
     private String getStackTrace( Exception e )
 124  
     {
 125  4
         ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
 126  
 
 127  4
         PrintStream stream = new PrintStream( byteStream );
 128  
 
 129  4
         e.printStackTrace( stream );
 130  
 
 131  4
         stream.flush();
 132  
 
 133  4
         return byteStream.toString();
 134  
     }
 135  
 
 136  
     @Deprecated
 137  
     public StringBuffer getOutputBuffer()
 138  
     {
 139  0
         return new StringBuffer( stdOut );
 140  
     }
 141  
 }