Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* sbt -- Simple Build Tool
* Copyright 2008, 2009, 2010 Mark Harrah
*/package sbt
importPath._
importIO.{pathSplit, wrapNull}
import java.io.Fileimport java.net.URLimport scala.collection.{generic, immutable, mutable}
finalclassRichFile(val asFile: File)
{
def/(component: String): File = if(component == ".") asFile elsenewFile(asFile, component)
/** True if and only if the wrapped file exists.*/defexists= asFile.exists
/** True if and only if the wrapped file is a directory.*/defisDirectory= asFile.isDirectory
/** The last modified time of the wrapped file.*/deflastModified= asFile.lastModified
/* True if and only if the wrapped file `asFile` exists and the file 'other'
* does not exist or was modified before the `asFile`.*/defnewerThan(other: File): Boolean = Path.newerThan(asFile, other)
/* True if and only if the wrapped file `asFile` does not exist or the file `other`
* exists and was modified after `asFile`.*/defolderThan(other: File): Boolean = Path.newerThan(other, asFile)
/** The wrapped file converted to a URL.*/defasURL= asFile.toURI.toURL
defabsolutePath: String = asFile.getAbsolutePath
/** The last component of this path.*/defname= asFile.getName
/** The extension part of the name of this path. This is the part of the name after the last period, or the empty string if there is no period.*/defext= baseAndExt._2
/** The base of the name of this path. This is the part of the name before the last period, or the full name if there is no period.*/defbase= baseAndExt._1
defbaseAndExt: (String, String) =
{
val nme = name
val dot = nme.lastIndexOf('.')
if(dot < 0) (nme, "") else (nme.substring(0, dot), nme.substring(dot+1))
}
defrelativize(sub: File): Option[File] = Path.relativizeFile(asFile, sub)
defrelativeTo(base: File): Option[File] = Path.relativizeFile(base, asFile)
defhash: Array[Byte] = Hash(asFile)
defhashString: String = Hash.toHex(hash)
defhashStringHalf: String = Hash.halve(hashString)
}
import java.io.FileimportFile.pathSeparator
traitPathLow
{
implicitdefsingleFileFinder(file: File): PathFinder = PathFinder(file)
}
traitPathExtraextendsAlternativeswithMapperwithPathLow
{
implicitdefrichFile(file: File): RichFile = newRichFile(file)
implicitdeffilesToFinder(cc: Traversable[File]): PathFinder = PathFinder.strict(cc)
}
objectPathextendsPathExtra
{
defapply(f: File): RichFile = newRichFile(f)
defapply(f: String): RichFile = newRichFile(newFile(f))
deffileProperty(name: String): File = newFile(System.getProperty(name))
defuserHome: File = fileProperty("user.home")
defabsolute(file: File): File = newFile(file.toURI.normalize).getAbsoluteFile
defmakeString(paths: Seq[File]): String = makeString(paths, pathSeparator)
defmakeString(paths: Seq[File], sep: String): String = {
val separated = paths.map(_.getAbsolutePath)
separated.find(_ contains sep).foreach( p => sys.error(s"Path '$p' contains separator '$sep'") )
separated.mkString(sep)
}
defnewerThan(a: File, b: File): Boolean = a.exists && (!b.exists || a.lastModified > b.lastModified)
/** The separator character of the platform.*/val sep = java.io.File.separatorChar
@deprecated("Use IO.relativizeFile", "0.13.1")
defrelativizeFile(baseFile: File, file: File): Option[File] = IO.relativizeFile(baseFile, file)
deftoURLs(files: Seq[File]): Array[URL] = files.map(_.toURI.toURL).toArray
}
objectPathFinder
{
/** A PathFinder that always produces the empty set of Paths.*/val empty = newPathFinder { private[sbt] defaddTo(fileSet: mutable.Set[File]) {} }
defstrict(files: Traversable[File]): PathFinder = apply(files)
defapply(files: => Traversable[File]): PathFinder = newPathFinder {
private[sbt] defaddTo(fileSet: mutable.Set[File]) = fileSet ++= files
}
defapply(file: File): PathFinder = newSingleFile(file)
}
/** A path finder constructs a set of paths. The set is evaluated by a call to the get
* method. The set will be different for different calls to get if the underlying filesystem
* has changed.*/sealedabstractclassPathFinder
{
/** The union of the paths found by this PathFinder with the paths found by 'paths'.*/def+++(paths: PathFinder): PathFinder = newPaths(this, paths)
/** Excludes all paths from excludePaths from the paths selected by this PathFinder.*/def---(excludePaths: PathFinder): PathFinder = newExcludeFiles(this, excludePaths)
/** Constructs a new finder that selects all paths with a name that matches filter and are
* descendants of paths selected by this finder.*/def**(filter: FileFilter): PathFinder = newDescendantOrSelfPathFinder(this, filter)
def***: PathFinder = **(AllPassFilter)
/** Constructs a new finder that selects all paths with a name that matches filter and are
* immediate children of paths selected by this finder.*/def*(filter: FileFilter): PathFinder = newChildPathFinder(this, filter)
/** Constructs a new finder that selects all paths with name literal that are immediate children
* of paths selected by this finder.*/def/(literal: String): PathFinder = newChildPathFinder(this, newExactFilter(literal))
/** Constructs a new finder that selects all paths with name literal that are immediate children
* of paths selected by this finder.*/finaldef\(literal: String): PathFinder = this / literal
@deprecated("Use pair.", "0.13.1")
defx_![T](mapper: File => Option[T]): Traversable[(File,T)] = pair(mapper, false)
/** Applies `mapper` to each path selected by this PathFinder and returns the path paired with the non-empty result.
* If the result is empty (None) and `errorIfNone` is true, an exception is thrown.
* If `errorIfNone` is false, the path is dropped from the returned Traversable.*/defpair[T](mapper: File => Option[T], errorIfNone: Boolean = true): Seq[(File,T)] =
{
val apply = if(errorIfNone) mapper | fail else mapper
for(file <- get; mapped <- apply(file)) yield (file, mapped)
}
@deprecated("Use pair.", "0.13.1")
defx[T](mapper: File => Option[T], errorIfNone: Boolean = true): Seq[(File,T)] = pair(mapper, errorIfNone)
/** Selects all descendant paths with a name that matches include and do not have an intermediate
* path with a name that matches intermediateExclude. Typical usage is:
*
* descendantsExcept("*.jar", ".svn")*/defdescendantsExcept(include: FileFilter, intermediateExclude: FileFilter): PathFinder =
(this ** include) --- (this ** intermediateExclude ** include)
/** Evaluates this finder and converts the results to a `Seq` of distinct `File`s. The files returned by this method will reflect the underlying filesystem at the
* time of calling. If the filesystem changes, two calls to this method might be different.*/finaldefget: Seq[File] =
{
import collection.JavaConversions._
val pathSet: mutable.Set[File] = new java.util.LinkedHashSet[File]
addTo(pathSet)
pathSet.toSeq
}
/** Only keeps paths for which `f` returns true. It is non-strict, so it is not evaluated until the returned finder is evaluated.*/finaldeffilter(f: File => Boolean): PathFinder = PathFinder(get filter f)
/* Non-strict flatMap: no evaluation occurs until the returned finder is evaluated.*/finaldefflatMap(f: File => PathFinder): PathFinder = PathFinder(get.flatMap(p => f(p).get))
/** Evaluates this finder and converts the results to an `Array` of `URL`s..*/finaldefgetURLs: Array[URL] = get.toArray.map(_.toURI.toURL)
/** Evaluates this finder and converts the results to a distinct sequence of absolute path strings.*/finaldefgetPaths: Seq[String] = get.map(_.absolutePath)
private[sbt] defaddTo(fileSet: mutable.Set[File])
/** Create a PathFinder from this one where each path has a unique name.
* A single path is arbitrarily selected from the set of paths with the same name.*/defdistinct: PathFinder = PathFinder { get.map(p => (p.asFile.getName, p)).toMap.values }
/** Constructs a string by evaluating this finder, converting the resulting Paths to absolute path strings, and joining them with the platform path separator.*/finaldefabsString= Path.makeString(get)
/** Constructs a debugging string for this finder by evaluating it and separating paths by newlines.*/overridedeftoString= get.mkString("\n ", "\n ","")
}
privateclassSingleFile(asFile: File) extendsPathFinder
{
private[sbt] defaddTo(fileSet: mutable.Set[File]): Unit = if(asFile.exists) fileSet += asFile
}
privateabstractclassFilterFilesextendsPathFinderwithFileFilter
{
defparent: PathFinderdeffilter: FileFilterfinaldefaccept(file: File) = filter.accept(file)
protecteddefhandleFile(file: File, fileSet: mutable.Set[File]): Unit =
for(matchedFile <- wrapNull(file.listFiles(this)))
fileSet += newFile(file, matchedFile.getName)
}
privateclassDescendantOrSelfPathFinder(val parent: PathFinder, val filter: FileFilter) extendsFilterFiles
{
private[sbt] defaddTo(fileSet: mutable.Set[File])
{
for(file <- parent.get)
{
if(accept(file))
fileSet += file
handleFileDescendant(file, fileSet)
}
}
privatedefhandleFileDescendant(file: File, fileSet: mutable.Set[File])
{
handleFile(file, fileSet)
for(childDirectory <- wrapNull(file listFiles DirectoryFilter))
handleFileDescendant(newFile(file, childDirectory.getName), fileSet)
}
}
privateclassChildPathFinder(val parent: PathFinder, val filter: FileFilter) extendsFilterFiles
{
private[sbt] defaddTo(fileSet: mutable.Set[File]): Unit =
for(file <- parent.get)
handleFile(file, fileSet)
}
privateclassPaths(a: PathFinder, b: PathFinder) extendsPathFinder
{
private[sbt] defaddTo(fileSet: mutable.Set[File])
{
a.addTo(fileSet)
b.addTo(fileSet)
}
}
privateclassExcludeFiles(include: PathFinder, exclude: PathFinder) extendsPathFinder
{
private[sbt] defaddTo(pathSet: mutable.Set[File])
{
val includeSet = new mutable.LinkedHashSet[File]
include.addTo(includeSet)
val excludeSet = new mutable.HashSet[File]
exclude.addTo(excludeSet)
includeSet --= excludeSet
pathSet ++= includeSet
}
}