mirror of https://github.com/sbt/sbt.git
Add toString methods to classloaders, for debugging.
* Add toString methods to all classloader classes.
This commit is contained in:
parent
fa36d0e290
commit
50460fad28
|
|
@ -46,14 +46,26 @@ final class SelfFirstLoader(classpath: Seq[URL], parent: ClassLoader) extends Lo
|
|||
|
||||
/** Doesn't load any classes itself, but instead verifies that all classes loaded through `parent` either come from `root` or `classpath`.*/
|
||||
final class ClasspathFilter(parent: ClassLoader, root: ClassLoader, classpath: Set[File]) extends ClassLoader(parent) {
|
||||
override def toString =
|
||||
s"""|ClasspathFilter(
|
||||
| parent = $parent
|
||||
| root = $root
|
||||
| cp = $classpath
|
||||
|)""".stripMargin
|
||||
|
||||
private[this] val directories: Seq[File] = classpath.toSeq.filter(_.isDirectory)
|
||||
override def loadClass(className: String, resolve: Boolean): Class[_] =
|
||||
{
|
||||
val c = super.loadClass(className, resolve)
|
||||
if (includeLoader(c.getClassLoader, root) || fromClasspath(c))
|
||||
c
|
||||
else
|
||||
else {
|
||||
System.err.println(s"DEBUGME: Failing to load class $className because it was not in expected parent chain.")
|
||||
System.err.println(s"DEBUGME: Found: ${c.getClassLoader}")
|
||||
System.err.println(s"DEBUGME: Expected: ${root}")
|
||||
System.err.println(s"DEBUGME: onClasspath: ${fromClasspath(c)}")
|
||||
throw new ClassNotFoundException(className)
|
||||
}
|
||||
}
|
||||
private[this] def fromClasspath(c: Class[_]): Boolean =
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,6 +26,13 @@ object ClasspathUtilities {
|
|||
new URLClassLoader(Path.toURLs(paths), parent) with RawResources with NativeCopyLoader {
|
||||
override def resources = resourceMap
|
||||
override val config = new NativeCopyConfig(nativeTemp, paths, javaLibraryPaths)
|
||||
override def toString =
|
||||
s"""|URLClassLoader with NativeCopyLoader with RawResources(
|
||||
| urls = $paths,
|
||||
| parent = $parent,
|
||||
| resourceMap = ${resourceMap.keySet},
|
||||
| nativeTemp = $nativeTemp
|
||||
|)""".stripMargin
|
||||
}
|
||||
|
||||
def javaLibraryPaths: Seq[File] = IO.parseClasspath(System.getProperty("java.library.path"))
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ final class NullLoader extends ClassLoader {
|
|||
override final def loadClass(className: String, resolve: Boolean): Class[_] = throw new ClassNotFoundException("No classes can be loaded from the null loader")
|
||||
override def getResource(name: String): URL = null
|
||||
override def getResources(name: String): Enumeration[URL] = null
|
||||
override def toString = "NullLoader"
|
||||
}
|
||||
|
||||
/** Exception thrown when `loaderA` and `loaderB` load a different Class for the same name. */
|
||||
|
|
@ -84,6 +85,8 @@ class DualLoader(parentA: ClassLoader, aOnlyClasses: String => Boolean, aOnlyRes
|
|||
new DualEnumeration(urlsA, urlsB)
|
||||
}
|
||||
}
|
||||
|
||||
override def toString = s"DualLoader(a = $parentA, b = $parentB)"
|
||||
}
|
||||
|
||||
/** Concatenates `a` and `b` into a single `Enumeration`.*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue