Fix Java dependency tracking in 0.6.x

This commit is contained in:
Mark Harrah 2009-12-14 18:39:15 -05:00
parent 414043b7f4
commit bad073408d
4 changed files with 19 additions and 3 deletions

View File

@ -15,9 +15,19 @@ object ClasspathUtilities
def toClasspath(paths: Iterable[Path]): Array[URL] = paths.map(_.asURL).toSeq.toArray
def toLoader(finder: PathFinder): ClassLoader = toLoader(finder.get)
def toLoader(finder: PathFinder, parent: ClassLoader): ClassLoader = toLoader(finder.get, parent)
def toLoader(paths: Iterable[Path]): ClassLoader = new URLClassLoader(toClasspath(paths), getClass.getClassLoader)
def toLoader(paths: Iterable[Path]): ClassLoader = new URLClassLoader(toClasspath(paths), rootLoader)
def toLoader(paths: Iterable[Path], parent: ClassLoader): ClassLoader = new URLClassLoader(toClasspath(paths), parent)
lazy val rootLoader =
{
def parent(loader: ClassLoader): ClassLoader =
{
val p = loader.getParent
if(p eq null) loader else parent(p)
}
parent(getClass.getClassLoader)
}
private[sbt] def printSource(c: Class[_]) =
println(c.getName + " loader=" +c.getClassLoader + " location=" + FileUtilities.classLocationFile(c))

View File

@ -79,6 +79,7 @@ final class Compile(maximumErrors: Int, compiler: AnalyzingCompiler, analysisCal
protected def processJava(sources: Set[File], classpath: Set[File], outputDirectory: File, options: Seq[String], log: Logger)
{
val arguments = (new CompilerArguments(compiler.scalaInstance))(sources, classpath, outputDirectory, options, true)
log.debug("Calling 'javac' with arguments:\n\t" + arguments.mkString("\n\t"))
val code = Process("javac", arguments) ! log
if( code != 0 ) throw new CompileFailed(arguments.toArray, "javac returned nonzero exit code")
}

View File

@ -310,6 +310,11 @@ abstract class AbstractCompileConditional(val config: AbstractCompileConfigurati
}
})
}
private def scalaJars: Iterable[Path] =
{
val instance = compiler.scalaInstance
Seq(instance.libraryJar, instance.compilerJar).map(Path.fromFile)
}
protected def execute(executeAnalysis: ConditionalAnalysis) =
{
log.info(executeAnalysis.toString)
@ -328,7 +333,7 @@ abstract class AbstractCompileConditional(val config: AbstractCompileConfigurati
val compile = new Compile(config.maxErrors, compiler, analysisCallback, projectPath)
compile(label, dirtySources, cp, outputDirectory, options, javaOptions, compileOrder, log)
}
val loader = ClasspathUtilities.toLoader(cp)
val loader = ClasspathUtilities.toLoader(cp ++ scalaJars)
val r = classfile.Analyze(projectPath, outputDirectory, dirtySources, sourceRoots.get, log)(analysis.allProducts, analysisCallback, loader)(run)
if(log.atLevel(Level.Debug))
{

View File

@ -53,7 +53,7 @@ private[sbt] object Analyze
{
val loaded =
try { Some(Class.forName(tpe, false, loader)) }
catch { case e: NoClassDefFoundError => log.warn("Problem processing dependencies of source " + source + " : " +e.toString); None }
catch { case e => log.warn("Problem processing dependencies of source " + source + " : " +e.toString); None }
for(clazz <- loaded; file <- Control.convertException(FileUtilities.classLocationFile(clazz)).right)
{
if(file.isDirectory)