diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/io')
-rw-r--r-- | src/compiler/scala/tools/nsc/io/NullPrintStream.scala | 37 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/Sources.scala | 86 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/package.scala | 3 |
3 files changed, 0 insertions, 126 deletions
diff --git a/src/compiler/scala/tools/nsc/io/NullPrintStream.scala b/src/compiler/scala/tools/nsc/io/NullPrintStream.scala deleted file mode 100644 index 52c7ddc74b..0000000000 --- a/src/compiler/scala/tools/nsc/io/NullPrintStream.scala +++ /dev/null @@ -1,37 +0,0 @@ -/* NSC -- new Scala compiler - * Copyright 2005-2011 LAMP/EPFL - * @author Paul Phillips - */ - -package scala.tools.nsc -package io - -import java.io.{ PrintStream, ByteArrayOutputStream } - -/** A sink for when you want to discard all output. - */ -class NullPrintStream extends PrintStream(new ByteArrayOutputStream()) { } - -object NullPrintStream extends NullPrintStream { - def setOut() = Console setOut this - def setErr() = Console setErr this - def setOutAndErr() = { setOut() ; setErr() } - def sinkingOutAndErr[T](body: => T): T = - Console.withOut(this) { - Console.withErr(this) { - body - } - } - - def sinkingSystemOutAndErr[T](body: => T): T = { - val savedOut = System.out - val savedErr = System.err - System setOut NullPrintStream - System setErr NullPrintStream - try body - finally { - System setOut savedOut - System setErr savedErr - } - } -} diff --git a/src/compiler/scala/tools/nsc/io/Sources.scala b/src/compiler/scala/tools/nsc/io/Sources.scala deleted file mode 100644 index 25d27acae8..0000000000 --- a/src/compiler/scala/tools/nsc/io/Sources.scala +++ /dev/null @@ -1,86 +0,0 @@ -package scala.tools.nsc -package io - -import util.ClassPath -import java.util.concurrent.{ Future, ConcurrentHashMap, ExecutionException } -import java.util.zip.ZipException -import collection.JavaConverters._ -import Properties.{ envOrElse, propOrElse } - -class Sources(val path: String) { - val expandedPath = ClassPath.join(ClassPath expandPath path: _*) - val cache = new ConcurrentHashMap[String, List[Fileish]] - def allNames = cache.keys.asScala.toList.sorted - def apply(name: String) = get(name) - def size = cache.asScala.values map (_.length) sum - def isEmpty = path == "" - - private var debug = false - private def dbg(msg: => Any) = if (debug) Console println msg - private val partitioned = ClassPath toPaths expandedPath partition (_.isDirectory) - - val dirs = partitioned._1 map (_.toDirectory) - val jars = partitioned._2 filter Jar.isJarOrZip map (_.toFile) - val (isDone, force) = ( - if (path == "") (() => true, () => ()) - else { - val f1 = spawn(calculateDirs()) - val f2 = spawn(calculateJars()) - val fn1 = () => { f1.isDone() && f2.isDone() } - val fn2 = () => { f1.get() ; f2.get() ; () } - - (fn1, fn2) - } - ) - - private def catchZip(body: => Unit): Unit = { - try body - catch { case x: ZipException => dbg("Caught: " + x) } - } - - private def calculateDirs() = - dirs foreach { d => dbg(d) ; catchZip(addSources(d.deepFiles map (x => Fileish(x)))) } - - private def calculateJars() = - jars foreach { j => dbg(j) ; catchZip(addSources(new Jar(j).fileishIterator)) } - - private def addSources(fs: TraversableOnce[Fileish]) = - fs foreach { f => if (f.isSourceFile) add(f.name, f) } - - private def get(key: String): List[Fileish] = - if (cache containsKey key) cache.get(key) else Nil - - private def add(key: String, value: Fileish) = { - if (cache containsKey key) cache.replace(key, value :: cache.get(key)) - else cache.put(key, List(value)) - } - override def toString = "Sources(%d dirs, %d jars, %d sources)".format( - dirs.size, jars.size, cache.asScala.values map (_.length) sum - ) -} - -trait LowPrioritySourcesImplicits { - self: Sources.type => - - implicit def fallbackSources: Sources = defaultSources -} - -object Sources extends LowPrioritySourcesImplicits { - val empty = new Sources("") - - private def libraryInits = ClassPath.scalaLibrary.toList flatMap (_.toAbsolute.parents) - private def librarySourceDir = libraryInits map (_ / "src") find (_.isDirectory) - private def expandedSourceDir = librarySourceDir.toList flatMap (ClassPath expandDir _.path) - - private val initialPath = sys.props.traceSourcePath.value - private val initialSources = apply(expandedSourceDir :+ initialPath: _*) - - def defaultSources = { - val path = sys.props.traceSourcePath.value - if (path == "") empty - else if (path == initialPath) initialSources - else apply(expandedSourceDir :+ path: _*) - } - - def apply(paths: String*): Sources = new Sources(ClassPath.join(paths: _*)) -} diff --git a/src/compiler/scala/tools/nsc/io/package.scala b/src/compiler/scala/tools/nsc/io/package.scala index 52e6de0bed..d29030603e 100644 --- a/src/compiler/scala/tools/nsc/io/package.scala +++ b/src/compiler/scala/tools/nsc/io/package.scala @@ -23,9 +23,6 @@ package object io { def callable[T](body: => T): Callable[T] = new Callable[T] { override def call() = body } def spawn[T](body: => T): Future[T] = daemonThreadPool submit callable(body) def submit(runnable: Runnable) = daemonThreadPool submit runnable - def runnableFn(f: () => Unit): Runnable = runnable(f()) - def callableFn[T](f: () => T): Callable[T] = callable(f()) - def spawnFn[T](f: () => T): Future[T] = spawn(f()) // Create, start, and return a daemon thread def daemonize(body: => Unit): Thread = newThread(_ setDaemon true)(body) |