Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: longwa/grails-teamcity
base: 5c5eaaa105
...
head fork: longwa/grails-teamcity
compare: 80a7b359ea
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
2  TeamcityGrailsPlugin.groovy
@@ -1,5 +1,5 @@
class TeamcityGrailsPlugin {
- def version = "1.0.1"
+ def version = "1.0.2"
def grailsVersion = "2.0 > *"
def dependsOn = [:]
def pluginExcludes = [
View
9 scripts/_Events.groovy
@@ -1,4 +1,13 @@
/**
+ * Packaging
+ */
+eventPackagingEnd = {
+ def msg = loadMessageClass().newInstance("progressMessage")
+ msg.text = "Packaging Complete"
+ msg.write(grailsConsole.&log)
+}
+
+/**
* Test Events
*/
eventTestSuiteStart = { name ->
View
39 src/groovy/grails/teamcity/ServiceMessage.groovy
@@ -1,6 +1,7 @@
package grails.teamcity
import java.text.SimpleDateFormat
+import org.codehaus.groovy.runtime.StackTraceUtils
/**
* A service message is the basic way of communicating with TeamCity by outputting specially formatted
@@ -10,6 +11,7 @@ class ServiceMessage {
def attributes = [:] as TreeMap
def messageName
+ def text = ""
ServiceMessage(def name) {
messageName = name
@@ -31,12 +33,17 @@ class ServiceMessage {
* Format the message
*/
String toString() {
- def attrString = attributes.collect { k, v -> "${k}='${escape(v?.toString())}'" }.join(" ")
- "##teamcity[${messageName} ${attrString}]"
+ def attrString = attributes.collect { k, v -> "${k}='${escape(valueToString(v))}'" }.join(" ")
+ if( text ) {
+ "##teamcity[${messageName} '${escape(text)}']"
+ }
+ else {
+ "##teamcity[${messageName} ${attrString}]"
+ }
}
/**
- * Call the given logger function if enabled.
+ * Call the given logger function if service messages are enabled.
* @param method that can take a single string argument
*/
void write(Closure logger) {
@@ -52,11 +59,35 @@ class ServiceMessage {
System.getenv("TEAMCITY_VERSION") != null
}
- private String escape(String str) {
+ protected String escape(String str) {
+ // Make sure you escape the escape character first
str.replaceAll("\\|", "||")
.replaceAll("\n", "|n")
+ .replaceAll("\r", "|r")
+ .replaceAll("\u0085", "|x")
+ .replaceAll("\u2028", "|l")
+ .replaceAll("\u2029", "|p")
.replaceAll("'", "|'")
.replaceAll("\\[", "|[")
.replaceAll("\\]", "|]")
}
+
+ protected String valueToString(def val) {
+ if( val == null ) {
+ ""
+ }
+ else if( val instanceof Throwable) {
+ Throwable t = StackTraceUtils.deepSanitize(val)
+
+ // Convert the sanitize stack to a string
+ StringWriter stringWriter = new StringWriter()
+ PrintWriter printWriter = new PrintWriter(stringWriter)
+ t.printStackTrace(printWriter)
+
+ stringWriter.toString()
+ }
+ else {
+ val.toString()
+ }
+ }
}
View
11 test/unit/grails/teamcity/ServiceMessageTests.groovy
@@ -47,4 +47,15 @@ class ServiceMessageTests extends GroovyTestCase {
assert output != null
assert output == "##teamcity[test flowId='grails' foo='true' timestamp='now']"
}
+
+ void testExceptionFormatting() {
+ def e = new AssertionError("Something bad happened")
+ def message = new ServiceMessage("test")
+ message.detail = e
+ message.message = e.message
+
+ message.write { str ->
+ assert !str.contains("at grails.teamcity.ServiceMessageTests")
+ }
+ }
}

No commit comments for this range

Something went wrong with that request. Please try again.