Permalink
Browse files

Merge pull request #433 from vigdorchik/optimize_java_compile

Do not load classes for dependencies since having URLs is enough.
  • Loading branch information...
2 parents 2bd103f + cbb1e3d commit 2e868e6d672ad39147a1f9f1a7d24dce06248a34 @harrah committed Apr 19, 2012
Showing with 14 additions and 19 deletions.
  1. +14 −19 util/classfile/Analyze.scala
View
33 util/classfile/Analyze.scala
@@ -53,32 +53,28 @@ private[sbt] object Analyze
{
trapAndLog(log)
{
- val loaded = load(tpe, Some("Problem processing dependencies of source " + source))
- for(clazz <- loaded; file <- ErrorHandling.convert(IO.classLocationFile(clazz)).right)
+ for (url <- Option(loader.getResource(tpe.replace('.', '/') + ClassExt)); file <- IO.urlAsFile(url))
{
- val name = clazz.getName
- if(file.isDirectory)
+ val name = {
+ val lastDot = tpe.lastIndexOf('.')
+ if (lastDot < 0) tpe else tpe.substring(lastDot + 1)
+ }
+ if(url.getProtocol == "jar")
+ analysis.binaryDependency(file, name, source)
+ else
{
- val resolved = resolveClassFile(file, tpe)
- assume(resolved.exists, "Resolved class file " + resolved + " from " + source + " did not exist")
- if(file == outputDirectory)
+ assume(url.getProtocol == "file")
+ productToSource.get(file) match
{
- productToSource.get(resolved) match
- {
- case Some(dependsOn) => analysis.sourceDependency(dependsOn, source)
- case None => analysis.binaryDependency(resolved, clazz.getName, source)
- }
+ case Some(dependsOn) => analysis.sourceDependency(dependsOn, source)
+ case None => analysis.binaryDependency(file, name, source)
}
- else
- analysis.binaryDependency(resolved, name, source)
}
- else
- analysis.binaryDependency(file, name, source)
}
}
}
- classFiles.flatMap(_.types).foreach(processDependency)
+ classFiles.flatMap(_.types).toSet.foreach(processDependency)
readAPI(source, classFiles.toSeq.flatMap(c => load(c.className, Some("Error reading API from class file") )))
analysis.endSource(source)
}
@@ -106,7 +102,6 @@ private[sbt] object Analyze
}
private final val ClassExt = ".class"
private def trimClassExt(name: String) = if(name.endsWith(ClassExt)) name.substring(0, name.length - ClassExt.length) else name
- private def resolveClassFile(file: File, className: String): File = (file /: (className.replace('.','/') + ClassExt).split("/"))(new File(_, _))
private def guessSourcePath(sourceNameMap: Map[String, Set[File]], classFile: ClassFile, log: Logger) =
{
val classNameParts = classFile.className.split("""\.""")
@@ -168,4 +163,4 @@ private[sbt] object Analyze
private val mainModifiers = STATIC | PUBLIC
private val notMainModifiers = ABSTRACT
-}
+}

0 comments on commit 2e868e6

Please sign in to comment.