diff --git a/LICENSE b/LICENSE index 7b09b8ec6..15f983d64 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2008, 2009, 2010 Mark Harrah, Jason Zaugg +Copyright (c) 2008, 2009, 2010 Mark Harrah, Tony Sloane, Jason Zaugg All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/util/log/NOTICE b/util/log/NOTICE index 1a42b7a31..2455dad65 100644 --- a/util/log/NOTICE +++ b/util/log/NOTICE @@ -1,3 +1,3 @@ Simple Build Tool: Logging Component -Copyright 2008, 2009 Mark Harrah +Copyright 2008, 2009, 2010 Mark Harrah, Tony Sloane Licensed under BSD-style license (see LICENSE) \ No newline at end of file diff --git a/util/log/StackTrace.scala b/util/log/StackTrace.scala new file mode 100644 index 000000000..1ecd6e8bf --- /dev/null +++ b/util/log/StackTrace.scala @@ -0,0 +1,63 @@ +/* sbt -- Simple Build Tool + * Copyright 2010 Tony Sloane + */ +package sbt + +object StackTrace +{ + def isSbtClass(name: String) = name.startsWith("sbt") || name.startsWith("xsbt") + /** + * Return a printable representation of the stack trace associated + * with t. Information about t and its Throwable causes is included. + * The number of lines to be included for each Throwable is configured + * via d which should be greater than or equal to zero. If d is zero, + * then all elements are included up to (but not including) the first + * element that comes from sbt. If d is greater than zero, then up to + * that many lines are included, where the line for the Throwable is + * counted plus one line for each stack element. Less lines will be + * included if there are not enough stack elements. + */ + def trimmed(t : Throwable, d : Int) : String = { + require(d >= 0) + val b = new StringBuilder () + + def appendStackTrace (t : Throwable, first : Boolean) { + + val include : StackTraceElement => Boolean = + if (d == 0) + element => !isSbtClass(element.getClassName) + else { + var count = d - 1 + (_ => { count -= 1; count >= 0 }) + } + + def appendElement (e : StackTraceElement) { + b.append ("\tat ") + b.append (e) + b.append ('\n') + } + + if (!first) + b.append ("Caused by: ") + b.append (t) + b.append ('\n') + + val els = t.getStackTrace () + var i = 0 + while ((i < els.size) && include (els (i))) { + appendElement (els (i)) + i += 1 + } + + } + + appendStackTrace (t, true) + var c = t + while (c.getCause () != null) { + c = c.getCause () + appendStackTrace (c, false) + } + b.toString () + + } +} \ No newline at end of file