Permalink
Browse files

Upgrade to SBT 0.13

  • Loading branch information...
1 parent 5d37dab commit ab47db737010827b51be6237ad273f9ae61c471a @philwills philwills committed Sep 30, 2013
Showing with 36 additions and 24 deletions.
  1. +9 −1 build.sbt
  2. +1 −1 project/build.properties
  3. +1 −1 project/plugins.sbt
  4. +25 −21 src/main/scala/com/gu/TeamCityTestReporting.scala
View
@@ -6,7 +6,15 @@ 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 <<= (version) { version: String =>
+ val scalasbt = "http://scalasbt.artifactoryonline.com/scalasbt/"
+ val (name, url) = if (version.contains("-SNAPSHOT"))
+ ("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
+
View
@@ -1 +1 @@
-sbt.version=0.12.2
+sbt.version=0.13.0
View
@@ -1 +1 @@
-addSbtPlugin("com.github.gseitz" % "sbt-release" % "0.8")
+addSbtPlugin("com.github.gseitz" % "sbt-release" % "0.8")
@@ -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}
@@ -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)
}
}
}
@@ -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
}

0 comments on commit ab47db7

Please sign in to comment.