-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathClassPath.scala
30 lines (28 loc) · 1 KB
/
ClassPath.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package cbt
import java.io._
import java.nio._
import java.nio.file._
import java.net._
object ClassPath{
def flatten( classPaths: Seq[ClassPath] ): ClassPath = ClassPath( classPaths.map(_.files).flatten )
}
case class ClassPath(files: Seq[Path] = Seq()){
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(
nonExisting.isEmpty,
"Classpath contains entires that don't exist on disk:\n" ++ nonExisting.mkString("\n") ++ "\nin classpath:\n"++string
)
def +:(file: Path) = ClassPath(file +: files)
def :+(file: Path) = ClassPath(files :+ file)
def ++(other: ClassPath) = ClassPath(files ++ other.files)
def string = strings.mkString( File.pathSeparator )
def strings = files.map{
f => f.toString ++ ( if( f.isDirectory ) "/" else "" )
}.sorted
def toConsole = string
}