aboutsummaryrefslogtreecommitdiff
path: root/stage1/ClassPath.scala
diff options
context:
space:
mode:
Diffstat (limited to 'stage1/ClassPath.scala')
-rw-r--r--stage1/ClassPath.scala30
1 files changed, 30 insertions, 0 deletions
diff --git a/stage1/ClassPath.scala b/stage1/ClassPath.scala
new file mode 100644
index 0000000..66a1b44
--- /dev/null
+++ b/stage1/ClassPath.scala
@@ -0,0 +1,30 @@
+package cbt
+import java.io._
+import java.net._
+import scala.collection.immutable.Seq
+
+object ClassPath{
+ def apply(files: File*): ClassPath = ClassPath(files.toVector)
+ def flatten( classPaths: Seq[ClassPath] ): ClassPath = ClassPath( classPaths.map(_.files).flatten )
+}
+case class ClassPath(files: Seq[File]){
+ private val duplicates = (files diff files.distinct).distinct
+ assert(
+ duplicates.isEmpty,
+ "Duplicate classpath entries found:\n" ++ duplicates.mkString("\n") ++ "\nin classpath:\n"++string
+ )
+ private val nonExisting = files.distinct.filterNot(_.exists)
+ assert(
+ duplicates.isEmpty,
+ "Classpath contains entires that don't exist on disk:\n" ++ nonExisting.mkString("\n") ++ "\nin classpath:\n"++string
+ )
+
+ def +:(file: File) = ClassPath(file +: files)
+ def :+(file: File) = ClassPath(files :+ file)
+ def ++(other: ClassPath) = ClassPath(files ++ other.files)
+ def string = strings.mkString( File.pathSeparator )
+ def strings = files.map{
+ f => f.string ++ ( if(f.isDirectory) "/" else "" )
+ }
+ def toConsole = string
+}