diff options
author | Paul Phillips <paulp@improving.org> | 2010-02-10 19:51:38 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-02-10 19:51:38 +0000 |
commit | 6e76af56f708d345bda2fff580634107945ef3fb (patch) | |
tree | 563058a03d54463fbe9139e8f9f74db23a944400 /src/compiler/scala/tools/nsc/io | |
parent | 06ae221de943d7258dfa2ffcbc6c59fe9493497f (diff) | |
download | scala-6e76af56f708d345bda2fff580634107945ef3fb.tar.gz scala-6e76af56f708d345bda2fff580634107945ef3fb.tar.bz2 scala-6e76af56f708d345bda2fff580634107945ef3fb.zip |
More work on classpaths.
to have command line options following source files, at the price of
temporarily breaking tools/pathResolver. Working my way through all the
usages of classpath in trunk zeroing in on fully consistent handling.
Review by community.
Diffstat (limited to 'src/compiler/scala/tools/nsc/io')
-rw-r--r-- | src/compiler/scala/tools/nsc/io/AbstractFile.scala | 3 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/Path.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/Socket.scala | 14 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/Streamable.scala | 2 |
4 files changed, 19 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/io/AbstractFile.scala b/src/compiler/scala/tools/nsc/io/AbstractFile.scala index 15a05aa3fc..af93cafb68 100644 --- a/src/compiler/scala/tools/nsc/io/AbstractFile.scala +++ b/src/compiler/scala/tools/nsc/io/AbstractFile.scala @@ -109,6 +109,9 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] { if (file ne null) file.exists else true + /** Does this abstract file represent something which can contain classfiles? */ + def isClassContainer = isDirectory || Path.isJarOrZip(sfile) + /** Create a file on disk, if one does not exist already. */ def create: Unit diff --git a/src/compiler/scala/tools/nsc/io/Path.scala b/src/compiler/scala/tools/nsc/io/Path.scala index 39fba8bcb2..2b7f2620d6 100644 --- a/src/compiler/scala/tools/nsc/io/Path.scala +++ b/src/compiler/scala/tools/nsc/io/Path.scala @@ -141,6 +141,8 @@ class Path private[io] (val jfile: JFile) } // compares against extension in a CASE INSENSITIVE way. def hasExtension(other: String) = extension.toLowerCase == other.toLowerCase + // returns the filename without the extension. + def stripExtension: String = name stripSuffix ("." + extension) // conditionally execute def ifFile[T](f: File => T): Option[T] = if (isFile) Some(f(toFile)) else None diff --git a/src/compiler/scala/tools/nsc/io/Socket.scala b/src/compiler/scala/tools/nsc/io/Socket.scala index 18ccbda7a2..e883c71b8e 100644 --- a/src/compiler/scala/tools/nsc/io/Socket.scala +++ b/src/compiler/scala/tools/nsc/io/Socket.scala @@ -6,7 +6,7 @@ package scala.tools.nsc package io -import java.io.{ IOException } +import java.io.{ IOException, InputStreamReader, BufferedReader, PrintWriter } import java.net.{ URL, MalformedURLException } import java.net.{ InetAddress, Socket => JSocket } import scala.util.control.Exception._ @@ -31,4 +31,16 @@ class Socket(jsocket: JSocket) { def getInputStream() = jsocket.getInputStream() def getPort() = jsocket.getPort() def close() = jsocket.close() + + /** Creates an InputStream and applies the closure, automatically closing it on completion. + */ + def applyReaderAndWriter[T](f: (BufferedReader, PrintWriter) => T): T = { + val out = new PrintWriter(getOutputStream(), true) + val in = new BufferedReader(new InputStreamReader(getInputStream())) + try f(in, out) + finally { + in.close() + out.close() + } + } }
\ No newline at end of file diff --git a/src/compiler/scala/tools/nsc/io/Streamable.scala b/src/compiler/scala/tools/nsc/io/Streamable.scala index a55028bc25..ff4520e3ca 100644 --- a/src/compiler/scala/tools/nsc/io/Streamable.scala +++ b/src/compiler/scala/tools/nsc/io/Streamable.scala @@ -101,7 +101,7 @@ object Streamable */ def bufferedReader(codec: Codec = getCodec()) = new BufferedReader(reader(codec)) - /** Creates an InputStream and applies the closure, automatically closing it on completion. + /** Creates a BufferedReader and applies the closure, automatically closing it on completion. */ def applyReader[T](f: BufferedReader => T): T = { val in = bufferedReader() |