From 322e856f132c4ee8ac651848a041b693f830371b Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 2 Jul 2010 20:50:29 +0000 Subject: Routed all places in trunk which look for jar f... Routed all places in trunk which look for jar files through the same function, and then changed the default behavior to recognize jars even if they don't have a *.jar extension by squinting at the first few bytes of the file. Closes #3000 (THE AMAZING TICKET 3000!), review by phaller. --- src/compiler/scala/tools/nsc/io/Path.scala | 7 +++---- src/compiler/scala/tools/nsc/plugins/Plugin.scala | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/compiler/scala/tools/nsc/io/Path.scala b/src/compiler/scala/tools/nsc/io/Path.scala index afef38be3c..4373cc64a5 100644 --- a/src/compiler/scala/tools/nsc/io/Path.scala +++ b/src/compiler/scala/tools/nsc/io/Path.scala @@ -26,15 +26,14 @@ import scala.util.Random.alphanumeric * @since 2.8 */ -object Path -{ +object Path { private val ZipMagicNumber = List[Byte](80, 75, 3, 4) + private def magicNumberIsZip(f: Path) = f.isFile && (f.toFile.bytes().take(4).toList == ZipMagicNumber) /** If examineFile is true, it will look at the first four bytes of the file * and see if the magic number indicates it may be a jar or zip. */ - private def magicNumberIsZip(f: Path) = f.isFile && (f.toFile.bytes().take(4).toList == ZipMagicNumber) - def isJarOrZip(f: Path): Boolean = isJarOrZip(f, false) + def isJarOrZip(f: Path): Boolean = isJarOrZip(f, true) def isJarOrZip(f: Path, examineFile: Boolean): Boolean = f.hasExtension("zip", "jar") || (examineFile && magicNumberIsZip(f)) diff --git a/src/compiler/scala/tools/nsc/plugins/Plugin.scala b/src/compiler/scala/tools/nsc/plugins/Plugin.scala index 1b7e208334..49bbb12a9a 100644 --- a/src/compiler/scala/tools/nsc/plugins/Plugin.scala +++ b/src/compiler/scala/tools/nsc/plugins/Plugin.scala @@ -133,7 +133,7 @@ object Plugin { val alljars = (jars ::: (for { dir <- dirs if dir.isDirectory entry <- dir.toDirectory.files.toList sortBy (_.name) - if entry.extension == "jar" + if Path.isJarOrZip(entry) pdesc <- loadDescription(entry) if !(ignoring contains pdesc.name) } yield entry)).distinct -- cgit v1.2.3