From 77001a4259b14a93419bd3a576ade51f670b1185 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Tue, 9 Apr 2013 20:13:06 -0400 Subject: [PATCH] drop canonicalization of files on classpath and other cleanup. Fixes #723. --- .../src/main/scala/sbt/inc/Incremental.scala | 2 +- .../inc/src/main/scala/sbt/inc/Locate.scala | 2 +- .../sbt/compiler/AggressiveCompile.scala | 2 +- .../scala/xsbt/test/TestScriptParser.scala | 6 +- .../src/main/scala/sbt/classfile/Parser.scala | 2 +- .../sbt/classpath/ClasspathUtilities.scala | 57 ++++--------------- 6 files changed, 19 insertions(+), 52 deletions(-) diff --git a/compile/inc/src/main/scala/sbt/inc/Incremental.scala b/compile/inc/src/main/scala/sbt/inc/Incremental.scala index f9d4f2da1..561ed15b7 100644 --- a/compile/inc/src/main/scala/sbt/inc/Incremental.scala +++ b/compile/inc/src/main/scala/sbt/inc/Incremental.scala @@ -261,7 +261,7 @@ object Incremental dependsOn => { def inv(reason: String): Boolean = { - log.debug("Invalidating " + dependsOn.getCanonicalPath + ": " + reason) + log.debug("Invalidating " + dependsOn + ": " + reason) true } def entryModified(className: String, classpathEntry: File): Boolean = diff --git a/compile/inc/src/main/scala/sbt/inc/Locate.scala b/compile/inc/src/main/scala/sbt/inc/Locate.scala index 87a032624..cb485f28a 100644 --- a/compile/inc/src/main/scala/sbt/inc/Locate.scala +++ b/compile/inc/src/main/scala/sbt/inc/Locate.scala @@ -50,7 +50,7 @@ object Locate def definesClass(entry: File): String => Boolean = if(entry.isDirectory) directoryDefinesClass(entry) - else if(entry.exists && classpath.ClasspathUtilities.isArchive(entry)) + else if(entry.exists && classpath.ClasspathUtilities.isArchive(entry, contentFallback=true)) jarDefinesClass(entry) else const(false) diff --git a/compile/integration/src/main/scala/sbt/compiler/AggressiveCompile.scala b/compile/integration/src/main/scala/sbt/compiler/AggressiveCompile.scala index 67d0ddd8e..b33db6d84 100644 --- a/compile/integration/src/main/scala/sbt/compiler/AggressiveCompile.scala +++ b/compile/integration/src/main/scala/sbt/compiler/AggressiveCompile.scala @@ -77,7 +77,7 @@ class AggressiveCompile(cacheFile: File) { import config._ import currentSetup._ - val absClasspath = classpath.map(_.getCanonicalFile) + val absClasspath = classpath.map(_.getAbsoluteFile) val apiOption = (api: Either[Boolean, Source]) => api.right.toOption val cArgs = new CompilerArguments(compiler.scalaInstance, compiler.cp) val searchClasspath = explicitBootClasspath(options.options) ++ withBootclasspath(cArgs, absClasspath) diff --git a/scripted/base/src/main/scala/xsbt/test/TestScriptParser.scala b/scripted/base/src/main/scala/xsbt/test/TestScriptParser.scala index 82ab5cb0f..52a71b338 100644 --- a/scripted/base/src/main/scala/xsbt/test/TestScriptParser.scala +++ b/scripted/base/src/main/scala/xsbt/test/TestScriptParser.scala @@ -18,7 +18,7 @@ word ::= [^ \[\]]+ comment ::= '#' \S* nl nl ::= '\r' \'n' | '\n' | '\r' | eof */ -final case class Statement(command: String, arguments: List[String], successExpected: Boolean, line: Int) extends NotNull +final case class Statement(command: String, arguments: List[String], successExpected: Boolean, line: Int) { def linePrefix = "{line " + line + "} " } @@ -31,7 +31,7 @@ private object TestScriptParser } import TestScriptParser._ -class TestScriptParser(handlers: Map[Char, StatementHandler]) extends RegexParsers with NotNull +class TestScriptParser(handlers: Map[Char, StatementHandler]) extends RegexParsers { require(!handlers.isEmpty) override def skipWhitespace = false @@ -42,7 +42,7 @@ class TestScriptParser(handlers: Map[Char, StatementHandler]) extends RegexParse if(handlers.keys.exists(key => key == '+' || key == '-')) sys.error("Start characters cannot be '+' or '-'") - def parse(scriptFile: File): List[(StatementHandler, Statement)] = parse(read(scriptFile), Some(scriptFile.getCanonicalPath)) + def parse(scriptFile: File): List[(StatementHandler, Statement)] = parse(read(scriptFile), Some(scriptFile.getAbsolutePath)) def parse(script: String): List[(StatementHandler, Statement)] = parse(script, None) private def parse(script: String, label: Option[String]): List[(StatementHandler, Statement)] = { diff --git a/util/classfile/src/main/scala/sbt/classfile/Parser.scala b/util/classfile/src/main/scala/sbt/classfile/Parser.scala index 187740280..26b753835 100644 --- a/util/classfile/src/main/scala/sbt/classfile/Parser.scala +++ b/util/classfile/src/main/scala/sbt/classfile/Parser.scala @@ -16,7 +16,7 @@ import Constants._ private[sbt] object Parser { - def apply(file: File): ClassFile = Using.fileInputStream(file)(parse(file.getCanonicalPath)).right.get + def apply(file: File): ClassFile = Using.fileInputStream(file)(parse(file.getAbsolutePath)).right.get private def parse(fileName: String)(is: InputStream): Either[String, ClassFile] = Right(parseImpl(fileName, is)) private def parseImpl(filename: String, is: InputStream): ClassFile = { diff --git a/util/classpath/src/main/scala/sbt/classpath/ClasspathUtilities.scala b/util/classpath/src/main/scala/sbt/classpath/ClasspathUtilities.scala index 83cda6beb..ff987f113 100644 --- a/util/classpath/src/main/scala/sbt/classpath/ClasspathUtilities.scala +++ b/util/classpath/src/main/scala/sbt/classpath/ClasspathUtilities.scala @@ -74,24 +74,19 @@ object ClasspathUtilities private[sbt] def printSource(c: Class[_]) = println(c.getName + " loader=" +c.getClassLoader + " location=" + IO.classLocationFile(c)) - def isArchive(file: File): Boolean = isArchiveName(file.getName) + def isArchive(file: File, contentFallback: Boolean = false): Boolean = + file.isFile && (isArchiveName(file.getName) || (contentFallback && hasZipContent(file))) + def isArchiveName(fileName: String) = fileName.endsWith(".jar") || fileName.endsWith(".zip") - // Partitions the given classpath into (jars, directories) - private[sbt] def separate(paths: Iterable[File]): (Iterable[File], Iterable[File]) = paths.partition(isArchive) - // Partitions the given classpath into (jars, directories) - private[sbt] def buildSearchPaths(classpath: Iterable[File]): (collection.Set[File], collection.Set[File]) = - { - val (jars, dirs) = separate(classpath) - (linkedSet(jars ++ extraJars), linkedSet(dirs ++ extraDirs)) - } - private[sbt] def onClasspath(classpathJars: collection.Set[File], classpathDirectories: collection.Set[File], file: File): Boolean = - { - val f = file.getCanonicalFile - if(ClasspathUtilities.isArchive(f)) - classpathJars(f) - else - classpathDirectories.toList.find(Path.relativize(_, f).isDefined).isDefined - } + + def hasZipContent(file: File): Boolean = try { + Using.fileInputStream(file) { in => + (in.read() == 0x50) && + (in.read() == 0x4b) && + (in.read() == 0x03) && + (in.read() == 0x04) + } + } catch { case e: Exception => false } /** Returns all entries in 'classpath' that correspond to a compiler plugin.*/ private[sbt] def compilerPlugins(classpath: Seq[File]): Iterable[File] = @@ -118,32 +113,4 @@ object ClasspathUtilities } catch { case e: Exception => Nil } } - - private lazy val (extraJars, extraDirs) = - { - import scala.tools.nsc.GenericRunnerCommand - val settings = (new GenericRunnerCommand(Nil, message => sys.error(message))).settings - val bootPaths = IO.pathSplit(settings.bootclasspath.value).map(p => new File(p)).toList - val (bootJars, bootDirs) = separate(bootPaths) - val extJars = - { - val buffer = new ListBuffer[File] - def findJars(dir: File) - { - buffer ++= dir.listFiles(new SimpleFileFilter(isArchive)) - for(dir <- dir.listFiles(DirectoryFilter)) - findJars(dir) - } - for(path <- IO.pathSplit(settings.extdirs.value); dir = new File(path) if dir.isDirectory) - findJars(dir) - buffer.readOnly.map(_.getCanonicalFile) - } - (linkedSet(extJars ++ bootJars), linkedSet(bootDirs)) - } - private def linkedSet[T](s: Iterable[T]): Set[T] = - { - val set: mutable.Set[T] = JavaConversions.asScalaSet(new java.util.LinkedHashSet[T]) - set ++= s - set - } }