2009-08-21 14:12:43 +02:00
|
|
|
/* sbt -- Simple Build Tool
|
|
|
|
|
* Copyright 2009 Mark Harrah
|
|
|
|
|
*/
|
|
|
|
|
package xsbt.boot
|
|
|
|
|
|
2009-09-09 05:13:30 +02:00
|
|
|
import BootConfiguration.{IvyPackage, JLinePackagePath, SbtBootPackage, ScalaPackage}
|
2010-06-16 02:38:18 +02:00
|
|
|
import scala.collection.immutable.Stream
|
2009-08-21 14:12:43 +02:00
|
|
|
|
|
|
|
|
/** A custom class loader to ensure the main part of sbt doesn't load any Scala or
|
|
|
|
|
* Ivy classes from the jar containing the loader. */
|
2010-06-16 02:38:18 +02:00
|
|
|
private[boot] final class BootFilteredLoader(parent: ClassLoader) extends ClassLoader(parent)
|
2009-08-21 14:12:43 +02:00
|
|
|
{
|
|
|
|
|
@throws(classOf[ClassNotFoundException])
|
|
|
|
|
override final def loadClass(className: String, resolve: Boolean): Class[_] =
|
|
|
|
|
{
|
2009-09-09 05:13:30 +02:00
|
|
|
// note that we allow xsbti.* and jline.*
|
2009-08-21 14:12:43 +02:00
|
|
|
if(className.startsWith(ScalaPackage) || className.startsWith(IvyPackage) || className.startsWith(SbtBootPackage))
|
|
|
|
|
throw new ClassNotFoundException(className)
|
|
|
|
|
else
|
|
|
|
|
super.loadClass(className, resolve)
|
|
|
|
|
}
|
2010-03-20 00:29:57 +01:00
|
|
|
override def getResources(name: String) = if(includeResource(name)) super.getResources(name) else excludedLoader.getResources(name)
|
|
|
|
|
override def getResource(name: String) = if(includeResource(name)) super.getResource(name) else excludedLoader.getResource(name)
|
2009-09-09 05:13:30 +02:00
|
|
|
def includeResource(name: String) = name.startsWith(JLinePackagePath)
|
2010-03-20 00:29:57 +01:00
|
|
|
// the loader to use when a resource is excluded. This needs to be at least parent.getParent so that it skips parent. parent contains
|
|
|
|
|
// resources included in the launcher, which need to be ignored. Now that launcher can be unrooted (not the application entry point),
|
|
|
|
|
// this needs to be the Java extension loader (the loader with getParent == null)
|
|
|
|
|
private val excludedLoader = Loaders(parent.getParent).head
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object Loaders
|
|
|
|
|
{
|
|
|
|
|
def apply(loader: ClassLoader): Stream[ClassLoader] =
|
|
|
|
|
{
|
|
|
|
|
def loaders(loader: ClassLoader, accum: Stream[ClassLoader]): Stream[ClassLoader] =
|
|
|
|
|
if(loader eq null) accum else loaders(loader.getParent, Stream.cons(loader, accum))
|
|
|
|
|
loaders(getClass.getClassLoader.getParent, Stream.empty)
|
|
|
|
|
}
|
2009-08-21 14:12:43 +02:00
|
|
|
}
|