Blame | Last modification | View Log | RSS feed
package releaseManager;import java.io.IOException;import java.io.PrintStream;import java.io.StringReader;import java.io.StringWriter;/*** Hides the details of the teamcity messages* TODO: Ensure all strings are escaped correctly.* @author RPuchmay**/public class TeamCity{private PrintStream output;private static final String START_SUITE = "##teamcity[testSuiteStarted name='%s']";private static final String FINISH_SUITE = "##teamcity[testSuiteFinished name='%s']";private static final String START_TEST = "##teamcity[testStarted name='%s']";private static final String FINISH_TEST = "##teamcity[testFinished name='%s']";private static final String ERROR_MESSAGE = "##teamcity[message text='%s' errorDetails='%s' status='ERROR']";private static final String NEW_LINE = "\n";public TeamCity(PrintStream output){this.output = output;}public void startSuite(String suiteName){output.format(START_SUITE + NEW_LINE, suiteName);}public void startTest(String packageName){output.format(START_TEST + NEW_LINE, packageName);}public void finishTest(String packageName){output.format(FINISH_TEST + NEW_LINE, packageName);}public void finishSuite(String suiteName){output.format(FINISH_SUITE + NEW_LINE, suiteName);}public void error(String message, String details){output.format(ERROR_MESSAGE + NEW_LINE, message, encode(details));}public String encode(String input){String result = new String();try{StringReader reader = new StringReader(input);StringWriter writer = new StringWriter();int character;while ((character = reader.read()) != -1){switch (character){case (int)'\n': writer.append("|n");break;case (int)'\r': writer.append("|r");break;case (int)'\'': writer.append("|'");break;case (int)'|': writer.append("||");break;case (int)'[': writer.append("|[");break;case (int)']': writer.append("|]");break;default: writer.append((char)character);}}result = writer.toString();}catch (IOException e){// Ignore, just return empty string below.}return result;}}