From 6b2c36d0eff5b428b5b5659ffb84f8d7b874c2c6 Mon Sep 17 00:00:00 2001 From: dmharrah Date: Sat, 11 Jul 2009 18:48:35 +0000 Subject: [PATCH] * Fixed problem where a dependency on only static members of a Java class was not recorded * Fixed problem where new dependencies on sources not included in the compilation were not added git-svn-id: https://simple-build-tool.googlecode.com/svn/trunk@859 d89573ee-9141-11dd-94d4-bdf5e562f29c --- src/main/scala/sbt/Analysis.scala | 5 +++ src/main/scala/sbt/AnalysisCallback.scala | 42 +++++++++++------------ src/main/scala/sbt/Analyzer.scala | 18 ++++++++-- 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/src/main/scala/sbt/Analysis.scala b/src/main/scala/sbt/Analysis.scala index 4498fd800..898249b26 100644 --- a/src/main/scala/sbt/Analysis.scala +++ b/src/main/scala/sbt/Analysis.scala @@ -95,6 +95,11 @@ sealed class BasicAnalysis(analysisPath: Path, projectPath: Path, log: Logger) e def addSourceDependency(on: Path, from: Path) = add(on, from, sourceDependencyMap) def addExternalDependency(on: File, from: Path) = add(on.getAbsoluteFile, from, externalDependencyMap) + def addProductDependency(on: Path, from: Path) = + { + for( (source, _) <- productMap.find(_._2.contains(on)) ) + addSourceDependency(source, from) + } def addProduct(source: Path, file: Path) = add(source, file, productMap) def addSource(source: Path) = { diff --git a/src/main/scala/sbt/AnalysisCallback.scala b/src/main/scala/sbt/AnalysisCallback.scala index e20d9190b..3578c8942 100644 --- a/src/main/scala/sbt/AnalysisCallback.scala +++ b/src/main/scala/sbt/AnalysisCallback.scala @@ -45,6 +45,12 @@ trait AnalysisCallback extends NotNull /** Called to indicate that the source file sourcePath depends on the class file * classFile.*/ def classDependency(classFile: File, sourcePath: Path): Unit + /** Called to indicate that the source file sourcePath depends on the class file + * classFile that is a product of some source. This differs from classDependency + * because it is really a sourceDependency. The source corresponding to classFile + * was not incuded in the compilation so the plugin doesn't know what the source is though. It + * only knows that the class file came from the output directory.*/ + def productDependency(classFile: Path, sourcePath: Path): Unit /** Called to indicate that the source file sourcePath produces a class file at * modulePath.*/ def generatedClass(sourcePath: Path, modulePath: Path): Unit @@ -58,36 +64,30 @@ abstract class BasicAnalysisCallback[A <: BasicCompileAnalysis](val basePath: Pa { def superclassNotFound(superclassName: String) {} - def beginSource(sourcePath: Path) - { + def beginSource(sourcePath: Path): Unit = analysis.addSource(sourcePath) - } - def sourceDependency(dependsOnPath: Path, sourcePath: Path) - { + + def sourceDependency(dependsOnPath: Path, sourcePath: Path): Unit = analysis.addSourceDependency(dependsOnPath, sourcePath) - } - def jarDependency(jarFile: File, sourcePath: Path) - { + + def jarDependency(jarFile: File, sourcePath: Path): Unit = analysis.addExternalDependency(jarFile, sourcePath) - } - def classDependency(classFile: File, sourcePath: Path) - { + + def classDependency(classFile: File, sourcePath: Path): Unit = analysis.addExternalDependency(classFile, sourcePath) - } - def generatedClass(sourcePath: Path, modulePath: Path) - { + + def productDependency(classFile: Path, sourcePath: Path): Unit = + analysis.addProductDependency(classFile, sourcePath) + + def generatedClass(sourcePath: Path, modulePath: Path): Unit = analysis.addProduct(sourcePath, modulePath) - } - def endSource(sourcePath: Path) - { + + def endSource(sourcePath: Path): Unit = analysis.removeSelfDependency(sourcePath) - } } abstract class BasicCompileAnalysisCallback(basePath: Path, superclassNames: Iterable[String], analysis: CompileAnalysis) extends BasicAnalysisCallback(basePath, superclassNames, analysis) { - def foundApplication(sourcePath: Path, className: String) - { + def foundApplication(sourcePath: Path, className: String): Unit = analysis.addApplication(sourcePath, className) - } } \ No newline at end of file diff --git a/src/main/scala/sbt/Analyzer.scala b/src/main/scala/sbt/Analyzer.scala index 3e45d804a..b1e8a0462 100644 --- a/src/main/scala/sbt/Analyzer.scala +++ b/src/main/scala/sbt/Analyzer.scala @@ -119,9 +119,13 @@ class Analyzer(val global: Global) extends Plugin case ze: ZipArchive#Entry => callback.jarDependency(new File(ze.getArchive.getName), sourcePath) case pf: PlainFile => { - // ignore dependencies in the output directory: these are handled by source dependencies - if(Path.relativize(outputPath, pf.file).isEmpty) - callback.classDependency(pf.file, sourcePath) + Path.relativize(outputPath, pf.file) match + { + case None => // dependency is a class file outside of the output directory + callback.classDependency(pf.file, sourcePath) + case Some(relativeToOutput) => // dependency is a product of a source not included in this compilation + callback.productDependency(relativeToOutput, sourcePath) + } } case _ => () } @@ -182,6 +186,14 @@ class Analyzer(val global: Global) extends Plugin val entry = classPath.root.find(name, false) if (entry ne null) Some(entry.classFile) + else if(isTopLevelModule(sym)) + { + val linked = sym.linkedClassOfModule + if(linked == NoSymbol) + None + else + classFile(linked) + } else None }