| 4736 |
rpuchmay |
1 |
package releaseManager;
|
|
|
2 |
|
|
|
3 |
import java.io.IOException;
|
|
|
4 |
import java.io.PrintStream;
|
|
|
5 |
import java.io.StringReader;
|
|
|
6 |
import java.io.StringWriter;
|
|
|
7 |
|
|
|
8 |
/**
|
|
|
9 |
* Hides the details of the teamcity messages
|
|
|
10 |
* TODO: Ensure all strings are escaped correctly.
|
|
|
11 |
* @author RPuchmay
|
|
|
12 |
*
|
|
|
13 |
*/
|
|
|
14 |
public class TeamCity
|
|
|
15 |
{
|
|
|
16 |
private PrintStream output;
|
|
|
17 |
|
|
|
18 |
private static final String START_SUITE = "##teamcity[testSuiteStarted name='%s']";
|
|
|
19 |
private static final String FINISH_SUITE = "##teamcity[testSuiteFinished name='%s']";
|
|
|
20 |
private static final String START_TEST = "##teamcity[testStarted name='%s']";
|
|
|
21 |
private static final String FINISH_TEST = "##teamcity[testFinished name='%s']";
|
|
|
22 |
private static final String ERROR_MESSAGE = "##teamcity[message text='%s' errorDetails='%s' status='ERROR']";
|
|
|
23 |
|
|
|
24 |
private static final String NEW_LINE = "\n";
|
|
|
25 |
|
|
|
26 |
public TeamCity(PrintStream output)
|
|
|
27 |
{
|
|
|
28 |
this.output = output;
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
public void startSuite(String suiteName)
|
|
|
32 |
{
|
|
|
33 |
output.format(START_SUITE + NEW_LINE, suiteName);
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
public void startTest(String packageName)
|
|
|
37 |
{
|
|
|
38 |
output.format(START_TEST + NEW_LINE, packageName);
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
public void finishTest(String packageName)
|
|
|
42 |
{
|
|
|
43 |
output.format(FINISH_TEST + NEW_LINE, packageName);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
public void finishSuite(String suiteName)
|
|
|
47 |
{
|
|
|
48 |
output.format(FINISH_SUITE + NEW_LINE, suiteName);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
public void error(String message, String details)
|
|
|
52 |
{
|
|
|
53 |
output.format(ERROR_MESSAGE + NEW_LINE, message, encode(details));
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
public String encode(String input)
|
|
|
57 |
{
|
|
|
58 |
String result = new String();
|
|
|
59 |
try
|
|
|
60 |
{
|
|
|
61 |
StringReader reader = new StringReader(input);
|
|
|
62 |
StringWriter writer = new StringWriter();
|
|
|
63 |
int character;
|
|
|
64 |
|
|
|
65 |
while ((character = reader.read()) != -1)
|
|
|
66 |
{
|
|
|
67 |
switch (character)
|
|
|
68 |
{
|
|
|
69 |
case (int)'\n': writer.append("|n");
|
|
|
70 |
break;
|
|
|
71 |
case (int)'\r': writer.append("|r");
|
|
|
72 |
break;
|
|
|
73 |
case (int)'\'': writer.append("|'");
|
|
|
74 |
break;
|
|
|
75 |
case (int)'|': writer.append("||");
|
|
|
76 |
break;
|
|
|
77 |
case (int)'[': writer.append("|[");
|
|
|
78 |
break;
|
|
|
79 |
case (int)']': writer.append("|]");
|
|
|
80 |
break;
|
|
|
81 |
default: writer.append((char)character);
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
result = writer.toString();
|
|
|
85 |
}
|
|
|
86 |
catch (IOException e)
|
|
|
87 |
{
|
|
|
88 |
// Ignore, just return empty string below.
|
|
|
89 |
}
|
|
|
90 |
return result;
|
|
|
91 |
}
|
|
|
92 |
}
|