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