summaryrefslogtreecommitdiff
path: root/src/reflect/scala/reflect/io/ZipArchive.scala
diff options
context:
space:
mode:
authormpociecha <michal.pociecha@gmail.com>2014-11-30 13:14:10 +0100
committermpociecha <michal.pociecha@gmail.com>2014-11-30 22:31:32 +0100
commit9fe0c8cc824f938fe4303caa668a5d3f267d1223 (patch)
treeecd3334fa284b9a3e544223e09a6880ecdc8a45e /src/reflect/scala/reflect/io/ZipArchive.scala
parent3b585e901040e6a820e8533c5a818b7096b9625e (diff)
downloadscala-9fe0c8cc824f938fe4303caa668a5d3f267d1223.tar.gz
scala-9fe0c8cc824f938fe4303caa668a5d3f267d1223.tar.bz2
scala-9fe0c8cc824f938fe4303caa668a5d3f267d1223.zip
Add flat classpath implementation for zip and jar files
This commit adds an implementation of flat classpath which can handle both jar and vanilla zip files. In fact there are two versions - for a class- and a sourcepath. Both extend ZipArchiveFileLookup which provides common logic. They use FileZipArchive. @gkossakowski made a comparison of different ways of handling zips and jars (e.g. using javac's ZipFileIndex). He stated that general efficiency of FileZipArchive, taking into account various parameters, is the best. FileZipArchive is slightly changed. From now it allows to find the entry for directory in all directory entries without iterating all entries regardless of a type. Thanks to that we can simply find a directory for a package - like in the case of DirectoryFileLookup. There's also added possibility to cache classpath representation of classpath elements from jar and zip files across compiler instances. The cache is just a map AbstractFile -> FlatClassPath. It should reduce the number of created classpath and file instances e.g. in the case of many ScalaPresentationCompilers in Scala IDE. To prevent the possibility to avoid a cache, caches are created as a part of factories responsible for the creation of these types of the flat classpath.
Diffstat (limited to 'src/reflect/scala/reflect/io/ZipArchive.scala')
-rw-r--r--src/reflect/scala/reflect/io/ZipArchive.scala13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/reflect/scala/reflect/io/ZipArchive.scala b/src/reflect/scala/reflect/io/ZipArchive.scala
index 8260189459..dc2ec848b1 100644
--- a/src/reflect/scala/reflect/io/ZipArchive.scala
+++ b/src/reflect/scala/reflect/io/ZipArchive.scala
@@ -125,14 +125,15 @@ abstract class ZipArchive(override val file: JFile) extends AbstractFile with Eq
}
/** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
final class FileZipArchive(file: JFile) extends ZipArchive(file) {
- def iterator: Iterator[Entry] = {
+ lazy val (root, allDirs) = {
+ val root = new DirEntry("/")
+ val dirs = mutable.HashMap[String, DirEntry]("/" -> root)
val zipFile = try {
new ZipFile(file)
} catch {
case ioe: IOException => throw new IOException("Error accessing " + file.getPath, ioe)
}
- val root = new DirEntry("/")
- val dirs = mutable.HashMap[String, DirEntry]("/" -> root)
+
val enum = zipFile.entries()
while (enum.hasMoreElements) {
@@ -150,11 +151,11 @@ final class FileZipArchive(file: JFile) extends ZipArchive(file) {
dir.entries(f.name) = f
}
}
-
- try root.iterator
- finally dirs.clear()
+ (root, dirs)
}
+ def iterator: Iterator[Entry] = root.iterator
+
def name = file.getName
def path = file.getPath
def input = File(file).inputStream()