From 6354b174e85a1822ecd4e08e608f61c1480ca7c5 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Mon, 15 Oct 2012 12:42:28 -0400 Subject: [PATCH] Java classfile analysis: log the problematic URL when IO.urlAsFile throws an exception. Ref #564. --- util/classfile/Analyze.scala | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/util/classfile/Analyze.scala b/util/classfile/Analyze.scala index e6b4ad63f..72dfed3f5 100644 --- a/util/classfile/Analyze.scala +++ b/util/classfile/Analyze.scala @@ -11,6 +11,7 @@ import java.io.File import java.lang.annotation.Annotation import java.lang.reflect.Method import java.lang.reflect.Modifier.{STATIC, PUBLIC, ABSTRACT} +import java.net.URL private[sbt] object Analyze { @@ -45,7 +46,7 @@ private[sbt] object Analyze { trapAndLog(log) { - for (url <- Option(loader.getResource(tpe.replace('.', '/') + ClassExt)); file <- IO.urlAsFile(url)) + for (url <- Option(loader.getResource(tpe.replace('.', '/') + ClassExt)); file <- urlAsFile(url, log)) { if(url.getProtocol == "jar") analysis.binaryDependency(file, tpe, source) @@ -73,6 +74,12 @@ private[sbt] object Analyze analysis.endSource(source) } } + private[this] def urlAsFile(url: URL, log: Logger): Option[File] = + try IO.urlAsFile(url) + catch { case e: Exception => + log.warn("Could not convert URL '" + url.toExternalForm + "' to File: " + e.toString) + None + } private def trapAndLog(log: Logger)(execute: => Unit) { try { execute }