Permalink
Browse files

Updated for sbt 0.10

  • Loading branch information...
1 parent 824abc1 commit 590199ccc270713c9a82e53eff793096f553921d @tackley tackley committed Jun 20, 2011
Showing with 49 additions and 28 deletions.
  1. +1 −0 .gitignore
  2. +10 −0 build.sbt
  3. +0 −8 project/build.properties
  4. +0 −5 project/build/TeamCityTestReportingPlugin.scala
  5. +38 −15 src/main/scala/TeamCityTestReporting.scala
View
@@ -9,3 +9,4 @@ project/boot/
*.iml
*.iws
*.ipr
+.idea*
View
@@ -0,0 +1,10 @@
+
+
+sbtPlugin := true
+
+
+name := "sbt-teamcity-test-reporting-plugin"
+
+organization := "com.gu"
+
+version := "1.0"
View
@@ -1,8 +0,0 @@
-#Project properties
-#Mon Oct 04 15:01:59 BST 2010
-project.organization=com.gu
-project.name=sbt-teamcity-test-reporting-plugin
-sbt.version=0.7.4
-project.version=0.2
-build.scala.versions=2.7.7
-project.initialize=false
@@ -1,5 +0,0 @@
-import sbt._
-class TeamCityTestReportingPlugin(info: ProjectInfo) extends PluginProject(info) {
- override def managedStyle = ManagedStyle.Maven
- lazy val publishTo = Resolver.file("GitHub Pages", (Path.userHome / "guardian.github.com" / "maven" / "repo-releases").asFile )
-}
@@ -3,17 +3,22 @@ package com.gu
import sbt._
import org.scalatools.testing.{Event => TEvent, Result => TResult}
+import Keys._
-trait TeamCityTestReporting extends BasicScalaProject {
- override def testListeners = super.testListeners ++ TeamCityTestListener.ifRunningUnderTeamCity
+object TeamCityTestReporting extends Plugin {
+ override def settings = Seq(
+ testListeners ++= TeamCityTestListener.ifRunningUnderTeamCity
+ )
}
class TeamCityTestListener extends TestReportListener {
/** called for each class or equivalent grouping */
- def startGroup(name: String) = teamcityReport("testSuiteStarted", "name" -> name )
+ def startGroup(name: String) {
+ teamcityReport("testSuiteStarted", "name" -> name)
+ }
/** called for each test method or equivalent */
- def testEvent(event: TestEvent) = {
+ def testEvent(event: TestEvent) {
for (e: TEvent <- event.detail) {
// this is a lie: the test has already been executed and started by this point,
@@ -25,7 +30,8 @@ class TeamCityTestListener extends TestReportListener {
case TResult.Error | TResult.Failure =>
teamcityReport("testFailed",
"name" -> e.testName,
- "details" -> (e.error.toString.replace("\n", " ").replace("'", "\"") + " " + e.error.getStackTrace().mkString(" at ", " at ", "")))
+ "details" -> (e.error.toString +
+ "\n" + e.error.getStackTrace.mkString("\n at ", "\n at ", "")))
case TResult.Skipped =>
teamcityReport("testIgnored", "name" -> e.testName)
}
@@ -37,19 +43,36 @@ class TeamCityTestListener extends TestReportListener {
/** called if there was an error during test */
- def endGroup(name: String, t: Throwable) = teamcityReport("testSuiteFinished", "name" -> name)
+ def endGroup(name: String, t: Throwable) {
+ teamcityReport("testSuiteFinished", "name" -> name)
+ }
/** called if test completed */
- def endGroup(name: String, result: Result.Value) = teamcityReport("testSuiteFinished", "name" -> name)
+ def endGroup(name: String, result: TestResult.Value) {
+ teamcityReport("testSuiteFinished", "name" -> name)
+ }
- private def teamcityReport(messageName: String, attributes: (String, String)*) =
- println("##teamcity["+ messageName +" "+ attributes.map{ case (k, v) => k +"='"+ v +"'" }.mkString(" ") + "]")
-}
-object TeamCityTestListener {
- // this is nicer in 2.8 with Option.apply ...
- private lazy val teamCityProjectName = Some(System.getenv("TEAMCITY_PROJECT_NAME")).filter(_ != null)
- lazy val ifRunningUnderTeamCity = teamCityProjectName.map(ignore => new TeamCityTestListener)
+ // http://confluence.jetbrains.net/display/TCD65/Build+Script+Interaction+with+TeamCity
+ def tidy(s: String) = s
+ .replace("|", "||")
+ .replace("'", "|'")
+ .replace("\n", "|n")
+ .replace("\r", "|r")
+ .replace("\u0085", "|x")
+ .replace("\u2028", "|l")
+ .replace("\u2029", "|p")
+ .replace("[", "|[")
+ .replace("]", "|]")
- println("teamcityprojectname = " + teamCityProjectName)
+ private def teamcityReport(messageName: String, attributes: (String, String)*) {
+ println("##teamcity[" + messageName + " " + attributes.map {
+ case (k, v) => k + "='" + tidy(v) + "'"
+ }.mkString(" ") + "]")
+ }
+}
+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 590199c

Please sign in to comment.