summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/util/ClassPath.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-02-14 01:00:37 +0000
committerPaul Phillips <paulp@improving.org>2010-02-14 01:00:37 +0000
commit730720552b80eacd2581f860fbd861098e54fa7e (patch)
tree9bb850bf8aaa7f0f4364171da10864dc96d1a95f /src/compiler/scala/tools/nsc/util/ClassPath.scala
parentd04911d894ce107593c773d253d19b5d094a2ad0 (diff)
downloadscala-730720552b80eacd2581f860fbd861098e54fa7e.tar.gz
scala-730720552b80eacd2581f860fbd861098e54fa7e.tar.bz2
scala-730720552b80eacd2581f860fbd861098e54fa7e.zip
Reducing the amount of low-level classpath mani...
Reducing the amount of low-level classpath manipulation going on around town. No review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/util/ClassPath.scala')
-rw-r--r--src/compiler/scala/tools/nsc/util/ClassPath.scala28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/util/ClassPath.scala b/src/compiler/scala/tools/nsc/util/ClassPath.scala
index c0c1f7a417..25b5b83a23 100644
--- a/src/compiler/scala/tools/nsc/util/ClassPath.scala
+++ b/src/compiler/scala/tools/nsc/util/ClassPath.scala
@@ -15,6 +15,7 @@ import scala.collection.mutable.{ListBuffer, ArrayBuffer, HashSet => MutHashSet}
import io.{ File, Directory, Path, AbstractFile }
import scala.tools.util.StringOps.splitWhere
import Path.isJarOrZip
+import File.pathSeparator
/** <p>
* This module provides star expansion of '-classpath' option arguments, behaves the same as
@@ -45,14 +46,19 @@ object ClassPath {
else List(pattern)
}
- /** Split path using platform-dependent path separator */
- private def splitPath(path: String): List[String] =
- path split File.pathSeparator toList
+ /** Split classpath using platform-dependent path separator */
+ def split(path: String): List[String] = path split pathSeparator filterNot (_ == "") toList
+
+ /** Join classpath using platform-dependent path separator */
+ def join(path: Seq[String]): String = path 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)
/** Expand path and possibly expanding stars */
def expandPath(path: String, expandStar: Boolean = true): List[String] =
- if (expandStar) splitPath(path) flatMap expandS
- else splitPath(path)
+ if (expandStar) split(path) flatMap expandS
+ else split(path)
/** Expand dir out to contents, a la extdir */
def expandDir(extdir: String): List[String] = {
@@ -228,7 +234,7 @@ class SourcePath[T](dir: AbstractFile, val context: ClassPathContext[T]) extends
/**
* A directory (or a .jar file) containing classfiles and packages
*/
-class DirectoryClassPath(dir: AbstractFile, val context: ClassPathContext[AbstractFile]) extends ClassPath[AbstractFile] {
+class DirectoryClassPath(val dir: AbstractFile, val context: ClassPathContext[AbstractFile]) extends ClassPath[AbstractFile] {
def name = dir.name
def asURLs = List(dir.sfile.toURL)
val sourcepaths: List[AbstractFile] = Nil
@@ -297,6 +303,11 @@ extends ClassPath[T] {
new MergedClassPath[T](newEntries, context)
}
+ def asClasspathString: String = ClassPath.join(entries partialMap {
+ case x: DirectoryClassPath => x.dir.path
+ case x: MergedClassPath[_] => x.asClasspathString
+ })
+
override def toString() = "merged classpath "+ entries.mkString("(", "\n", ")")
}
@@ -305,6 +316,7 @@ extends ClassPath[T] {
* as AbstractFile. nsc.io.ZipArchive is used to view zip/jar archives as directories.
*/
class JavaClassPath(
- containers: List[List[ClassPath[AbstractFile]]],
+ containers: List[ClassPath[AbstractFile]],
context: JavaContext)
-extends MergedClassPath[AbstractFile](containers.flatten, context) { }
+extends MergedClassPath[AbstractFile](containers, context) {
+}