diff --git a/java/execution/impl/src/com/intellij/execution/JavaTestFrameworkRunnableState.java b/java/execution/impl/src/com/intellij/execution/JavaTestFrameworkRunnableState.java index 827fd3f2dfd7..a43e62da7138 100644 --- a/java/execution/impl/src/com/intellij/execution/JavaTestFrameworkRunnableState.java +++ b/java/execution/impl/src/com/intellij/execution/JavaTestFrameworkRunnableState.java @@ -109,7 +109,6 @@ public abstract class JavaTestFrameworkRunnableState - - - + \ No newline at end of file diff --git a/plugins/junit_rt/src/com/intellij/junit3/JUnit3IdeaTestRunner.java b/plugins/junit_rt/src/com/intellij/junit3/JUnit3IdeaTestRunner.java index 27ada8d3b4b9..e7bd2692b04b 100644 --- a/plugins/junit_rt/src/com/intellij/junit3/JUnit3IdeaTestRunner.java +++ b/plugins/junit_rt/src/com/intellij/junit3/JUnit3IdeaTestRunner.java @@ -18,8 +18,6 @@ package com.intellij.junit3; import com.intellij.rt.execution.junit.*; import com.intellij.rt.execution.junit.segments.OutputObjectRegistry; import com.intellij.rt.execution.junit.segments.PacketProcessor; -import jetbrains.buildServer.messages.serviceMessages.ServiceMessage; -import jetbrains.buildServer.messages.serviceMessages.ServiceMessageTypes; import junit.framework.*; import junit.textui.ResultPrinter; import junit.textui.TestRunner; @@ -179,7 +177,7 @@ public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner { final Map attrs = new HashMap(); attrs.put("name", getMethodName(test)); attrs.put("message", failureMessage != null ? failureMessage : ""); - System.out.println(ServiceMessage.asString(ServiceMessageTypes.TEST_FAILED, attrs)); + System.out.println(MapSerializerUtil.asString(MapSerializerUtil.TEST_FAILED, attrs)); } private static String getMethodName(Test test) { diff --git a/plugins/junit_rt/src/com/intellij/junit4/JUnit4TestListener.java b/plugins/junit_rt/src/com/intellij/junit4/JUnit4TestListener.java index 9b21ca5fe63f..7d9ceb6a2ec2 100644 --- a/plugins/junit_rt/src/com/intellij/junit4/JUnit4TestListener.java +++ b/plugins/junit_rt/src/com/intellij/junit4/JUnit4TestListener.java @@ -21,9 +21,7 @@ package com.intellij.junit4; import com.intellij.rt.execution.junit.ComparisonFailureData; -import jetbrains.buildServer.messages.serviceMessages.MapSerializerUtil; -import jetbrains.buildServer.messages.serviceMessages.ServiceMessage; -import jetbrains.buildServer.messages.serviceMessages.ServiceMessageTypes; +import com.intellij.rt.execution.junit.MapSerializerUtil; import junit.framework.ComparisonFailure; import org.junit.Ignore; import org.junit.runner.Description; @@ -140,11 +138,11 @@ public class JUnit4TestListener extends RunListener { //class setUp failed if (methodName == null) { for (Iterator iterator = description.getChildren().iterator(); iterator.hasNext(); ) { - testFailure(failure, ServiceMessageTypes.TEST_FAILED, getFullMethodName((Description)iterator.next())); + testFailure(failure, MapSerializerUtil.TEST_FAILED, getFullMethodName((Description)iterator.next())); } } else { - testFailure(failure, ServiceMessageTypes.TEST_FAILED, methodName); + testFailure(failure, MapSerializerUtil.TEST_FAILED, methodName); } } @@ -168,7 +166,7 @@ public class JUnit4TestListener extends RunListener { ComparisonFailureData.registerSMAttributes(null, stringWriter.toString(), e.getMessage(), attrs, e); } finally { - myPrintStream.println(ServiceMessage.asString(messageName, attrs)); + myPrintStream.println(MapSerializerUtil.asString(messageName, attrs)); } } @@ -204,7 +202,7 @@ public class JUnit4TestListener extends RunListener { private void testAssumptionFailure(Failure failure, Description testDescription, String name) throws Exception { testStarted(testDescription); - testFailure(failure, ServiceMessageTypes.TEST_IGNORED, name); + testFailure(failure, MapSerializerUtil.TEST_IGNORED, name); testFinished(testDescription); } @@ -224,7 +222,7 @@ public class JUnit4TestListener extends RunListener { //junit < 4.4 } attrs.put("name", getFullMethodName(description)); - myPrintStream.println(ServiceMessage.asString(ServiceMessageTypes.TEST_IGNORED, attrs)); + myPrintStream.println(MapSerializerUtil.asString(MapSerializerUtil.TEST_IGNORED, attrs)); testFinished(description); } diff --git a/plugins/junit_rt/src/com/intellij/rt/execution/junit/MapSerializerUtil.java b/plugins/junit_rt/src/com/intellij/rt/execution/junit/MapSerializerUtil.java new file mode 100644 index 000000000000..dbe9bd597737 --- /dev/null +++ b/plugins/junit_rt/src/com/intellij/rt/execution/junit/MapSerializerUtil.java @@ -0,0 +1,123 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.rt.execution.junit; + + +import java.util.Iterator; +import java.util.Map; + +public class MapSerializerUtil { + public static final String TEST_FAILED = "testFailed"; + public static final String TEST_IGNORED = "testIgnored"; + + + /** + * String escaping info provider. + */ + public interface EscapeInfoProvider { + /** + * Converts character to its representation in the final string + * @param c character to convert + * @return character representation or 0 if conversion is not applicable to that character + */ + char escape(char c); + + /** + * Escape character to use before escaped characters (before character representations generated by {@link #escape(char)} method) + * @return see above + */ + char escapeCharacter(); + } + + public static final EscapeInfoProvider STD_ESCAPER = new EscapeInfoProvider() { + public char escape(final char c) { + switch (c) { + case '\n': return 'n'; + case '\r': return 'r'; + case '\u0085': return 'x'; // next-line character + case '\u2028': return 'l'; // line-separator character + case '\u2029': return 'p'; // paragraph-separator character + case '|': return '|'; + case '\'': return '\''; + case '[': return '['; + case ']': return ']'; + default:return 0; + } + } + + public char escapeCharacter() { + return '|'; + } + }; + + /** + * Escapes characters specified by provider with '\' and specified character. + * @param str initial string + * @param p escape info provider. + * @return escaped string. + */ + public static String escapeStr(final String str, EscapeInfoProvider p) { + if (str == null) return null; + int finalCount = calcFinalEscapedStringCount(str, p); + + if (str.length() == finalCount) return str; + + char[] resultChars = new char[finalCount]; + int resultPos = 0; + for (int i = 0; i < str.length(); i++) { + char c = str.charAt(i); + final char escaped = p.escape(c); + if (escaped != 0) { + resultChars[resultPos++] = p.escapeCharacter(); + resultChars[resultPos++] = escaped; + } + else { + resultChars[resultPos++] = c; + } + } + + if (resultPos != finalCount) { + throw new RuntimeException("Incorrect escaping for '" + str + "'"); + } + return new String(resultChars); + } + + private static int calcFinalEscapedStringCount(final String name, final EscapeInfoProvider p) { + int result = 0; + for (int i = 0; i < name.length(); i++) { + char c = name.charAt(i); + if (p.escape(c) != 0) { + result += 2; + } + else { + result += 1; + } + } + + return result; + } + + public static String asString(final String messageName, final Map attributes) { + String text = "##teamcity[" + messageName; + for (Iterator iterator = attributes.keySet().iterator(); iterator.hasNext(); ) { + final Object attrName = iterator.next(); + text += " " + attrName + "='" + escapeStr((String)attributes.get(attrName), STD_ESCAPER) + "'"; + } + text += "]"; + return text; + } + +} diff --git a/plugins/testng_rt/src/org/testng/IDEATestNGRemoteListener.java b/plugins/testng_rt/src/org/testng/IDEATestNGRemoteListener.java index 08fe21a74286..6ce51491d450 100644 --- a/plugins/testng_rt/src/org/testng/IDEATestNGRemoteListener.java +++ b/plugins/testng_rt/src/org/testng/IDEATestNGRemoteListener.java @@ -1,9 +1,6 @@ package org.testng; import com.intellij.rt.execution.junit.ComparisonFailureData; -import jetbrains.buildServer.messages.serviceMessages.MapSerializerUtil; -import jetbrains.buildServer.messages.serviceMessages.ServiceMessage; -import jetbrains.buildServer.messages.serviceMessages.ServiceMessageTypes; import org.testng.internal.IResultListener; import org.testng.xml.XmlTest; @@ -166,7 +163,7 @@ public class IDEATestNGRemoteListener implements ISuiteListener, IResultListener notification = null; } ComparisonFailureData.registerSMAttributes(notification, getTrace(ex), failureMessage, attrs, ex); - myPrintStream.println(ServiceMessage.asString(ServiceMessageTypes.TEST_FAILED, attrs)); + myPrintStream.println(MapSerializerUtil.asString("testFailed", attrs)); onTestFinished(result); } diff --git a/plugins/testng_rt/src/org/testng/MapSerializerUtil.java b/plugins/testng_rt/src/org/testng/MapSerializerUtil.java new file mode 100644 index 000000000000..0d28976e66e0 --- /dev/null +++ b/plugins/testng_rt/src/org/testng/MapSerializerUtil.java @@ -0,0 +1,122 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.testng; + + +import java.util.Iterator; +import java.util.Map; + +public class MapSerializerUtil { + private static final String STD_EX_SUFFIX = + "Valid property list format is (name( )*=( )*\'escaped_value\'( )*)* where escape simbol is \"|\""; + + + /** + * String escaping info provider. + */ + public interface EscapeInfoProvider { + /** + * Converts character to its representation in the final string + * @param c character to convert + * @return character representation or 0 if conversion is not applicable to that character + */ + char escape(char c); + + /** + * Escape character to use before escaped characters (before character representations generated by {@link #escape(char)} method) + * @return see above + */ + char escapeCharacter(); + } + + public static final EscapeInfoProvider STD_ESCAPER = new EscapeInfoProvider() { + public char escape(final char c) { + switch (c) { + case '\n': return 'n'; + case '\r': return 'r'; + case '\u0085': return 'x'; // next-line character + case '\u2028': return 'l'; // line-separator character + case '\u2029': return 'p'; // paragraph-separator character + case '|': return '|'; + case '\'': return '\''; + case '[': return '['; + case ']': return ']'; + default:return 0; + } + } + + public char escapeCharacter() { + return '|'; + } + }; + + /** + * Escapes characters specified by provider with '\' and specified character. + * @param str initial string + * @param p escape info provider. + * @return escaped string. + */ + public static String escapeStr(final String str, EscapeInfoProvider p) { + if (str == null) return null; + int finalCount = calcFinalEscapedStringCount(str, p); + + if (str.length() == finalCount) return str; + + char[] resultChars = new char[finalCount]; + int resultPos = 0; + for (int i = 0; i < str.length(); i++) { + char c = str.charAt(i); + final char escaped = p.escape(c); + if (escaped != 0) { + resultChars[resultPos++] = p.escapeCharacter(); + resultChars[resultPos++] = escaped; + } + else { + resultChars[resultPos++] = c; + } + } + + if (resultPos != finalCount) { + throw new RuntimeException("Incorrect escaping for '" + str + "'"); + } + return new String(resultChars); + } + + private static int calcFinalEscapedStringCount(final String name, final EscapeInfoProvider p) { + int result = 0; + for (int i = 0; i < name.length(); i++) { + char c = name.charAt(i); + if (p.escape(c) != 0) { + result += 2; + } + else { + result += 1; + } + } + + return result; + } + + public static String asString(final String messageName, final Map attributes) { + String text = "##teamcity[" + messageName; + for (final String attrName : attributes.keySet()) { + text += " " + attrName + "='" + escapeStr(attributes.get(attrName), STD_ESCAPER) + "'"; + } + text += "]"; + return text; + } + +} diff --git a/plugins/testng_rt/testng_rt.iml b/plugins/testng_rt/testng_rt.iml index 3921608b92b4..f347fc89bc27 100644 --- a/plugins/testng_rt/testng_rt.iml +++ b/plugins/testng_rt/testng_rt.iml @@ -8,7 +8,6 @@ - \ No newline at end of file