mirror of https://github.com/sbt/sbt.git
additional utility methods
This commit is contained in:
parent
ccf0508ce6
commit
9d6a4f70f7
|
|
@ -13,7 +13,7 @@ import java.util.Properties
|
|||
import java.util.jar.{Attributes, JarEntry, JarFile, JarInputStream, JarOutputStream, Manifest}
|
||||
import java.util.zip.{CRC32, GZIPOutputStream, ZipEntry, ZipFile, ZipInputStream, ZipOutputStream}
|
||||
import scala.collection.immutable.TreeSet
|
||||
import scala.collection.mutable.HashSet
|
||||
import scala.collection.mutable.{HashMap,HashSet}
|
||||
import scala.reflect.{Manifest => SManifest}
|
||||
import Function.tupled
|
||||
|
||||
|
|
@ -244,6 +244,15 @@ object IO
|
|||
|
||||
private[sbt] def jars(dir: File): Iterable[File] = listFiles(dir, GlobFilter("*.jar"))
|
||||
|
||||
def deleteIfEmpty(dirs: collection.Set[File]): Unit =
|
||||
{
|
||||
val isEmpty = new HashMap[File, Boolean]
|
||||
def visit(f: File): Boolean = isEmpty.getOrElseUpdate(f, dirs(f) && f.isDirectory && (f.listFiles forall visit) )
|
||||
|
||||
dirs foreach visit
|
||||
for( (f, true) <- isEmpty) f.delete
|
||||
}
|
||||
|
||||
def delete(files: Iterable[File]): Unit = files.foreach(delete)
|
||||
def delete(file: File)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
package sbt
|
||||
|
||||
import java.io.File
|
||||
import java.io.File
|
||||
|
||||
trait Mapper
|
||||
{
|
||||
|
|
@ -51,4 +51,10 @@ trait Alternatives
|
|||
new Alternative[A,B] { def | (g: A => Option[B]) =
|
||||
(a: A) => f(a) orElse g(a)
|
||||
}
|
||||
final def alternatives[A,B](alts: Seq[A => Option[B]]): A => Option[B] =
|
||||
alts match
|
||||
{
|
||||
case Seq(f, fs @ _*) => f | alternatives(fs)
|
||||
case Seq() => a => None
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue