Skip to content
This repository has been archived by the owner on Jan 31, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4 from guardian/pw-sbt-0.13
Browse files Browse the repository at this point in the history
Upgrade to work with SBT 0.13
  • Loading branch information
philwills committed Sep 30, 2013
2 parents 6da4023 + 1c804f0 commit 7589a5d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
11 changes: 10 additions & 1 deletion build.sbt
Expand Up @@ -6,7 +6,16 @@ sbtPlugin := true

releaseSettings

publishTo := Some(Resolver.url("scala-sbt-plugin-releases", new URL("http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns))
publishTo := {
val isSnapshot = version.value.contains("-SNAPSHOT")
val scalasbt = "http://scalasbt.artifactoryonline.com/scalasbt/"
val (name, url) = if (isSnapshot)
("sbt-plugin-snapshots", scalasbt+"sbt-plugin-snapshots")
else
("sbt-plugin-releases", scalasbt+"sbt-plugin-releases")
Some(Resolver.url(name, new URL(url))(Resolver.ivyStylePatterns))
}

publishMavenStyle := false


2 changes: 1 addition & 1 deletion project/build.properties
@@ -1 +1 @@
sbt.version=0.12.2
sbt.version=0.13.0
2 changes: 1 addition & 1 deletion project/plugins.sbt
@@ -1 +1 @@
addSbtPlugin("com.github.gseitz" % "sbt-release" % "0.6")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "0.8")
46 changes: 25 additions & 21 deletions src/main/scala/com/gu/TeamCityTestReporting.scala
@@ -1,7 +1,7 @@
package com.gu

import sbt._
import org.scalatools.testing.{Event => TEvent, Result => TResult}
import sbt.testing.{Event, OptionalThrowable, Status}

import Keys._
import java.io.{PrintWriter, StringWriter}
Expand All @@ -22,37 +22,41 @@ class TeamCityTestListener extends TestReportListener {
// different projects will get mixed up.
}

def nicelyFormatException(t: Throwable) = {
val w = new StringWriter
val p = new PrintWriter(w)
t.printStackTrace(p)
w.toString
def nicelyFormatException(t: OptionalThrowable) = {
if (t.isDefined) {
val w = new StringWriter
val p = new PrintWriter(w)
t.get.printStackTrace(p)
w.toString
} else ""
}

/** called for each test method or equivalent */
def testEvent(event: TestEvent) {
for (e: TEvent <- event.detail) {
for (e: Event <- event.detail) {

// TC seems to get a bit upset if you start a test while one is already running
// so a nasty bit of synchronisation here to stop that happening
synchronized {
// this is a lie: the test has already been executed and started by this point,
// but sbt doesn't send an event when test starts
teamcityReport("testStarted", "name" -> e.testName)
teamcityReport("testStarted", "name" -> e.fullyQualifiedName)

e.result match {
case TResult.Success => // nothing extra to report
case TResult.Error | TResult.Failure =>
e.status match {
case Status.Success => // nothing extra to report
case Status.Error | Status.Failure =>
teamcityReport("testFailed",
"name" -> e.testName,
"details" -> nicelyFormatException(e.error())
"name" -> e.fullyQualifiedName,
"details" -> nicelyFormatException(e.throwable)
)
case TResult.Skipped =>
teamcityReport("testIgnored", "name" -> e.testName)
case Status.Skipped | Status.Ignored | Status.Pending=>
teamcityReport("testIgnored", "name" -> e.fullyQualifiedName)
case Status.Canceled =>
// I can't think how this would happen and no appropriate message for Teamcity
println(s"Test:${e.fullyQualifiedName} was cancelled")
}

teamcityReport("testFinished", "name" -> e.testName)

teamcityReport("testFinished", "name" -> e.fullyQualifiedName)
}
}
}
Expand All @@ -77,14 +81,14 @@ class TeamCityTestListener extends TestReportListener {
.replace("]", "|]")

private def teamcityReport(messageName: String, attributes: (String, String)*) {
println("##teamcity[" + messageName + " " + attributes.map {
case (k, v) => k + "='" + tidy(v) + "'"
}.mkString(" ") + "]")
val attributeString = attributes.map {
case (k, v) => s"$k='${tidy(v)}'"
}.mkString(" ")
println(s"##teamcity[$messageName $attributeString]")
}
}

object TeamCityTestListener {
// teamcity se
private lazy val teamCityProjectName = Option(System.getenv("TEAMCITY_PROJECT_NAME"))
lazy val ifRunningUnderTeamCity = teamCityProjectName.map(ignore => new TeamCityTestListener).toSeq
}
Expand Down

0 comments on commit 7589a5d

Please sign in to comment.