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