From 666819e707dc34770857ced295f1726a55901e29 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Fri, 8 Aug 2014 13:03:01 -0400 Subject: [PATCH] Fix unknown host exception in junit xml listener. Fixes #1506 --- testing/src/main/scala/sbt/JUnitXmlTestsListener.scala | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/testing/src/main/scala/sbt/JUnitXmlTestsListener.scala b/testing/src/main/scala/sbt/JUnitXmlTestsListener.scala index 815a1110d..ec9303283 100644 --- a/testing/src/main/scala/sbt/JUnitXmlTestsListener.scala +++ b/testing/src/main/scala/sbt/JUnitXmlTestsListener.scala @@ -1,7 +1,7 @@ package sbt -import java.io.{ StringWriter, PrintWriter, File } -import java.net.InetAddress +import java.io.{IOException, StringWriter, PrintWriter, File} +import java.net.{InetAddress} import scala.collection.mutable.ListBuffer import scala.util.DynamicVariable @@ -15,7 +15,11 @@ import testing.{ Event => TEvent, Status => TStatus, OptionalThrowable, TestSele */ class JUnitXmlTestsListener(val outputDir: String) extends TestsListener { /**Current hostname so we know which machine executed the tests*/ - val hostname = InetAddress.getLocalHost.getHostName + val hostname = + try InetAddress.getLocalHost.getHostName + catch { + case x: IOException => "localhost" + } /**The dir in which we put all result files. Is equal to the given dir + "/test-reports"*/ val targetDir = new File(outputDir + "/test-reports/")