diff options
author | Paul Phillips <paulp@improving.org> | 2010-03-26 04:26:03 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-03-26 04:26:03 +0000 |
commit | 2bf117c3b2545856ace3d2dd23e5fffad199bac9 (patch) | |
tree | a72d6ec99bd04abb89d89a1d49cfad036d5e7ae8 | |
parent | f427b1e67d63dfe49d8b0dd25265c721ce5851cc (diff) | |
download | scala-2bf117c3b2545856ace3d2dd23e5fffad199bac9.tar.gz scala-2bf117c3b2545856ace3d2dd23e5fffad199bac9.tar.bz2 scala-2bf117c3b2545856ace3d2dd23e5fffad199bac9.zip |
Some minor I/O changes. No review.
-rw-r--r-- | src/compiler/scala/tools/ant/sabbus/ScalacFork.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/CompileSocket.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ScriptRunner.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/Directory.scala | 1 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/File.scala | 10 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/Path.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/util/ClassPath.scala | 5 |
7 files changed, 17 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/ant/sabbus/ScalacFork.scala b/src/compiler/scala/tools/ant/sabbus/ScalacFork.scala index 5b64369a2f..353499ddb3 100644 --- a/src/compiler/scala/tools/ant/sabbus/ScalacFork.scala +++ b/src/compiler/scala/tools/ant/sabbus/ScalacFork.scala @@ -109,7 +109,7 @@ class ScalacFork extends MatchingTask with ScalacShared with TaskArgs { // dump the arguments to a file and do "java @file" val tempArgFile = io.File.makeTemp("scalacfork") val tokens = settings.toArgs ++ (includedFiles map (_.getPath)) - tempArgFile writeAll List(tokens mkString " ") + tempArgFile writeAll (tokens mkString " ") val paths = List(Some(tempArgFile.toAbsolute.path), argfile).flatten map (_.toString) val res = execWithArgFiles(java, paths) diff --git a/src/compiler/scala/tools/nsc/CompileSocket.scala b/src/compiler/scala/tools/nsc/CompileSocket.scala index 8d599c6c96..d4697b69e6 100644 --- a/src/compiler/scala/tools/nsc/CompileSocket.scala +++ b/src/compiler/scala/tools/nsc/CompileSocket.scala @@ -129,7 +129,7 @@ class CompileSocket { val file = portFile(port) val secret = new SecureRandom().nextInt.toString - try file writeAll List(secret) catch { + try file writeAll secret catch { case e @ (_: FileNotFoundException | _: SecurityException) => fatal("Cannot create file: %s".format(file.path)) } diff --git a/src/compiler/scala/tools/nsc/ScriptRunner.scala b/src/compiler/scala/tools/nsc/ScriptRunner.scala index 51e85eaf95..adf442fc0e 100644 --- a/src/compiler/scala/tools/nsc/ScriptRunner.scala +++ b/src/compiler/scala/tools/nsc/ScriptRunner.scala @@ -338,7 +338,7 @@ object ScriptRunner { val scriptFile = File.makeTemp("scalacmd", ".scala") // save the command to the file - scriptFile writeAll List(command) + scriptFile writeAll command try withCompiledScript(settings, scriptFile.path) { runCompiled(settings, _, scriptArgs) } finally scriptFile.delete() // in case there was a compilation error diff --git a/src/compiler/scala/tools/nsc/io/Directory.scala b/src/compiler/scala/tools/nsc/io/Directory.scala index b8ce6e5355..2c7f5e1059 100644 --- a/src/compiler/scala/tools/nsc/io/Directory.scala +++ b/src/compiler/scala/tools/nsc/io/Directory.scala @@ -37,6 +37,7 @@ import Path._ * @since 2.8 */ class Directory(jfile: JFile) extends Path(jfile) { + override def toAbsolute: Directory = if (isAbsolute) this else super.toAbsolute.toDirectory override def toDirectory: Directory = this override def toFile: File = new File(jfile) override def isValid = jfile.isDirectory() || !jfile.exists() diff --git a/src/compiler/scala/tools/nsc/io/File.scala b/src/compiler/scala/tools/nsc/io/File.scala index 74446a699d..67d39fd742 100644 --- a/src/compiler/scala/tools/nsc/io/File.scala +++ b/src/compiler/scala/tools/nsc/io/File.scala @@ -52,6 +52,8 @@ class File(jfile: JFile)(implicit val creationCodec: Codec = null) extends Path(jfile) with Streamable.Chars { def withCodec(codec: Codec): File = new File(jfile)(codec) + override def addExtension(ext: String): File = super.addExtension(ext).toFile + override def toAbsolute: File = if (isAbsolute) this else super.toAbsolute.toFile override def toDirectory: Directory = new Directory(jfile) override def toFile: File = this override def normalize: File = super.normalize.toFile @@ -78,10 +80,10 @@ with Streamable.Chars { def bufferedWriter(append: Boolean = false, codec: Codec = getCodec()) = new BufferedWriter(writer(append, codec)) - /** Writes all the Strings in the given iterator to the file. */ - def writeAll(xs: Traversable[String], append: Boolean = false, codec: Codec = getCodec()): Unit = { - val out = bufferedWriter(append, codec) - try xs foreach (out write _) + /** Creates a new file and writes all the Strings to it. */ + def writeAll(strings: String*): Unit = { + val out = bufferedWriter() + try strings foreach (out write _) finally out close } diff --git a/src/compiler/scala/tools/nsc/io/Path.scala b/src/compiler/scala/tools/nsc/io/Path.scala index 98d981f65e..2b5acaed0c 100644 --- a/src/compiler/scala/tools/nsc/io/Path.scala +++ b/src/compiler/scala/tools/nsc/io/Path.scala @@ -159,9 +159,11 @@ class Path private[io] (val jfile: JFile) { case idx => name drop (idx + 1) } // compares against extension in a CASE INSENSITIVE way. - def hasExtension(other: String) = extension.toLowerCase == other.toLowerCase + def hasExtension(ext: String) = extension.toLowerCase == ext.toLowerCase // returns the filename without the extension. def stripExtension: String = name stripSuffix ("." + extension) + // returns the Path with the extension. + def addExtension(ext: String): Path = Path(path + "." + ext) // 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/util/ClassPath.scala b/src/compiler/scala/tools/nsc/util/ClassPath.scala index 9ec9bf584f..f54fb4d0a2 100644 --- a/src/compiler/scala/tools/nsc/util/ClassPath.scala +++ b/src/compiler/scala/tools/nsc/util/ClassPath.scala @@ -71,7 +71,7 @@ object ClassPath { def split(path: String): List[String] = (path split pathSeparator).toList filterNot (_ == "") distinct /** Join classpath using platform-dependent path separator */ - def join(path: String*): String = path filterNot (_ == "") mkString pathSeparator + def join(paths: String*): String = paths filterNot (_ == "") mkString pathSeparator /** Split the classpath, apply a transformation function, and reassemble it. */ def map(cp: String, f: String => String): String = join(split(cp) map f: _*) @@ -82,6 +82,9 @@ object ClassPath { /** Split the classpath and map them into Paths */ def toPaths(cp: String): List[Path] = split(cp) map (x => Path(x).toAbsolute) + /** Join the paths as a classpath */ + def fromPaths(paths: Path*): String = join(paths map (_.path): _*) + /** Split the classpath and map them into URLs */ def toURLs(cp: String): List[URL] = toPaths(cp) map (_.toURL) |