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
31 public static final int UNDEFINED = -1;
32
33 public static final int SUCCESS = 0;
34
35 public static final int ERROR = 1;
36
37 private StringBuilder stdOut = new StringBuilder();
38
39 private int resultCode = UNDEFINED;
40
41 private long startTime;
42
43 private long endTime;
44
45 private static final String LS = System.getProperty( "line.separator" );
46
47
48
49
50
51 public void appendInfo( String message )
52 {
53 stdOut.append( "[INFO] " ).append( message ).append( LS );
54 }
55
56
57
58
59 public void appendWarn( String message )
60 {
61 stdOut.append( "[WARN] " ).append( message ).append( LS );
62 }
63
64
65
66
67
68 public void appendDebug( String message )
69 {
70 stdOut.append( "[DEBUG] " ).append( message ).append( LS );
71 }
72
73
74
75
76
77
78 public void appendDebug( String message, Exception e )
79 {
80 appendDebug( message );
81
82 stdOut.append( getStackTrace( e ) ).append( LS );
83 }
84
85
86
87
88
89
90 public void appendError( String message )
91 {
92 stdOut.append( "[ERROR] " ).append( message ).append( LS );
93
94 setResultCode( ERROR );
95 }
96
97
98
99
100
101
102 public void appendError( Exception e )
103 {
104 appendError( getStackTrace( e ) );
105 }
106
107
108
109
110
111
112
113 public void appendError( String message, Exception e )
114 {
115 appendError( message );
116
117 stdOut.append( getStackTrace( e ) ).append( LS );
118 }
119
120
121
122
123
124
125 public void appendOutput( String message )
126 {
127 stdOut.append( message );
128 }
129
130 public String getOutput()
131 {
132 return stdOut.toString();
133 }
134
135 public int getResultCode()
136 {
137 return resultCode;
138 }
139
140 public void setResultCode( int resultCode )
141 {
142 this.resultCode = resultCode;
143 }
144
145 public long getStartTime()
146 {
147 return startTime;
148 }
149
150 public void setStartTime( long startTime )
151 {
152 this.startTime = startTime;
153 }
154
155 public long getEndTime()
156 {
157 return endTime;
158 }
159
160 public void setEndTime( long endTime )
161 {
162 this.endTime = endTime;
163 }
164
165 private String getStackTrace( Exception e )
166 {
167 ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
168
169 PrintStream stream = new PrintStream( byteStream );
170
171 e.printStackTrace( stream );
172
173 stream.flush();
174
175 return byteStream.toString();
176 }
177 }