diff options
author | Iulian Dragos <jaguarul@gmail.com> | 2009-05-29 14:16:24 +0000 |
---|---|---|
committer | Iulian Dragos <jaguarul@gmail.com> | 2009-05-29 14:16:24 +0000 |
commit | 9636749e637088f8ba149b73620535cd1992614a (patch) | |
tree | 86882e4a89a8ee60609f36b5dc0d4e4c20f368d5 /src/compiler/scala/tools/nsc/io | |
parent | 036f2602017bf04dc3a40783a531d488bbd9e12a (diff) | |
download | scala-9636749e637088f8ba149b73620535cd1992614a.tar.gz scala-9636749e637088f8ba149b73620535cd1992614a.tar.bz2 scala-9636749e637088f8ba149b73620535cd1992614a.zip |
Refactored the existing dependency tracker and ...
Refactored the existing dependency tracker and added a 'build manager'
interface for IDE use.
Diffstat (limited to 'src/compiler/scala/tools/nsc/io')
-rw-r--r-- | src/compiler/scala/tools/nsc/io/AbstractFile.scala | 38 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/PlainFile.scala | 28 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/VirtualDirectory.scala | 19 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/VirtualFile.scala | 18 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/ZipArchive.scala | 24 |
5 files changed, 124 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/io/AbstractFile.scala b/src/compiler/scala/tools/nsc/io/AbstractFile.scala index 7414a6ca27..70121aefb9 100644 --- a/src/compiler/scala/tools/nsc/io/AbstractFile.scala +++ b/src/compiler/scala/tools/nsc/io/AbstractFile.scala @@ -102,12 +102,26 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] { /** Returns the path of this abstract file. */ def path: String + /** The absolute file, if this is a relative file. */ + def absolute: AbstractFile + /** Returns the containing directory of this abstract file */ def container : AbstractFile /** Returns the underlying File if any and null otherwise. */ def file: File + /** Does this abstract file denote an existing file? */ + def exists: Boolean = + if (file ne null) file.exists() + else true + + /** Create a file on disk, if one does not exist already. */ + def create: Unit + + /** Delete the underlying file or directory (recursively). */ + def delete: Unit + /** Is this abstract file a directory? */ def isDirectory: Boolean @@ -164,6 +178,11 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] { */ def lookupName(name: String, directory: Boolean): AbstractFile + /** Returns an abstract file with the given name. It does not + * check that it exists. + */ + def lookupNameUnchecked(name: String, directory: Boolean): AbstractFile + /** Returns the abstract file in this abstract directory with the specified * path relative to it, If there is no such file, returns null. The argument * <code>directory</code> tells whether to look for a directory or a regular @@ -174,8 +193,23 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] { * @return ... */ def lookupPath(path: String, directory: Boolean): AbstractFile = { - val length = path.length() + lookup((f, p, dir) => f.lookupName(p, dir), path, directory) + } + + /** Return an abstract file that does not check that `path' denotes + * an existing file. + */ + def lookupPathUnchecked(path: String, directory: Boolean): AbstractFile = { + lookup((f, p, dir) => f.lookupNameUnchecked(p, dir), path, directory) + } + + private def lookup(getFile: (AbstractFile, String, Boolean) => AbstractFile, + path0: String, + directory: Boolean): AbstractFile = { val separator = File.separatorChar + // trim trailing '/'s + val path = if (path0.charAt(path0.length - 1) == separator) path0.substring(0, path0.length - 1) else path0 + val length = path.length() assert(0 < length && path.lastIndexOf(separator) < length - 1, path) var file = this var start = 0 @@ -183,7 +217,7 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] { val index = path.indexOf(separator, start) assert(index < 0 || start < index) val name = path.substring(start, if (index < 0) length else index) - file = file.lookupName(name, if (index < 0) directory else true) + file = getFile(file, name, if (index < 0) directory else true) if ((file eq null) || index < 0) return file start = index + 1 } diff --git a/src/compiler/scala/tools/nsc/io/PlainFile.scala b/src/compiler/scala/tools/nsc/io/PlainFile.scala index 6b11295d49..aa839d5892 100644 --- a/src/compiler/scala/tools/nsc/io/PlainFile.scala +++ b/src/compiler/scala/tools/nsc/io/PlainFile.scala @@ -26,7 +26,7 @@ class PlainFile(val file: File) extends AbstractFile { catch { case _: IOException => file.getAbsolutePath } assert(file ne null) - assert(file.exists(), "non-existent file: " + file) +// assert(file.exists(), "non-existent file: " + file) /** Returns the name of this abstract file. */ def name = file.getName() @@ -34,6 +34,9 @@ class PlainFile(val file: File) extends AbstractFile { /** Returns the path of this abstract file. */ def path = file.getPath() + /** The absolute file. */ + def absolute = new PlainFile(file.getCanonicalFile()) + override def container : AbstractFile = new PlainFile(file.getParentFile) override def input = new FileInputStream(file) @@ -80,4 +83,27 @@ class PlainFile(val file: File) extends AbstractFile { else new PlainFile(child) } + /** Does this abstract file denote an existing file? */ + def create { + if (!exists) + file.createNewFile() + } + + /** Delete the underlying file or directory (recursively). */ + def delete { + if (file.isFile) file.delete + else if (file.isDirectory) { + elements.foreach(_.delete) + file.delete + } + } + + /** Returns a plain file with the given name. It does not + * check that it exists. + */ + def lookupNameUnchecked(name: String, directory: Boolean): AbstractFile = { + val f = new File(file, name) + new PlainFile(f) + } + } diff --git a/src/compiler/scala/tools/nsc/io/VirtualDirectory.scala b/src/compiler/scala/tools/nsc/io/VirtualDirectory.scala index 403d59d289..53346df53c 100644 --- a/src/compiler/scala/tools/nsc/io/VirtualDirectory.scala +++ b/src/compiler/scala/tools/nsc/io/VirtualDirectory.scala @@ -17,6 +17,9 @@ extends AbstractFile { case None => name case Some(parent) => parent.path+'/'+ name } + + def absolute = this + def container = maybeContainer.get def isDirectory = true var lastModified: Long = System.currentTimeMillis @@ -27,6 +30,22 @@ extends AbstractFile { override def input = error("directories cannot be read") override def output = error("directories cannot be written") + /** Does this abstract file denote an existing file? */ + def create { + throw new UnsupportedOperationException + } + + /** Delete the underlying file or directory (recursively). */ + def delete { + throw new UnsupportedOperationException + } + + /** Returns an abstract file with the given name. It does not + * check that it exists. + */ + def lookupNameUnchecked(name: String, directory: Boolean): AbstractFile = + throw new UnsupportedOperationException() + private val files = mut.Map.empty[String, AbstractFile] // the toList is so that the directory may continue to be diff --git a/src/compiler/scala/tools/nsc/io/VirtualFile.scala b/src/compiler/scala/tools/nsc/io/VirtualFile.scala index 0b9c703757..ba86a165f7 100644 --- a/src/compiler/scala/tools/nsc/io/VirtualFile.scala +++ b/src/compiler/scala/tools/nsc/io/VirtualFile.scala @@ -47,6 +47,8 @@ class VirtualFile(val name: String, _path: String) extends AbstractFile { def path = _path + def absolute = this + /** Returns null. */ final def file: File = null @@ -77,6 +79,16 @@ class VirtualFile(val name: String, _path: String) extends AbstractFile { Iterator.empty } + /** Does this abstract file denote an existing file? */ + def create { + throw new UnsupportedOperationException + } + + /** Delete the underlying file or directory (recursively). */ + def delete { + throw new UnsupportedOperationException + } + /** * Returns the abstract file in this abstract directory with the * specified name. If there is no such file, returns null. The @@ -92,5 +104,11 @@ class VirtualFile(val name: String, _path: String) extends AbstractFile { null } + /** Returns an abstract file with the given name. It does not + * check that it exists. + */ + def lookupNameUnchecked(name: String, directory: Boolean): AbstractFile = + throw new UnsupportedOperationException() + //######################################################################## } diff --git a/src/compiler/scala/tools/nsc/io/ZipArchive.scala b/src/compiler/scala/tools/nsc/io/ZipArchive.scala index ab730128bd..c380acd9a3 100644 --- a/src/compiler/scala/tools/nsc/io/ZipArchive.scala +++ b/src/compiler/scala/tools/nsc/io/ZipArchive.scala @@ -101,6 +101,12 @@ final class ZipArchive(file: File, val archive: ZipFile) extends PlainFile(file) root.lookupName(name, directory) } + /** Returns an abstract file with the given name. It does not + * check that it exists. + */ + override def lookupNameUnchecked(name: String, directory: Boolean): AbstractFile = + throw new UnsupportedOperationException() + //######################################################################## // Private Methods @@ -231,12 +237,24 @@ final class URLZipArchive(url: URL) extends AbstractFile { def file: File = null + def absolute: AbstractFile = this + def isDirectory: Boolean = true def lastModified: Long = try { url.openConnection().getLastModified() } catch { case _ => 0 } + /** Does this abstract file denote an existing file? */ + def create { + throw new UnsupportedOperationException + } + + /** Delete the underlying file or directory (recursively). */ + def delete { + throw new UnsupportedOperationException + } + def input: InputStream = url.openStream() def output = throw new Error("unsupported") @@ -251,6 +269,12 @@ final class URLZipArchive(url: URL) extends AbstractFile { root.lookupName(name, directory) } + /** Returns an abstract file with the given name. It does not + * check that it exists. + */ + def lookupNameUnchecked(name: String, directory: Boolean): AbstractFile = + throw new UnsupportedOperationException() + private def load() { def getEntryInputStream(in: InputStream): InputStream = { val buf = new scala.collection.mutable.ArrayBuffer[Byte] |