blob: 539efc70ac4655648af430dd878c45284345af75 (
plain) (
blame)
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.net._
object ClassPath{
def flatten( classPaths: Seq[ClassPath] ): ClassPath = ClassPath( classPaths.map(_.files).flatten )
}
case class ClassPath(files: Seq[File] = 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: 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 + (
// using file extension instead of isDirectory for performance reasons
if( f.getName.endsWith(".jar") /* !f.isDirectory */ ) "" else "/"
)
}.sorted
}
|