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 | 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 | |
} |