Properly track anonymous classes generated from Java sources.

git-svn-id: https://simple-build-tool.googlecode.com/svn/trunk@892 d89573ee-9141-11dd-94d4-bdf5e562f29c
This commit is contained in:
dmharrah 2009-07-27 12:51:29 +00:00
parent 443984daf9
commit b6da7c4e5c
2 changed files with 15 additions and 6 deletions

View File

@ -794,7 +794,12 @@ object FileUtilities
/** The directory in which temporary files are placed.*/
val temporaryDirectory = new File(System.getProperty("java.io.tmpdir"))
def classLocation(cl: Class[_]): URL = cl.getProtectionDomain.getCodeSource.getLocation
def classLocation(cl: Class[_]): URL =
{
val codeSource = cl.getProtectionDomain.getCodeSource
if(codeSource == null) null // TODO: return something nicer, probably the location of rt.jar
else codeSource.getLocation
}
def classLocationFile(cl: Class[_]): File = toFile(classLocation(cl))
def classLocation[T](implicit mf: scala.reflect.Manifest[T]): URL = classLocation(mf.erasure)
def classLocationFile[T](implicit mf: scala.reflect.Manifest[T]): File = classLocationFile(mf.erasure)

View File

@ -32,7 +32,7 @@ object Analyze
path <- Path.relativize(outputDirectory, newClass);
classFile = Parser(newClass.asFile, log);
sourceFile <- classFile.sourceFile;
source <- guessSourcePath(sourceSet, roots, classFile.className, log))
source <- guessSourcePath(sourceSet, roots, classFile, log))
{
analysis.beginSource(source)
analysis.generatedClass(source, path)
@ -82,15 +82,19 @@ object Analyze
compile orElse Control.convertErrorMessage(log)(analyze()).left.toOption
}
private def resolveClassFile(file: File, className: String): File = (file /: (className + ".class").split("""\\"""))(new File(_, _))
private def guessSourcePath(sources: scala.collection.Set[Path], roots: Iterable[Path], className: String, log: Logger) =
private def guessSourcePath(sources: scala.collection.Set[Path], roots: Iterable[Path], classFile: ClassFile, log: Logger) =
{
val relativeSourceFile = className.replace('.', '/') + ".java"
val classNameParts = classFile.className.split("""\.""")
val lastIndex = classNameParts.length - 1
val (pkg, simpleClassName) = (classNameParts.take(lastIndex), classNameParts(lastIndex))
val sourceFileName = classFile.sourceFile.getOrElse(simpleClassName.takeWhile(_ != '$').mkString("", "", ".java"))
val relativeSourceFile = (pkg ++ (sourceFileName :: Nil)).mkString("/")
val candidates = roots.map(root => Path.fromString(root, relativeSourceFile)).filter(sources.contains).toList
candidates match
{
case Nil => log.warn("Could not determine source for class " + className)
case Nil => log.warn("Could not determine source for class " + classFile.className)
case head :: Nil => ()
case _ =>log.warn("Multiple sources matched for class " + className + ": " + candidates.mkString(", "))
case _ =>log.warn("Multiple sources matched for class " + classFile.className + ": " + candidates.mkString(", "))
}
candidates
}