You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2013/12/04 16:21:25 UTC
[8/9] CLEREZZA-435: repaced tabs with spaces in scala files
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/bundledevtool/src/main/scala/sbt/io/IPC.scala
----------------------------------------------------------------------
diff --git a/bundledevtool/src/main/scala/sbt/io/IPC.scala b/bundledevtool/src/main/scala/sbt/io/IPC.scala
index 01f3092..ddd09f7 100644
--- a/bundledevtool/src/main/scala/sbt/io/IPC.scala
+++ b/bundledevtool/src/main/scala/sbt/io/IPC.scala
@@ -29,65 +29,65 @@ import java.net.{InetAddress, ServerSocket, Socket}
object IPC
{
- private val portMin = 1025
- private val portMax = 65536
- private val loopback = InetAddress.getByName(null) // loopback
-
- def client[T](port: Int)(f: IPC => T): T =
- ipc(new Socket(loopback, port))(f)
-
- def pullServer[T](f: Server => T): T =
- {
- val server = makeServer
- try { f(new Server(server)) }
- finally { server.close() }
- }
- def makeServer: ServerSocket =
- {
- val random = new java.util.Random
- def nextPort = random.nextInt(portMax - portMin + 1) + portMin
- def createServer(attempts: Int): ServerSocket =
- if(attempts > 0)
- try { new ServerSocket(nextPort, 1, loopback) }
- catch { case _: Exception => createServer(attempts - 1) }
- else
- error("Could not connect to socket: maximum attempts exceeded")
- createServer(10)
- }
- def server[T](f: IPC => Option[T]): T = serverImpl(makeServer, f)
- def server[T](port: Int)(f: IPC => Option[T]): T =
- serverImpl(new ServerSocket(port, 1, loopback), f)
- private def serverImpl[T](server: ServerSocket, f: IPC => Option[T]): T =
- {
- def listen(): T =
- {
- ipc(server.accept())(f) match
- {
- case Some(done) => done
- case None => listen()
- }
- }
-
- try { listen() }
- finally { server.close() }
- }
- private def ipc[T](s: Socket)(f: IPC => T): T =
- try { f(new IPC(s)) }
- finally { s.close() }
-
- final class Server private[IPC](s: ServerSocket) extends NotNull
- {
- def port = s.getLocalPort
- def close() = s.close()
- def connection[T](f: IPC => T): T = IPC.ipc(s.accept())(f)
- }
+ private val portMin = 1025
+ private val portMax = 65536
+ private val loopback = InetAddress.getByName(null) // loopback
+
+ def client[T](port: Int)(f: IPC => T): T =
+ ipc(new Socket(loopback, port))(f)
+
+ def pullServer[T](f: Server => T): T =
+ {
+ val server = makeServer
+ try { f(new Server(server)) }
+ finally { server.close() }
+ }
+ def makeServer: ServerSocket =
+ {
+ val random = new java.util.Random
+ def nextPort = random.nextInt(portMax - portMin + 1) + portMin
+ def createServer(attempts: Int): ServerSocket =
+ if(attempts > 0)
+ try { new ServerSocket(nextPort, 1, loopback) }
+ catch { case _: Exception => createServer(attempts - 1) }
+ else
+ error("Could not connect to socket: maximum attempts exceeded")
+ createServer(10)
+ }
+ def server[T](f: IPC => Option[T]): T = serverImpl(makeServer, f)
+ def server[T](port: Int)(f: IPC => Option[T]): T =
+ serverImpl(new ServerSocket(port, 1, loopback), f)
+ private def serverImpl[T](server: ServerSocket, f: IPC => Option[T]): T =
+ {
+ def listen(): T =
+ {
+ ipc(server.accept())(f) match
+ {
+ case Some(done) => done
+ case None => listen()
+ }
+ }
+
+ try { listen() }
+ finally { server.close() }
+ }
+ private def ipc[T](s: Socket)(f: IPC => T): T =
+ try { f(new IPC(s)) }
+ finally { s.close() }
+
+ final class Server private[IPC](s: ServerSocket) extends NotNull
+ {
+ def port = s.getLocalPort
+ def close() = s.close()
+ def connection[T](f: IPC => T): T = IPC.ipc(s.accept())(f)
+ }
}
final class IPC private(s: Socket) extends NotNull
{
- def port = s.getLocalPort
- private val in = new BufferedReader(new InputStreamReader(s.getInputStream))
- private val out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream))
-
- def send(s: String) = { out.write(s); out.newLine(); out.flush() }
- def receive: String = in.readLine()
+ def port = s.getLocalPort
+ private val in = new BufferedReader(new InputStreamReader(s.getInputStream))
+ private val out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream))
+
+ def send(s: String) = { out.write(s); out.newLine(); out.flush() }
+ def receive: String = in.readLine()
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/bundledevtool/src/main/scala/sbt/io/NameFilter.scala
----------------------------------------------------------------------
diff --git a/bundledevtool/src/main/scala/sbt/io/NameFilter.scala b/bundledevtool/src/main/scala/sbt/io/NameFilter.scala
index 38ac454..4bf5c68 100644
--- a/bundledevtool/src/main/scala/sbt/io/NameFilter.scala
+++ b/bundledevtool/src/main/scala/sbt/io/NameFilter.scala
@@ -29,65 +29,65 @@ import java.util.regex.Pattern
trait FileFilter extends java.io.FileFilter with NotNull
{
- def || (filter: FileFilter): FileFilter = new SimpleFileFilter( file => accept(file) || filter.accept(file) )
- def && (filter: FileFilter): FileFilter = new SimpleFileFilter( file => accept(file) && filter.accept(file) )
- def -- (filter: FileFilter): FileFilter = new SimpleFileFilter( file => accept(file) && !filter.accept(file) )
- def unary_- : FileFilter = new SimpleFileFilter( file => !accept(file) )
+ def || (filter: FileFilter): FileFilter = new SimpleFileFilter( file => accept(file) || filter.accept(file) )
+ def && (filter: FileFilter): FileFilter = new SimpleFileFilter( file => accept(file) && filter.accept(file) )
+ def -- (filter: FileFilter): FileFilter = new SimpleFileFilter( file => accept(file) && !filter.accept(file) )
+ def unary_- : FileFilter = new SimpleFileFilter( file => !accept(file) )
}
trait NameFilter extends FileFilter with NotNull
{
- def accept(name: String): Boolean
- final def accept(file: File): Boolean = accept(file.getName)
- def | (filter: NameFilter): NameFilter = new SimpleFilter( name => accept(name) || filter.accept(name) )
- def & (filter: NameFilter): NameFilter = new SimpleFilter( name => accept(name) && filter.accept(name) )
- def - (filter: NameFilter): NameFilter = new SimpleFilter( name => accept(name) && !filter.accept(name) )
- override def unary_- : NameFilter = new SimpleFilter( name => !accept(name) )
+ def accept(name: String): Boolean
+ final def accept(file: File): Boolean = accept(file.getName)
+ def | (filter: NameFilter): NameFilter = new SimpleFilter( name => accept(name) || filter.accept(name) )
+ def & (filter: NameFilter): NameFilter = new SimpleFilter( name => accept(name) && filter.accept(name) )
+ def - (filter: NameFilter): NameFilter = new SimpleFilter( name => accept(name) && !filter.accept(name) )
+ override def unary_- : NameFilter = new SimpleFilter( name => !accept(name) )
}
object HiddenFileFilter extends FileFilter {
- def accept(file: File) = file.isHidden && file.getName != "."
+ def accept(file: File) = file.isHidden && file.getName != "."
}
object ExistsFileFilter extends FileFilter {
- def accept(file: File) = file.exists
+ def accept(file: File) = file.exists
}
object DirectoryFilter extends FileFilter {
- def accept(file: File) = file.isDirectory
+ def accept(file: File) = file.isDirectory
}
class SimpleFileFilter(val acceptFunction: File => Boolean) extends FileFilter
{
- def accept(file: File) = acceptFunction(file)
+ def accept(file: File) = acceptFunction(file)
}
class ExactFilter(val matchName: String) extends NameFilter
{
- def accept(name: String) = matchName == name
+ def accept(name: String) = matchName == name
}
class SimpleFilter(val acceptFunction: String => Boolean) extends NameFilter
{
- def accept(name: String) = acceptFunction(name)
+ def accept(name: String) = acceptFunction(name)
}
class PatternFilter(val pattern: Pattern) extends NameFilter
{
- def accept(name: String) = pattern.matcher(name).matches
+ def accept(name: String) = pattern.matcher(name).matches
}
object AllPassFilter extends NameFilter
{
- def accept(name: String) = true
+ def accept(name: String) = true
}
object NothingFilter extends NameFilter
{
- def accept(name: String) = false
+ def accept(name: String) = false
}
object GlobFilter
{
- implicit def apply(expression: String): NameFilter =
- {
- require(!expression.exists(java.lang.Character.isISOControl), "Control characters not allowed in filter expression.")
- if(expression == "*")
- AllPassFilter
- else if(expression.indexOf('*') < 0) // includes case where expression is empty
- new ExactFilter(expression)
- else
- new PatternFilter(Pattern.compile(expression.split("\\*", -1).map(quote).mkString(".*")))
- }
- private def quote(s: String) = if(s.isEmpty) "" else Pattern.quote(s.replaceAll("\n", """\n"""))
+ implicit def apply(expression: String): NameFilter =
+ {
+ require(!expression.exists(java.lang.Character.isISOControl), "Control characters not allowed in filter expression.")
+ if(expression == "*")
+ AllPassFilter
+ else if(expression.indexOf('*') < 0) // includes case where expression is empty
+ new ExactFilter(expression)
+ else
+ new PatternFilter(Pattern.compile(expression.split("\\*", -1).map(quote).mkString(".*")))
+ }
+ private def quote(s: String) = if(s.isEmpty) "" else Pattern.quote(s.replaceAll("\n", """\n"""))
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/bundledevtool/src/main/scala/sbt/io/Pack.scala
----------------------------------------------------------------------
diff --git a/bundledevtool/src/main/scala/sbt/io/Pack.scala b/bundledevtool/src/main/scala/sbt/io/Pack.scala
index 562d443..c7dc287 100644
--- a/bundledevtool/src/main/scala/sbt/io/Pack.scala
+++ b/bundledevtool/src/main/scala/sbt/io/Pack.scala
@@ -30,29 +30,29 @@ import IO._
object Pack
{
- def pack(jarPath: File, out: File): Unit = pack(jarPath, out, defaultPackerOptions)
- def pack(jarPath: File, out: File, options: Iterable[(String, String)])
- {
- val packer = Pack200.newPacker
- import collection.JavaConversions._
- packer.properties ++= options
-
- Using.jarFile(false)(jarPath) { f =>
- Using.fileOutputStream()(out) { stream =>
- packer.pack(f, stream)
- }
- }
- }
- def unpack(packedPath: File, toJarPath: File)
- {
- val unpacker = Pack200.newUnpacker
- Using.fileOutputStream()(toJarPath) { fileStream =>
- Using.jarOutputStream(fileStream) { jarOut =>
- unpacker.unpack(packedPath, jarOut)
- }
- }
- }
- def defaultPackerOptions = scala.collection.immutable.Map()
+ def pack(jarPath: File, out: File): Unit = pack(jarPath, out, defaultPackerOptions)
+ def pack(jarPath: File, out: File, options: Iterable[(String, String)])
+ {
+ val packer = Pack200.newPacker
+ import collection.JavaConversions._
+ packer.properties ++= options
+
+ Using.jarFile(false)(jarPath) { f =>
+ Using.fileOutputStream()(out) { stream =>
+ packer.pack(f, stream)
+ }
+ }
+ }
+ def unpack(packedPath: File, toJarPath: File)
+ {
+ val unpacker = Pack200.newUnpacker
+ Using.fileOutputStream()(toJarPath) { fileStream =>
+ Using.jarOutputStream(fileStream) { jarOut =>
+ unpacker.unpack(packedPath, jarOut)
+ }
+ }
+ }
+ def defaultPackerOptions = scala.collection.immutable.Map()
}
import java.net.URL
@@ -60,41 +60,41 @@ import java.net.URL
* on scalaz and it is difficult to determine whether a jar is both signed and valid. */
object SignJar
{
- final class SignOption private[SignJar](val toList: List[String], val signOnly: Boolean)
- {
- override def toString = toList.mkString(" ")
- }
- def keyStore(url: URL) = new SignOption("-keystore" :: url.toExternalForm :: Nil, true)
- def signedJar(p: Path) = new SignOption("-signedjar" :: p.asFile.getAbsolutePath :: Nil, true)
- def verbose = new SignOption("-verbose" :: Nil, false)
- def sigFile(name: String) = new SignOption("-sigfile" :: name :: Nil, true)
- def storeType(t: String) = new SignOption("-storetype" :: t :: Nil, false)
- def provider(p: String) = new SignOption("-provider" :: p :: Nil, false)
- def providerName(p: String) = new SignOption("-providerName" :: p :: Nil, false)
- def storePassword(p: String) = new SignOption("-storepass" :: p :: Nil, true)
- def keyPassword(p: String) = new SignOption("-keypass" :: p :: Nil, true)
-
- private def VerifyOption = "-verify"
-
- /** Uses jarsigner to sign the given jar. */
- def sign(jarPath: File, alias: String, options: Seq[SignOption])(fork: (String, List[String]) => Int)
- {
- require(!alias.trim.isEmpty, "Alias cannot be empty")
- val arguments = options.toList.flatMap(_.toList) ::: jarPath.getAbsolutePath :: alias :: Nil
- execute("signing", arguments)(fork)
- }
- /** Uses jarsigner to verify the given jar.*/
- def verify(jarPath: File, options: Seq[SignOption])(fork: (String, List[String]) => Int)
- {
- val arguments = options.filter(!_.signOnly).toList.flatMap(_.toList) ::: VerifyOption :: jarPath.getAbsolutePath :: Nil
- execute("verifying", arguments)(fork)
- }
- private def execute(action: String, arguments: List[String])(fork: (String, List[String]) => Int)
- {
- val exitCode = fork(CommandName, arguments)
- if(exitCode != 0)
- error("Error " + action + " jar (exit code was " + exitCode + ".)")
- }
-
- private val CommandName = "jarsigner"
+ final class SignOption private[SignJar](val toList: List[String], val signOnly: Boolean)
+ {
+ override def toString = toList.mkString(" ")
+ }
+ def keyStore(url: URL) = new SignOption("-keystore" :: url.toExternalForm :: Nil, true)
+ def signedJar(p: Path) = new SignOption("-signedjar" :: p.asFile.getAbsolutePath :: Nil, true)
+ def verbose = new SignOption("-verbose" :: Nil, false)
+ def sigFile(name: String) = new SignOption("-sigfile" :: name :: Nil, true)
+ def storeType(t: String) = new SignOption("-storetype" :: t :: Nil, false)
+ def provider(p: String) = new SignOption("-provider" :: p :: Nil, false)
+ def providerName(p: String) = new SignOption("-providerName" :: p :: Nil, false)
+ def storePassword(p: String) = new SignOption("-storepass" :: p :: Nil, true)
+ def keyPassword(p: String) = new SignOption("-keypass" :: p :: Nil, true)
+
+ private def VerifyOption = "-verify"
+
+ /** Uses jarsigner to sign the given jar. */
+ def sign(jarPath: File, alias: String, options: Seq[SignOption])(fork: (String, List[String]) => Int)
+ {
+ require(!alias.trim.isEmpty, "Alias cannot be empty")
+ val arguments = options.toList.flatMap(_.toList) ::: jarPath.getAbsolutePath :: alias :: Nil
+ execute("signing", arguments)(fork)
+ }
+ /** Uses jarsigner to verify the given jar.*/
+ def verify(jarPath: File, options: Seq[SignOption])(fork: (String, List[String]) => Int)
+ {
+ val arguments = options.filter(!_.signOnly).toList.flatMap(_.toList) ::: VerifyOption :: jarPath.getAbsolutePath :: Nil
+ execute("verifying", arguments)(fork)
+ }
+ private def execute(action: String, arguments: List[String])(fork: (String, List[String]) => Int)
+ {
+ val exitCode = fork(CommandName, arguments)
+ if(exitCode != 0)
+ error("Error " + action + " jar (exit code was " + exitCode + ".)")
+ }
+
+ private val CommandName = "jarsigner"
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/bundledevtool/src/main/scala/sbt/io/Path.scala
----------------------------------------------------------------------
diff --git a/bundledevtool/src/main/scala/sbt/io/Path.scala b/bundledevtool/src/main/scala/sbt/io/Path.scala
index ea9d6f9..44c8ae8 100644
--- a/bundledevtool/src/main/scala/sbt/io/Path.scala
+++ b/bundledevtool/src/main/scala/sbt/io/Path.scala
@@ -34,260 +34,260 @@ import scala.collection.{generic, immutable, mutable, TraversableLike}
* @see sbt.PathFinder*/
sealed abstract class Path extends PathFinder
{
- /** Creates a base directory for this path. This is used by copy and zip functions
- * to determine the relative path that should be used in the destination. For example,
- * if the following path is specified to be copied to directory 'd',
- *
- * <code>((a / b) ###) / x / y</code>
- *
- * the copied path would be
- *
- * <code>d / x / y</code>
- *
- * The <code>relativePath</code> method is used to return the relative path to the base directory. */
- override def ### : Path = new BaseDirectory(this)
- private[sbt] def addTo(pathSet: mutable.Set[Path])
- {
- if(asFile.exists)
- pathSet += this
- }
- override def / (component: String): Path = if(component == ".") this else new RelativePath(this, component)
- /** True if and only if the file represented by this path exists.*/
- def exists = asFile.exists
- /** True if and only if the file represented by this path is a directory.*/
- def isDirectory = asFile.isDirectory
- /** The last modified time of the file represented by this path.*/
- def lastModified = asFile.lastModified
- /* True if and only if file that this path represents exists and the file represented by the path 'p'
- * does not exist or was modified before the file for this path.*/
- def newerThan(p: Path): Boolean = exists && (!p.exists || lastModified > p.lastModified)
- /* True if and only if file that this path represents does not exist or the file represented by the path 'p'
- * exists and was modified after the file for this path.*/
- def olderThan(p: Path): Boolean = p newerThan this
- /** The file represented by this path.*/
- def asFile: File
- /** The file represented by this path converted to a <code>URL</code>.*/
- def asURL = asFile.toURI.toURL
- /** The string representation of this path relative to the base directory. The project directory is the
- * default base directory if one is not specified explicitly using the <code>###</code> operator.*/
- lazy val relativePath: String = relativePathString(sep.toString)
- def relativePathString(separator: String): String
- final def projectRelativePath: String = projectRelativePathString(sep.toString)
- def projectRelativePathString(separator: String): String
- def absolutePath: String = asFile.getAbsolutePath
- private[sbt] def prependTo(s: String): String
-
- /** The last component of this path.*/
- def name = 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.*/
- def ext = 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.*/
- def base = baseAndExt._1
- def baseAndExt: (String, String) =
- {
- val nme = name
- val dot = nme.lastIndexOf('.')
- if(dot < 0) (nme, "") else (nme.substring(0, dot), nme.substring(dot+1))
- }
-
- /** Equality of Paths is defined in terms of the underlying <code>File</code>.*/
- override final def equals(other: Any) =
- other match
- {
- case op: Path => asFile == op.asFile
- case _ => false
- }
- /** The hash code of a Path is that of the underlying <code>File</code>.*/
- override final def hashCode = asFile.hashCode
+ /** Creates a base directory for this path. This is used by copy and zip functions
+ * to determine the relative path that should be used in the destination. For example,
+ * if the following path is specified to be copied to directory 'd',
+ *
+ * <code>((a / b) ###) / x / y</code>
+ *
+ * the copied path would be
+ *
+ * <code>d / x / y</code>
+ *
+ * The <code>relativePath</code> method is used to return the relative path to the base directory. */
+ override def ### : Path = new BaseDirectory(this)
+ private[sbt] def addTo(pathSet: mutable.Set[Path])
+ {
+ if(asFile.exists)
+ pathSet += this
+ }
+ override def / (component: String): Path = if(component == ".") this else new RelativePath(this, component)
+ /** True if and only if the file represented by this path exists.*/
+ def exists = asFile.exists
+ /** True if and only if the file represented by this path is a directory.*/
+ def isDirectory = asFile.isDirectory
+ /** The last modified time of the file represented by this path.*/
+ def lastModified = asFile.lastModified
+ /* True if and only if file that this path represents exists and the file represented by the path 'p'
+ * does not exist or was modified before the file for this path.*/
+ def newerThan(p: Path): Boolean = exists && (!p.exists || lastModified > p.lastModified)
+ /* True if and only if file that this path represents does not exist or the file represented by the path 'p'
+ * exists and was modified after the file for this path.*/
+ def olderThan(p: Path): Boolean = p newerThan this
+ /** The file represented by this path.*/
+ def asFile: File
+ /** The file represented by this path converted to a <code>URL</code>.*/
+ def asURL = asFile.toURI.toURL
+ /** The string representation of this path relative to the base directory. The project directory is the
+ * default base directory if one is not specified explicitly using the <code>###</code> operator.*/
+ lazy val relativePath: String = relativePathString(sep.toString)
+ def relativePathString(separator: String): String
+ final def projectRelativePath: String = projectRelativePathString(sep.toString)
+ def projectRelativePathString(separator: String): String
+ def absolutePath: String = asFile.getAbsolutePath
+ private[sbt] def prependTo(s: String): String
+
+ /** The last component of this path.*/
+ def name = 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.*/
+ def ext = 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.*/
+ def base = baseAndExt._1
+ def baseAndExt: (String, String) =
+ {
+ val nme = name
+ val dot = nme.lastIndexOf('.')
+ if(dot < 0) (nme, "") else (nme.substring(0, dot), nme.substring(dot+1))
+ }
+
+ /** Equality of Paths is defined in terms of the underlying <code>File</code>.*/
+ override final def equals(other: Any) =
+ other match
+ {
+ case op: Path => asFile == op.asFile
+ case _ => false
+ }
+ /** The hash code of a Path is that of the underlying <code>File</code>.*/
+ override final def hashCode = asFile.hashCode
}
private final class BaseDirectory(private[sbt] val path: Path) extends Path
{
- override def ### : Path = this
- override def toString = path.toString
- def asFile = path.asFile
- def relativePathString(separator: String) = ""
- def projectRelativePathString(separator: String) = path.projectRelativePathString(separator)
- private[sbt] def prependTo(s: String) = "." + sep + s
+ override def ### : Path = this
+ override def toString = path.toString
+ def asFile = path.asFile
+ def relativePathString(separator: String) = ""
+ def projectRelativePathString(separator: String) = path.projectRelativePathString(separator)
+ private[sbt] def prependTo(s: String) = "." + sep + s
}
private[sbt] final class FilePath(file: File) extends Path
{
- lazy val asFile = absolute(file)
- override def toString = absolutePath
- def relativePathString(separator: String) = asFile.getName
- def projectRelativePathString(separator: String) = relativePathString(separator)
- private[sbt] def prependTo(s: String) = absolutePath + sep + s
+ lazy val asFile = absolute(file)
+ override def toString = absolutePath
+ def relativePathString(separator: String) = asFile.getName
+ def projectRelativePathString(separator: String) = relativePathString(separator)
+ private[sbt] def prependTo(s: String) = absolutePath + sep + s
}
// toRoot is the path between this and the root project path and is used for toString
private[sbt] final class ProjectDirectory(file: File, toRoot: Option[Path]) extends Path
{
- def this(file: File) = this(file, None)
- lazy val asFile = absolute(file)
- override def toString = foldToRoot(_.toString, ".")
- def relativePathString(separator: String) = ""
- def projectRelativePathString(separator: String) = ""
- private[sbt] def prependTo(s: String) = foldToRoot(_.prependTo(s), "." + sep + s)
- private[sbt] def foldToRoot[T](f: Path => T, orElse: T) = toRoot.map(f).getOrElse(orElse)
+ def this(file: File) = this(file, None)
+ lazy val asFile = absolute(file)
+ override def toString = foldToRoot(_.toString, ".")
+ def relativePathString(separator: String) = ""
+ def projectRelativePathString(separator: String) = ""
+ private[sbt] def prependTo(s: String) = foldToRoot(_.prependTo(s), "." + sep + s)
+ private[sbt] def foldToRoot[T](f: Path => T, orElse: T) = toRoot.map(f).getOrElse(orElse)
}
private[sbt] final class RelativePath(val parentPath: Path, val component: String) extends Path
{
- checkComponent(component)
- override def toString = parentPath prependTo component
- lazy val asFile = new File(parentPath.asFile, component)
- private[sbt] def prependTo(s: String) = parentPath prependTo (component + sep + s)
- def relativePathString(separator: String) = relative(parentPath.relativePathString(separator), separator)
- def projectRelativePathString(separator: String) = relative(parentPath.projectRelativePathString(separator), separator)
- private def relative(parentRelative: String, separator: String) =
- {
- if(parentRelative.isEmpty)
- component
- else
- parentRelative + separator + component
- }
+ checkComponent(component)
+ override def toString = parentPath prependTo component
+ lazy val asFile = new File(parentPath.asFile, component)
+ private[sbt] def prependTo(s: String) = parentPath prependTo (component + sep + s)
+ def relativePathString(separator: String) = relative(parentPath.relativePathString(separator), separator)
+ def projectRelativePathString(separator: String) = relative(parentPath.projectRelativePathString(separator), separator)
+ private def relative(parentRelative: String, separator: String) =
+ {
+ if(parentRelative.isEmpty)
+ component
+ else
+ parentRelative + separator + component
+ }
}
- import java.io.File
- import File.pathSeparator
+ import java.io.File
+ import File.pathSeparator
trait PathExtra extends Alternatives with Mapper
{
- implicit def fileToPath(file: File): Path = Path.fromFile(file)
- implicit def pathToFile(path: Path): File = path.asFile
- implicit def pathsToFiles[CC[X] <: TraversableLike[X,CC[X]]](cc: CC[Path])(implicit cb: generic.CanBuildFrom[CC[Path], File, CC[File]]): CC[File] =
- cc.map(_.asFile)
- implicit def filesToPaths[CC[X] <: TraversableLike[X,CC[X]]](cc: CC[File])(implicit cb: generic.CanBuildFrom[CC[File], Path, CC[Path]]): CC[Path] =
- cc.map(fileToPath)
- implicit def filesToFinder(cc: Traversable[File]): PathFinder = finder(cc)
- implicit def pathsToFinder(cc: Traversable[Path]): PathFinder = lazyPathFinder(cc)
+ implicit def fileToPath(file: File): Path = Path.fromFile(file)
+ implicit def pathToFile(path: Path): File = path.asFile
+ implicit def pathsToFiles[CC[X] <: TraversableLike[X,CC[X]]](cc: CC[Path])(implicit cb: generic.CanBuildFrom[CC[Path], File, CC[File]]): CC[File] =
+ cc.map(_.asFile)
+ implicit def filesToPaths[CC[X] <: TraversableLike[X,CC[X]]](cc: CC[File])(implicit cb: generic.CanBuildFrom[CC[File], Path, CC[Path]]): CC[Path] =
+ cc.map(fileToPath)
+ implicit def filesToFinder(cc: Traversable[File]): PathFinder = finder(cc)
+ implicit def pathsToFinder(cc: Traversable[Path]): PathFinder = lazyPathFinder(cc)
}
object Path extends PathExtra
{
- def fileProperty(name: String) = Path.fromFile(System.getProperty(name))
- def userHome = fileProperty("user.home")
-
- def absolute(file: File) = new File(file.toURI.normalize).getAbsoluteFile
- /** Constructs a String representation of <code>Path</code>s. The absolute path String of each <code>Path</code> is
- * separated by the platform's path separator.*/
- def makeString(paths: Iterable[Path]): String = makeString(paths, pathSeparator)
- /** Constructs a String representation of <code>Path</code>s. The absolute path String of each <code>Path</code> is
- * separated by the given separator String.*/
- def makeString(paths: Iterable[Path], sep: String): String = paths.map(_.absolutePath).mkString(sep)
+ def fileProperty(name: String) = Path.fromFile(System.getProperty(name))
+ def userHome = fileProperty("user.home")
+
+ def absolute(file: File) = new File(file.toURI.normalize).getAbsoluteFile
+ /** Constructs a String representation of <code>Path</code>s. The absolute path String of each <code>Path</code> is
+ * separated by the platform's path separator.*/
+ def makeString(paths: Iterable[Path]): String = makeString(paths, pathSeparator)
+ /** Constructs a String representation of <code>Path</code>s. The absolute path String of each <code>Path</code> is
+ * separated by the given separator String.*/
+ def makeString(paths: Iterable[Path], sep: String): String = paths.map(_.absolutePath).mkString(sep)
- def makeString(paths: Seq[File]): String = makeString(paths, pathSeparator)
- def makeString(paths: Seq[File], sep: String): String = paths.map(_.getAbsolutePath).mkString(sep)
-
- /** Constructs a String representation of <code>Path</code>s. The relative path String of each <code>Path</code> is
- * separated by the platform's path separator.*/
- def makeRelativeString(paths: Iterable[Path]): String = paths.map(_.relativePathString(sep.toString)).mkString(pathSeparator)
-
- def splitString(projectPath: Path, value: String): Iterable[Path] =
- {
- for(pathString <- pathSplit(value) if pathString.length > 0) yield
- Path.fromString(projectPath, pathString)
- }
-
- /** A <code>PathFinder</code> that always produces the empty set of <code>Path</code>s.*/
- def emptyPathFinder =
- new PathFinder
- {
- private[sbt] def addTo(pathSet: mutable.Set[Path]) {}
- }
- /** A <code>PathFinder</code> that selects the paths provided by the <code>paths</code> argument, which is
- * reevaluated on each call to the <code>PathFinder</code>'s <code>get</code> method. */
- def lazyPathFinder(paths: => Traversable[Path]): PathFinder =
- new PathFinder
- {
- private[sbt] def addTo(pathSet: mutable.Set[Path]) = pathSet ++= paths
- }
- def finder(files: => Traversable[File]): PathFinder = lazyPathFinder { fromFiles(files) }
-
- /** The separator character of the platform.*/
- val sep = java.io.File.separatorChar
-
- /** Checks the string to verify that it is a legal path component. The string must be non-empty,
- * not a slash, and not '.' or '..'.*/
- def checkComponent(c: String): String =
- {
- require(c.length > 0, "Path component must not be empty")
- require(c.indexOf('/') == -1, "Path component '" + c + "' must not have forward slashes in it")
- require(c.indexOf('\\') == -1, "Path component '" + c + "' must not have backslashes in it")
- require(c != "..", "Path component cannot be '..'")
- require(c != ".", "Path component cannot be '.'")
- c
- }
- /** Converts a path string relative to the given base path to a <code>Path</code>. */
- def fromString(basePath: Path, value: String): Path =
- {
- if(value.isEmpty)
- basePath
- else
- {
- val f = new File(value)
- if(f.isAbsolute)
- fromFile(f)
- else
- {
- val components = value.split("""[/\\]""")
- (basePath /: components)( (path, component) => path / component )
- }
- }
- }
- def baseAncestor(path: Path): Option[Path] =
- path match
- {
- case pd: ProjectDirectory => None
- case fp: FilePath => None
- case rp: RelativePath => baseAncestor(rp.parentPath)
- case b: BaseDirectory => Some(b.path)
- }
-
- def relativize(basePath: Path, path: Path): Option[Path] = relativize(basePath, path.asFile)
- def relativize(basePath: Path, file: File): Option[Path] =
- basePathString(basePath) flatMap { baseString => relativize(basePath, baseString, file) }
- def relativize(basePath: Path, basePathString: String, file: File): Option[Path] =
- {
- val pathString = file.getAbsolutePath
- if(pathString.startsWith(basePathString))
- Some(fromString(basePath, pathString.substring(basePathString.length)))
- else
- None
- }
- def relativizeFile(baseFile: File, file: File): Option[File] = relativize(baseFile, file).map { path => new File(path) }
- private[sbt] def relativize(baseFile: File, file: File): Option[String] =
- {
- val pathString = file.getAbsolutePath
- baseFileString(baseFile) flatMap
- {
- baseString =>
- {
- if(pathString.startsWith(baseString))
- Some(pathString.substring(baseString.length))
- else
- None
- }
- }
- }
- private[sbt] def basePathString(basePath: Path): Option[String] = baseFileString(basePath.asFile)
- private def baseFileString(baseFile: File): Option[String] =
- {
- if(baseFile.isDirectory)
- {
- val cp = baseFile.getAbsolutePath
- assert(cp.length > 0)
- if(cp.charAt(cp.length - 1) == File.separatorChar)
- Some(cp)
- else
- Some(cp + File.separatorChar)
- }
- else
- None
- }
- def fromFile(file: String): Path = fromFile(new File(file))
- def fromFile(file: File): Path = new FilePath(file)
- import collection.generic.{CanBuildFrom, FilterMonadic}
- def fromFiles[Repr, That](files: FilterMonadic[File, Repr])(implicit bf: CanBuildFrom[Repr, Path, That]): That = files.map(fromFile)
+ def makeString(paths: Seq[File]): String = makeString(paths, pathSeparator)
+ def makeString(paths: Seq[File], sep: String): String = paths.map(_.getAbsolutePath).mkString(sep)
+
+ /** Constructs a String representation of <code>Path</code>s. The relative path String of each <code>Path</code> is
+ * separated by the platform's path separator.*/
+ def makeRelativeString(paths: Iterable[Path]): String = paths.map(_.relativePathString(sep.toString)).mkString(pathSeparator)
+
+ def splitString(projectPath: Path, value: String): Iterable[Path] =
+ {
+ for(pathString <- pathSplit(value) if pathString.length > 0) yield
+ Path.fromString(projectPath, pathString)
+ }
+
+ /** A <code>PathFinder</code> that always produces the empty set of <code>Path</code>s.*/
+ def emptyPathFinder =
+ new PathFinder
+ {
+ private[sbt] def addTo(pathSet: mutable.Set[Path]) {}
+ }
+ /** A <code>PathFinder</code> that selects the paths provided by the <code>paths</code> argument, which is
+ * reevaluated on each call to the <code>PathFinder</code>'s <code>get</code> method. */
+ def lazyPathFinder(paths: => Traversable[Path]): PathFinder =
+ new PathFinder
+ {
+ private[sbt] def addTo(pathSet: mutable.Set[Path]) = pathSet ++= paths
+ }
+ def finder(files: => Traversable[File]): PathFinder = lazyPathFinder { fromFiles(files) }
+
+ /** The separator character of the platform.*/
+ val sep = java.io.File.separatorChar
+
+ /** Checks the string to verify that it is a legal path component. The string must be non-empty,
+ * not a slash, and not '.' or '..'.*/
+ def checkComponent(c: String): String =
+ {
+ require(c.length > 0, "Path component must not be empty")
+ require(c.indexOf('/') == -1, "Path component '" + c + "' must not have forward slashes in it")
+ require(c.indexOf('\\') == -1, "Path component '" + c + "' must not have backslashes in it")
+ require(c != "..", "Path component cannot be '..'")
+ require(c != ".", "Path component cannot be '.'")
+ c
+ }
+ /** Converts a path string relative to the given base path to a <code>Path</code>. */
+ def fromString(basePath: Path, value: String): Path =
+ {
+ if(value.isEmpty)
+ basePath
+ else
+ {
+ val f = new File(value)
+ if(f.isAbsolute)
+ fromFile(f)
+ else
+ {
+ val components = value.split("""[/\\]""")
+ (basePath /: components)( (path, component) => path / component )
+ }
+ }
+ }
+ def baseAncestor(path: Path): Option[Path] =
+ path match
+ {
+ case pd: ProjectDirectory => None
+ case fp: FilePath => None
+ case rp: RelativePath => baseAncestor(rp.parentPath)
+ case b: BaseDirectory => Some(b.path)
+ }
+
+ def relativize(basePath: Path, path: Path): Option[Path] = relativize(basePath, path.asFile)
+ def relativize(basePath: Path, file: File): Option[Path] =
+ basePathString(basePath) flatMap { baseString => relativize(basePath, baseString, file) }
+ def relativize(basePath: Path, basePathString: String, file: File): Option[Path] =
+ {
+ val pathString = file.getAbsolutePath
+ if(pathString.startsWith(basePathString))
+ Some(fromString(basePath, pathString.substring(basePathString.length)))
+ else
+ None
+ }
+ def relativizeFile(baseFile: File, file: File): Option[File] = relativize(baseFile, file).map { path => new File(path) }
+ private[sbt] def relativize(baseFile: File, file: File): Option[String] =
+ {
+ val pathString = file.getAbsolutePath
+ baseFileString(baseFile) flatMap
+ {
+ baseString =>
+ {
+ if(pathString.startsWith(baseString))
+ Some(pathString.substring(baseString.length))
+ else
+ None
+ }
+ }
+ }
+ private[sbt] def basePathString(basePath: Path): Option[String] = baseFileString(basePath.asFile)
+ private def baseFileString(baseFile: File): Option[String] =
+ {
+ if(baseFile.isDirectory)
+ {
+ val cp = baseFile.getAbsolutePath
+ assert(cp.length > 0)
+ if(cp.charAt(cp.length - 1) == File.separatorChar)
+ Some(cp)
+ else
+ Some(cp + File.separatorChar)
+ }
+ else
+ None
+ }
+ def fromFile(file: String): Path = fromFile(new File(file))
+ def fromFile(file: File): Path = new FilePath(file)
+ import collection.generic.{CanBuildFrom, FilterMonadic}
+ def fromFiles[Repr, That](files: FilterMonadic[File, Repr])(implicit bf: CanBuildFrom[Repr, Path, That]): That = files.map(fromFile)
- def getFiles(files: Traversable[Path]): immutable.Set[File] = files.map(_.asFile).toSet
- def getURLs(files: Traversable[Path]): Array[URL] = files.map(_.asURL).toArray
+ def getFiles(files: Traversable[Path]): immutable.Set[File] = files.map(_.asFile).toSet
+ def getURLs(files: Traversable[Path]): Array[URL] = files.map(_.asURL).toArray
- def toURLs(files: Seq[File]): Array[URL] = files.map(_.toURI.toURL).toArray
+ def toURLs(files: Seq[File]): Array[URL] = files.map(_.toURI.toURL).toArray
}
/** A path finder constructs a set of paths. The set is evaluated by a call to the <code>get</code>
@@ -295,147 +295,147 @@ object Path extends PathExtra
* has changed.*/
sealed abstract class PathFinder extends NotNull
{
- /** The union of the paths found by this <code>PathFinder</code> with the paths found by 'paths'.*/
- def +++(paths: PathFinder): PathFinder = new Paths(this, paths)
- /** Excludes all paths from <code>excludePaths</code> from the paths selected by this <code>PathFinder</code>.*/
- def ---(excludePaths: PathFinder): PathFinder = new ExcludePaths(this, excludePaths)
- /** Constructs a new finder that selects all paths with a name that matches <code>filter</code> and are
- * descendents of paths selected by this finder.*/
- def **(filter: FileFilter): PathFinder = new DescendentOrSelfPathFinder(this, filter)
- def *** : PathFinder = **(AllPassFilter)
- /** Constructs a new finder that selects all paths with a name that matches <code>filter</code> and are
- * immediate children of paths selected by this finder.*/
- def *(filter: FileFilter): PathFinder = new ChildPathFinder(this, filter)
- /** Constructs a new finder that selects all paths with name <code>literal</code> that are immediate children
- * of paths selected by this finder.*/
- def / (literal: String): PathFinder = new ChildPathFinder(this, new ExactFilter(literal))
- /** Constructs a new finder that selects all paths with name <code>literal</code> that are immediate children
- * of paths selected by this finder.*/
- final def \ (literal: String): PathFinder = this / literal
+ /** The union of the paths found by this <code>PathFinder</code> with the paths found by 'paths'.*/
+ def +++(paths: PathFinder): PathFinder = new Paths(this, paths)
+ /** Excludes all paths from <code>excludePaths</code> from the paths selected by this <code>PathFinder</code>.*/
+ def ---(excludePaths: PathFinder): PathFinder = new ExcludePaths(this, excludePaths)
+ /** Constructs a new finder that selects all paths with a name that matches <code>filter</code> and are
+ * descendents of paths selected by this finder.*/
+ def **(filter: FileFilter): PathFinder = new DescendentOrSelfPathFinder(this, filter)
+ def *** : PathFinder = **(AllPassFilter)
+ /** Constructs a new finder that selects all paths with a name that matches <code>filter</code> and are
+ * immediate children of paths selected by this finder.*/
+ def *(filter: FileFilter): PathFinder = new ChildPathFinder(this, filter)
+ /** Constructs a new finder that selects all paths with name <code>literal</code> that are immediate children
+ * of paths selected by this finder.*/
+ def / (literal: String): PathFinder = new ChildPathFinder(this, new ExactFilter(literal))
+ /** Constructs a new finder that selects all paths with name <code>literal</code> that are immediate children
+ * of paths selected by this finder.*/
+ final def \ (literal: String): PathFinder = this / literal
- /** Makes the paths selected by this finder into base directories.
- * @see Path.###
- */
- def ### : PathFinder = new BasePathFinder(this)
+ /** Makes the paths selected by this finder into base directories.
+ * @see Path.###
+ */
+ def ### : PathFinder = new BasePathFinder(this)
- def x_![T](mapper: File => Option[T]): Traversable[(File,T)] = x(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.*/
- def x[T](mapper: File => Option[T], errorIfNone: Boolean = true): Traversable[(File,T)] =
- {
- val apply = if(errorIfNone) mapper | fail else mapper
- for(file <- getFiles; mapped <- apply(file)) yield (file, mapped)
- }
- /** Pairs each path selected by this PathFinder with its relativePath.*/
- def xx: Traversable[(File, String)] = get.map(path => (path.asFile, path.relativePath))
+ def x_![T](mapper: File => Option[T]): Traversable[(File,T)] = x(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.*/
+ def x[T](mapper: File => Option[T], errorIfNone: Boolean = true): Traversable[(File,T)] =
+ {
+ val apply = if(errorIfNone) mapper | fail else mapper
+ for(file <- getFiles; mapped <- apply(file)) yield (file, mapped)
+ }
+ /** Pairs each path selected by this PathFinder with its relativePath.*/
+ def xx: Traversable[(File, String)] = get.map(path => (path.asFile, path.relativePath))
- /** Selects all descendent paths with a name that matches <code>include</code> and do not have an intermediate
- * path with a name that matches <code>intermediateExclude</code>. Typical usage is:
- *
- * <code>descendentsExcept("*.jar", ".svn")</code>*/
- def descendentsExcept(include: FileFilter, intermediateExclude: FileFilter): PathFinder =
- (this ** include) --- (this ** intermediateExclude ** include)
-
- /** Evaluates this finder. The set 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.*/
- final def get: immutable.Set[Path] =
- {
- val pathSet = new mutable.HashSet[Path]
- addTo(pathSet)
- pathSet.toSet
- }
- /** Only keeps paths for which `f` returns true. It is non-strict, so it is not evaluated until the returned finder is evaluated.*/
- final def filter(f: Path => Boolean): PathFinder = Path.lazyPathFinder(get.filter(f))
- /* Non-strict flatMap: no evaluation occurs until the returned finder is evaluated.*/
- final def flatMap(f: Path => PathFinder): PathFinder = Path.lazyPathFinder(get.flatMap(p => f(p).get))
- /** Evaluates this finder and converts the results to an `Array` of `URL`s..*/
- final def getURLs: Array[URL] = Path.getURLs(get)
- /** Evaluates this finder and converts the results to a `Set` of `File`s.*/
- final def getFiles: immutable.Set[File] = Path.getFiles(get)
- /** Evaluates this finder and converts the results to a `Set` of absolute path strings.*/
- final def getPaths: immutable.Set[String] = strictMap(_.absolutePath)
- /** Evaluates this finder and converts the results to a `Set` of relative path strings.*/
- final def getRelativePaths: immutable.Set[String] = strictMap(_.relativePath)
- final def strictMap[T](f: Path => T): immutable.Set[T] = get.map(f).toSet
- private[sbt] def addTo(pathSet: mutable.Set[Path])
+ /** Selects all descendent paths with a name that matches <code>include</code> and do not have an intermediate
+ * path with a name that matches <code>intermediateExclude</code>. Typical usage is:
+ *
+ * <code>descendentsExcept("*.jar", ".svn")</code>*/
+ def descendentsExcept(include: FileFilter, intermediateExclude: FileFilter): PathFinder =
+ (this ** include) --- (this ** intermediateExclude ** include)
+
+ /** Evaluates this finder. The set 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.*/
+ final def get: immutable.Set[Path] =
+ {
+ val pathSet = new mutable.HashSet[Path]
+ addTo(pathSet)
+ pathSet.toSet
+ }
+ /** Only keeps paths for which `f` returns true. It is non-strict, so it is not evaluated until the returned finder is evaluated.*/
+ final def filter(f: Path => Boolean): PathFinder = Path.lazyPathFinder(get.filter(f))
+ /* Non-strict flatMap: no evaluation occurs until the returned finder is evaluated.*/
+ final def flatMap(f: Path => PathFinder): PathFinder = Path.lazyPathFinder(get.flatMap(p => f(p).get))
+ /** Evaluates this finder and converts the results to an `Array` of `URL`s..*/
+ final def getURLs: Array[URL] = Path.getURLs(get)
+ /** Evaluates this finder and converts the results to a `Set` of `File`s.*/
+ final def getFiles: immutable.Set[File] = Path.getFiles(get)
+ /** Evaluates this finder and converts the results to a `Set` of absolute path strings.*/
+ final def getPaths: immutable.Set[String] = strictMap(_.absolutePath)
+ /** Evaluates this finder and converts the results to a `Set` of relative path strings.*/
+ final def getRelativePaths: immutable.Set[String] = strictMap(_.relativePath)
+ final def strictMap[T](f: Path => T): immutable.Set[T] = get.map(f).toSet
+ private[sbt] def addTo(pathSet: mutable.Set[Path])
- /** 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.*/
- def distinct: PathFinder = Path.lazyPathFinder((Map() ++ get.map(p => (p.asFile.getName, p))) .values.toList )
+ /** 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.*/
+ def distinct: PathFinder = Path.lazyPathFinder((Map() ++ get.map(p => (p.asFile.getName, p))) .values.toList )
- /** Constructs a string by evaluating this finder, converting the resulting Paths to absolute path strings, and joining them with the platform path separator.*/
- final def absString = Path.makeString(get)
- /** Constructs a string by evaluating this finder, converting the resulting Paths to relative path strings, and joining them with the platform path separator.*/
- final def relativeString = Path.makeRelativeString(get)
- /** Constructs a debugging string for this finder by evaluating it and separating paths by newlines.*/
- override def toString = get.mkString("\n ", "\n ","")
+ /** Constructs a string by evaluating this finder, converting the resulting Paths to absolute path strings, and joining them with the platform path separator.*/
+ final def absString = Path.makeString(get)
+ /** Constructs a string by evaluating this finder, converting the resulting Paths to relative path strings, and joining them with the platform path separator.*/
+ final def relativeString = Path.makeRelativeString(get)
+ /** Constructs a debugging string for this finder by evaluating it and separating paths by newlines.*/
+ override def toString = get.mkString("\n ", "\n ","")
}
private class BasePathFinder(base: PathFinder) extends PathFinder
{
- private[sbt] def addTo(pathSet: mutable.Set[Path])
- {
- for(path <- base.get)
- pathSet += (path ###)
- }
+ private[sbt] def addTo(pathSet: mutable.Set[Path])
+ {
+ for(path <- base.get)
+ pathSet += (path ###)
+ }
}
private abstract class FilterPath extends PathFinder with FileFilter
{
- def parent: PathFinder
- def filter: FileFilter
- final def accept(file: File) = filter.accept(file)
-
- protected def handlePath(path: Path, pathSet: mutable.Set[Path])
- {
- for(matchedFile <- wrapNull(path.asFile.listFiles(this)))
- pathSet += path / matchedFile.getName
- }
+ def parent: PathFinder
+ def filter: FileFilter
+ final def accept(file: File) = filter.accept(file)
+
+ protected def handlePath(path: Path, pathSet: mutable.Set[Path])
+ {
+ for(matchedFile <- wrapNull(path.asFile.listFiles(this)))
+ pathSet += path / matchedFile.getName
+ }
}
private class DescendentOrSelfPathFinder(val parent: PathFinder, val filter: FileFilter) extends FilterPath
{
- private[sbt] def addTo(pathSet: mutable.Set[Path])
- {
- for(path <- parent.get)
- {
- if(accept(path.asFile))
- pathSet += path
- handlePathDescendent(path, pathSet)
- }
- }
- private def handlePathDescendent(path: Path, pathSet: mutable.Set[Path])
- {
- handlePath(path, pathSet)
- for(childDirectory <- wrapNull(path.asFile.listFiles(DirectoryFilter)))
- handlePathDescendent(path / childDirectory.getName, pathSet)
- }
+ private[sbt] def addTo(pathSet: mutable.Set[Path])
+ {
+ for(path <- parent.get)
+ {
+ if(accept(path.asFile))
+ pathSet += path
+ handlePathDescendent(path, pathSet)
+ }
+ }
+ private def handlePathDescendent(path: Path, pathSet: mutable.Set[Path])
+ {
+ handlePath(path, pathSet)
+ for(childDirectory <- wrapNull(path.asFile.listFiles(DirectoryFilter)))
+ handlePathDescendent(path / childDirectory.getName, pathSet)
+ }
}
private class ChildPathFinder(val parent: PathFinder, val filter: FileFilter) extends FilterPath
{
- private[sbt] def addTo(pathSet: mutable.Set[Path])
- {
- for(path <- parent.get)
- handlePath(path, pathSet)
- }
+ private[sbt] def addTo(pathSet: mutable.Set[Path])
+ {
+ for(path <- parent.get)
+ handlePath(path, pathSet)
+ }
}
private class Paths(a: PathFinder, b: PathFinder) extends PathFinder
{
- private[sbt] def addTo(pathSet: mutable.Set[Path])
- {
- a.addTo(pathSet)
- b.addTo(pathSet)
- }
+ private[sbt] def addTo(pathSet: mutable.Set[Path])
+ {
+ a.addTo(pathSet)
+ b.addTo(pathSet)
+ }
}
private class ExcludePaths(include: PathFinder, exclude: PathFinder) extends PathFinder
{
- private[sbt] def addTo(pathSet: mutable.Set[Path])
- {
- val includeSet = new mutable.HashSet[Path]
- include.addTo(includeSet)
-
- val excludeSet = new mutable.HashSet[Path]
- exclude.addTo(excludeSet)
-
- includeSet --= excludeSet
- pathSet ++= includeSet
- }
+ private[sbt] def addTo(pathSet: mutable.Set[Path])
+ {
+ val includeSet = new mutable.HashSet[Path]
+ include.addTo(includeSet)
+
+ val excludeSet = new mutable.HashSet[Path]
+ exclude.addTo(excludeSet)
+
+ includeSet --= excludeSet
+ pathSet ++= includeSet
+ }
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/bundledevtool/src/main/scala/sbt/io/PathMapper.scala
----------------------------------------------------------------------
diff --git a/bundledevtool/src/main/scala/sbt/io/PathMapper.scala b/bundledevtool/src/main/scala/sbt/io/PathMapper.scala
index c48b3fb..3a48360 100644
--- a/bundledevtool/src/main/scala/sbt/io/PathMapper.scala
+++ b/bundledevtool/src/main/scala/sbt/io/PathMapper.scala
@@ -24,58 +24,58 @@
*/
package sbt
- import java.io.File
+ import java.io.File
trait Mapper
{
- type PathMap = File => Option[String]
- type FileMap = File => Option[File]
+ type PathMap = File => Option[String]
+ type FileMap = File => Option[File]
- val basic: PathMap = f => Some(f.getPath)
- def relativeTo(base: File): PathMap = IO.relativize(base, _)
- def rebase(oldBase: File, newBase0: String): PathMap =
- {
- val newBase = normalizeBase(newBase0)
- (file: File) =>
- if(file == oldBase)
- Some( if(newBase.isEmpty) "." else newBase )
- else
- IO.relativize(oldBase, file).map(newBase + _)
- }
- def fail: Any => Nothing = f => error("No mapping for " + f)
- val flat: PathMap = f => Some(f.getName)
- def flatRebase(newBase0: String): PathMap =
- {
- val newBase = normalizeBase(newBase0)
- f => Some(newBase + f.getName)
- }
- def some[A,B](f: A => B): A => Some[B] = x => Some(f(x))
+ val basic: PathMap = f => Some(f.getPath)
+ def relativeTo(base: File): PathMap = IO.relativize(base, _)
+ def rebase(oldBase: File, newBase0: String): PathMap =
+ {
+ val newBase = normalizeBase(newBase0)
+ (file: File) =>
+ if(file == oldBase)
+ Some( if(newBase.isEmpty) "." else newBase )
+ else
+ IO.relativize(oldBase, file).map(newBase + _)
+ }
+ def fail: Any => Nothing = f => error("No mapping for " + f)
+ val flat: PathMap = f => Some(f.getName)
+ def flatRebase(newBase0: String): PathMap =
+ {
+ val newBase = normalizeBase(newBase0)
+ f => Some(newBase + f.getName)
+ }
+ def some[A,B](f: A => B): A => Some[B] = x => Some(f(x))
- def normalizeBase(base: String) = if(!base.isEmpty && !base.endsWith("/")) base + "/" else base
+ def normalizeBase(base: String) = if(!base.isEmpty && !base.endsWith("/")) base + "/" else base
- def abs: FileMap = f => Some(f.getAbsoluteFile)
- def resolve(newDirectory: File): FileMap = file => Some(new File(newDirectory, file.getPath))
- def rebase(oldBase: File, newBase: File): FileMap =
- file =>
- if(file == oldBase)
- Some(newBase)
- else
- IO.relativize(oldBase, file) map { r => new File(newBase, r) }
+ def abs: FileMap = f => Some(f.getAbsoluteFile)
+ def resolve(newDirectory: File): FileMap = file => Some(new File(newDirectory, file.getPath))
+ def rebase(oldBase: File, newBase: File): FileMap =
+ file =>
+ if(file == oldBase)
+ Some(newBase)
+ else
+ IO.relativize(oldBase, file) map { r => new File(newBase, r) }
- def flat(newDirectory: File): FileMap = file => Some(new File(newDirectory, file.getName))
+ def flat(newDirectory: File): FileMap = file => Some(new File(newDirectory, file.getName))
}
trait Alternative[A,B] { def | (g: A => Option[B]): A => Option[B] }
trait Alternatives
{
- implicit def alternative[A,B](f:A => Option[B]): Alternative[A,B] =
- 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
- }
+ implicit def alternative[A,B](f:A => Option[B]): Alternative[A,B] =
+ 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
+ }
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/bundledevtool/src/main/scala/sbt/io/Resources.scala
----------------------------------------------------------------------
diff --git a/bundledevtool/src/main/scala/sbt/io/Resources.scala b/bundledevtool/src/main/scala/sbt/io/Resources.scala
index cdb560a..d8fb52f 100644
--- a/bundledevtool/src/main/scala/sbt/io/Resources.scala
+++ b/bundledevtool/src/main/scala/sbt/io/Resources.scala
@@ -30,59 +30,59 @@ import Resources.error
object Resources
{
- def apply(basePath: String) =
- {
- require(basePath.startsWith("/"))
- val resource = getClass.getResource(basePath)
- if(resource == null)
- error("Resource base directory '" + basePath + "' not on classpath.")
- else
- {
- val file = toFile(resource)
- if(file.exists)
- new Resources(file)
- else
- error("Resource base directory '" + basePath + "' does not exist.")
- }
- }
- def error(msg: String) = throw new ResourcesException(msg)
- private val LoadErrorPrefix = "Error loading initial project: "
+ def apply(basePath: String) =
+ {
+ require(basePath.startsWith("/"))
+ val resource = getClass.getResource(basePath)
+ if(resource == null)
+ error("Resource base directory '" + basePath + "' not on classpath.")
+ else
+ {
+ val file = toFile(resource)
+ if(file.exists)
+ new Resources(file)
+ else
+ error("Resource base directory '" + basePath + "' does not exist.")
+ }
+ }
+ def error(msg: String) = throw new ResourcesException(msg)
+ private val LoadErrorPrefix = "Error loading initial project: "
}
class ResourcesException(msg: String) extends Exception(msg)
class Resources(val baseDirectory: File)
{
- import Resources._
- // The returned directory is not actually read-only, but it should be treated that way
- def readOnlyResourceDirectory(group: String, name: String): File =
- {
- val groupDirectory = new File(baseDirectory, group)
- if(groupDirectory.isDirectory)
- {
- val resourceDirectory = new File(groupDirectory, name)
- if(resourceDirectory.isDirectory)
- resourceDirectory
- else
- error("Resource directory '" + name + "' in group '" + group + "' not found.")
- }
- else
- error("Group '" + group + "' not found.")
- }
- def readWriteResourceDirectory[T](group: String, name: String)(withDirectory: File => T): T =
- {
- val file = readOnlyResourceDirectory(group, name)
- readWriteResourceDirectory(file)(withDirectory)
- }
+ import Resources._
+ // The returned directory is not actually read-only, but it should be treated that way
+ def readOnlyResourceDirectory(group: String, name: String): File =
+ {
+ val groupDirectory = new File(baseDirectory, group)
+ if(groupDirectory.isDirectory)
+ {
+ val resourceDirectory = new File(groupDirectory, name)
+ if(resourceDirectory.isDirectory)
+ resourceDirectory
+ else
+ error("Resource directory '" + name + "' in group '" + group + "' not found.")
+ }
+ else
+ error("Group '" + group + "' not found.")
+ }
+ def readWriteResourceDirectory[T](group: String, name: String)(withDirectory: File => T): T =
+ {
+ val file = readOnlyResourceDirectory(group, name)
+ readWriteResourceDirectory(file)(withDirectory)
+ }
- def readWriteResourceDirectory[T](readOnly: File)(withDirectory: File => T): T =
- {
- require(readOnly.isDirectory)
- def readWrite(readOnly: File)(temporary: File): T =
- {
- val readWriteDirectory = new File(temporary, readOnly.getName)
- copyDirectory(readOnly, readWriteDirectory)
- withDirectory(readWriteDirectory)
- }
- withTemporaryDirectory(readWrite(readOnly))
- }
+ def readWriteResourceDirectory[T](readOnly: File)(withDirectory: File => T): T =
+ {
+ require(readOnly.isDirectory)
+ def readWrite(readOnly: File)(temporary: File): T =
+ {
+ val readWriteDirectory = new File(temporary, readOnly.getName)
+ copyDirectory(readOnly, readWriteDirectory)
+ withDirectory(readWriteDirectory)
+ }
+ withTemporaryDirectory(readWrite(readOnly))
+ }
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/bundledevtool/src/main/scala/sbt/io/SourceModificationWatch.scala
----------------------------------------------------------------------
diff --git a/bundledevtool/src/main/scala/sbt/io/SourceModificationWatch.scala b/bundledevtool/src/main/scala/sbt/io/SourceModificationWatch.scala
index 9795905..bd22211 100644
--- a/bundledevtool/src/main/scala/sbt/io/SourceModificationWatch.scala
+++ b/bundledevtool/src/main/scala/sbt/io/SourceModificationWatch.scala
@@ -24,46 +24,46 @@
*/
package sbt
- import annotation.tailrec
+ import annotation.tailrec
object SourceModificationWatch
{
- @tailrec def watch(sourcesFinder: PathFinder, pollDelaySec: Int, state: WatchState)(terminationCondition: => Boolean): (Boolean, WatchState) =
- {
- import state._
+ @tailrec def watch(sourcesFinder: PathFinder, pollDelaySec: Int, state: WatchState)(terminationCondition: => Boolean): (Boolean, WatchState) =
+ {
+ import state._
- def sourceFiles: Iterable[java.io.File] = sourcesFinder.getFiles
- val (lastModifiedTime, fileCount) =
- ( (0L, 0) /: sourceFiles) {(acc, file) => /*println("processing "+file);*/ (math.max(acc._1, file.lastModified), acc._2 + 1)}
+ def sourceFiles: Iterable[java.io.File] = sourcesFinder.getFiles
+ val (lastModifiedTime, fileCount) =
+ ( (0L, 0) /: sourceFiles) {(acc, file) => /*println("processing "+file);*/ (math.max(acc._1, file.lastModified), acc._2 + 1)}
- //println("lastModifiedTime:"+new java.util.Date(lastModifiedTime))
- //println("lastModifiedTime - lastCallbackCallTime"+(lastModifiedTime - lastCallbackCallTime))
- val sourcesModified =
- lastModifiedTime > lastCallbackCallTime ||
- previousFileCount != fileCount
+ //println("lastModifiedTime:"+new java.util.Date(lastModifiedTime))
+ //println("lastModifiedTime - lastCallbackCallTime"+(lastModifiedTime - lastCallbackCallTime))
+ val sourcesModified =
+ lastModifiedTime > lastCallbackCallTime ||
+ previousFileCount != fileCount
- val (triggered, newCallbackCallTime) =
- if (sourcesModified) {
- (false, System.currentTimeMillis)
- }
- else
- (awaitingQuietPeriod, lastCallbackCallTime)
+ val (triggered, newCallbackCallTime) =
+ if (sourcesModified) {
+ (false, System.currentTimeMillis)
+ }
+ else
+ (awaitingQuietPeriod, lastCallbackCallTime)
- val newState = new WatchState(newCallbackCallTime, fileCount, sourcesModified, if(triggered) count + 1 else count)
- if(triggered)
- (true, newState)
- else
- {
- Thread.sleep(pollDelaySec * 1000)
- if(terminationCondition)
- (false, newState)
- else
- watch(sourcesFinder, pollDelaySec, newState)(terminationCondition)
- }
- }
+ val newState = new WatchState(newCallbackCallTime, fileCount, sourcesModified, if(triggered) count + 1 else count)
+ if(triggered)
+ (true, newState)
+ else
+ {
+ Thread.sleep(pollDelaySec * 1000)
+ if(terminationCondition)
+ (false, newState)
+ else
+ watch(sourcesFinder, pollDelaySec, newState)(terminationCondition)
+ }
+ }
}
final class WatchState(val lastCallbackCallTime: Long, val previousFileCount: Int, val awaitingQuietPeriod:Boolean, val count: Int)
object WatchState
{
- def empty = new WatchState(0L, 0, false, 0)
+ def empty = new WatchState(0L, 0, false, 0)
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/bundledevtool/src/main/scala/sbt/io/Using.scala
----------------------------------------------------------------------
diff --git a/bundledevtool/src/main/scala/sbt/io/Using.scala b/bundledevtool/src/main/scala/sbt/io/Using.scala
index c87f955..0b1698c 100644
--- a/bundledevtool/src/main/scala/sbt/io/Using.scala
+++ b/bundledevtool/src/main/scala/sbt/io/Using.scala
@@ -39,81 +39,81 @@ import Using._
abstract class Using[Source, T]
{
- protected def open(src: Source): T
- def apply[R](src: Source)(f: T => R): R =
- {
- val resource = open(src)
- try { f(resource) }
- finally { close(resource) }
- }
- protected def close(out: T): Unit
+ protected def open(src: Source): T
+ def apply[R](src: Source)(f: T => R): R =
+ {
+ val resource = open(src)
+ try { f(resource) }
+ finally { close(resource) }
+ }
+ protected def close(out: T): Unit
}
import scala.reflect.{Manifest => SManifest}
abstract class WrapUsing[Source, T](implicit srcMf: SManifest[Source], targetMf: SManifest[T]) extends Using[Source, T]
{
- protected def label[S](m: SManifest[S]) = m.erasure.getSimpleName
- protected def openImpl(source: Source): T
- protected final def open(source: Source): T =
- translate("Error wrapping " + label(srcMf) + " in " + label(targetMf) + ": ") { openImpl(source) }
+ protected def label[S](m: SManifest[S]) = m.erasure.getSimpleName
+ protected def openImpl(source: Source): T
+ protected final def open(source: Source): T =
+ translate("Error wrapping " + label(srcMf) + " in " + label(targetMf) + ": ") { openImpl(source) }
}
trait OpenFile[T] extends Using[File, T]
{
- protected def openImpl(file: File): T
- protected final def open(file: File): T =
- {
- val parent = file.getParentFile
- if(parent != null)
- IO.createDirectory(parent)
- openImpl(file)
- }
+ protected def openImpl(file: File): T
+ protected final def open(file: File): T =
+ {
+ val parent = file.getParentFile
+ if(parent != null)
+ IO.createDirectory(parent)
+ openImpl(file)
+ }
}
object Using
{
- def wrap[Source, T<: Closeable](openF: Source => T)(implicit srcMf: SManifest[Source], targetMf: SManifest[T]): Using[Source,T] =
- wrap(openF, closeCloseable)
- def wrap[Source, T](openF: Source => T, closeF: T => Unit)(implicit srcMf: SManifest[Source], targetMf: SManifest[T]): Using[Source,T] =
- new WrapUsing[Source, T]
- {
- def openImpl(source: Source) = openF(source)
- def close(t: T) = closeF(t)
- }
+ def wrap[Source, T<: Closeable](openF: Source => T)(implicit srcMf: SManifest[Source], targetMf: SManifest[T]): Using[Source,T] =
+ wrap(openF, closeCloseable)
+ def wrap[Source, T](openF: Source => T, closeF: T => Unit)(implicit srcMf: SManifest[Source], targetMf: SManifest[T]): Using[Source,T] =
+ new WrapUsing[Source, T]
+ {
+ def openImpl(source: Source) = openF(source)
+ def close(t: T) = closeF(t)
+ }
- def resource[Source, T <: Closeable](openF: Source => T): Using[Source,T] =
- resource(openF, closeCloseable)
- def resource[Source, T](openF: Source => T, closeF: T => Unit): Using[Source,T] =
- new Using[Source,T]
- {
- def open(s: Source) = openF(s)
- def close(s: T) = closeF(s)
- }
- def file[T <: Closeable](openF: File => T): OpenFile[T] = file(openF, closeCloseable)
- def file[T](openF: File => T, closeF: T => Unit): OpenFile[T] =
- new OpenFile[T]
- {
- def openImpl(file: File) = openF(file)
- def close(t: T) = closeF(t)
- }
- private def closeCloseable[T <: Closeable]: T => Unit = _.close()
+ def resource[Source, T <: Closeable](openF: Source => T): Using[Source,T] =
+ resource(openF, closeCloseable)
+ def resource[Source, T](openF: Source => T, closeF: T => Unit): Using[Source,T] =
+ new Using[Source,T]
+ {
+ def open(s: Source) = openF(s)
+ def close(s: T) = closeF(s)
+ }
+ def file[T <: Closeable](openF: File => T): OpenFile[T] = file(openF, closeCloseable)
+ def file[T](openF: File => T, closeF: T => Unit): OpenFile[T] =
+ new OpenFile[T]
+ {
+ def openImpl(file: File) = openF(file)
+ def close(t: T) = closeF(t)
+ }
+ private def closeCloseable[T <: Closeable]: T => Unit = _.close()
- def bufferedOutputStream = wrap( (out: OutputStream) => new BufferedOutputStream(out) )
- def bufferedInputStream = wrap( (in: InputStream) => new BufferedInputStream(in) )
- def fileOutputStream(append: Boolean = false) = file(f => new BufferedOutputStream(new FileOutputStream(f, append)))
- def fileInputStream = file(f => new BufferedInputStream(new FileInputStream(f)))
- def urlInputStream = resource( (u: URL) => translate("Error opening " + u + ": ")(u.openStream))
- def fileOutputChannel = file(f => new FileOutputStream(f).getChannel)
- def fileInputChannel = file(f => new FileInputStream(f).getChannel)
- def fileWriter(charset: Charset = IO.utf8, append: Boolean = false) =
- file(f => new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f, append), charset)) )
- def fileReader(charset: Charset) = file(f => new BufferedReader(new InputStreamReader(new FileInputStream(f), charset)) )
- def jarFile(verify: Boolean) = file(f => new JarFile(f, verify), (_: JarFile).close())
- def zipFile = file(f => new ZipFile(f), (_: ZipFile).close())
- def streamReader = wrap{ (_: (InputStream, Charset)) match { case (in, charset) => new InputStreamReader(in, charset) } }
- def gzipInputStream = wrap( (in: InputStream) => new GZIPInputStream(in, 8192) )
- def zipInputStream = wrap( (in: InputStream) => new ZipInputStream(in))
- def zipOutputStream = wrap( (out: OutputStream) => new ZipOutputStream(out))
- def gzipOutputStream = wrap((out: OutputStream) => new GZIPOutputStream(out, 8192), (_: GZIPOutputStream).finish())
- def jarOutputStream = wrap( (out: OutputStream) => new JarOutputStream(out))
- def jarInputStream = wrap( (in: InputStream) => new JarInputStream(in))
- def zipEntry(zip: ZipFile) = resource( (entry: ZipEntry) =>
- translate("Error opening " + entry.getName + " in " + zip + ": ") { zip.getInputStream(entry) } )
+ def bufferedOutputStream = wrap( (out: OutputStream) => new BufferedOutputStream(out) )
+ def bufferedInputStream = wrap( (in: InputStream) => new BufferedInputStream(in) )
+ def fileOutputStream(append: Boolean = false) = file(f => new BufferedOutputStream(new FileOutputStream(f, append)))
+ def fileInputStream = file(f => new BufferedInputStream(new FileInputStream(f)))
+ def urlInputStream = resource( (u: URL) => translate("Error opening " + u + ": ")(u.openStream))
+ def fileOutputChannel = file(f => new FileOutputStream(f).getChannel)
+ def fileInputChannel = file(f => new FileInputStream(f).getChannel)
+ def fileWriter(charset: Charset = IO.utf8, append: Boolean = false) =
+ file(f => new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f, append), charset)) )
+ def fileReader(charset: Charset) = file(f => new BufferedReader(new InputStreamReader(new FileInputStream(f), charset)) )
+ def jarFile(verify: Boolean) = file(f => new JarFile(f, verify), (_: JarFile).close())
+ def zipFile = file(f => new ZipFile(f), (_: ZipFile).close())
+ def streamReader = wrap{ (_: (InputStream, Charset)) match { case (in, charset) => new InputStreamReader(in, charset) } }
+ def gzipInputStream = wrap( (in: InputStream) => new GZIPInputStream(in, 8192) )
+ def zipInputStream = wrap( (in: InputStream) => new ZipInputStream(in))
+ def zipOutputStream = wrap( (out: OutputStream) => new ZipOutputStream(out))
+ def gzipOutputStream = wrap((out: OutputStream) => new GZIPOutputStream(out, 8192), (_: GZIPOutputStream).finish())
+ def jarOutputStream = wrap( (out: OutputStream) => new JarOutputStream(out))
+ def jarInputStream = wrap( (in: InputStream) => new JarInputStream(in))
+ def zipEntry(zip: ZipFile) = resource( (entry: ZipEntry) =>
+ translate("Error opening " + entry.getName + " in " + zip + ": ") { zip.getInputStream(entry) } )
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/jaxrs.stanbol.fragments/src/main/scala/org/apache/clerezza/jaxrs/stanbol/webfragements/WebFragmentRunner.scala
----------------------------------------------------------------------
diff --git a/jaxrs.stanbol.fragments/src/main/scala/org/apache/clerezza/jaxrs/stanbol/webfragements/WebFragmentRunner.scala b/jaxrs.stanbol.fragments/src/main/scala/org/apache/clerezza/jaxrs/stanbol/webfragements/WebFragmentRunner.scala
index b40d430..ab23e75 100644
--- a/jaxrs.stanbol.fragments/src/main/scala/org/apache/clerezza/jaxrs/stanbol/webfragements/WebFragmentRunner.scala
+++ b/jaxrs.stanbol.fragments/src/main/scala/org/apache/clerezza/jaxrs/stanbol/webfragements/WebFragmentRunner.scala
@@ -229,13 +229,13 @@ class WebFragmentRunner extends javax.servlet.Filter with GlobalMenuItemsProvide
}
override def doFilter(request: ServletRequest, response: ServletResponse,
- chain: FilterChain){
- chain.doFilter(request, response);
- }
+ chain: FilterChain){
+ chain.doFilter(request, response);
+ }
- override def destroy() {
+ override def destroy() {
winkRequestProcessor.unbindComponent(contextResolverImpl)
- }
+ }
def getMenuItems() : java.util.Set[GlobalMenuItem] = {
@@ -249,10 +249,10 @@ class WebFragmentRunner extends javax.servlet.Filter with GlobalMenuItemsProvide
def wrapped = servletContext;
new ServletContext() {
def getServletContextName() :String = { wrapped.getServletContextName()}
- def removeAttribute(name: String) :Unit = { wrapped.removeAttribute(name)}
- def setAttribute(name: String, value: Any) :Unit = { wrapped.setAttribute(name, value)}
- def getAttributeNames() :java.util.Enumeration[_] = { wrapped.getAttributeNames()}
- def getAttribute(name: String) :Object = {
+ def removeAttribute(name: String) :Unit = { wrapped.removeAttribute(name)}
+ def setAttribute(name: String, value: Any) :Unit = { wrapped.setAttribute(name, value)}
+ def getAttributeNames() :java.util.Enumeration[_] = { wrapped.getAttributeNames()}
+ def getAttribute(name: String) :Object = {
val result = wrapped.getAttribute(name)
if (result != null) {
result
@@ -263,29 +263,29 @@ class WebFragmentRunner extends javax.servlet.Filter with GlobalMenuItemsProvide
} else null
}
}
- def getInitParameterNames() :java.util.Enumeration[_] = { wrapped.getInitParameterNames()}
- def getInitParameter(name: String) :String = { wrapped.getInitParameter(name)}
- def getServerInfo() :String = { wrapped.getServerInfo()}
- def getRealPath(name: String) :String = { wrapped.getRealPath(name)}
- def log(message: String, exception: Throwable) :Unit = { wrapped.log(message,exception)}
- def log(exception: Exception, message: String) :Unit = { wrapped.log(exception, message)}
- def log(message: String) :Unit = { wrapped.log(message)}
- @Deprecated
- def getServletNames() :java.util.Enumeration[_] = { wrapped.getServletNames()}
- @Deprecated
- def getServlets() :java.util.Enumeration[_] = { wrapped.getServlets()}
- @Deprecated
- def getServlet(name: String) :javax.servlet.Servlet = { wrapped.getServlet(name)}
- def getNamedDispatcher(name: String) :javax.servlet.RequestDispatcher = { wrapped.getNamedDispatcher(name)}
- def getRequestDispatcher(path: String) :javax.servlet.RequestDispatcher = { wrapped.getRequestDispatcher(path)}
- def getResourceAsStream(path: String) :java.io.InputStream = { wrapped.getResourceAsStream(path)}
- def getResource(path: String) :java.net.URL = { wrapped.getResource(path)}
- def getResourcePaths(path: String) :java.util.Set[_] = { wrapped.getResourcePaths(path)}
- def getMimeType(file: String) :String = { wrapped.getMimeType(file)}
- def getMinorVersion() :Int = { wrapped.getMajorVersion()}
- def getMajorVersion() :Int = { wrapped.getMajorVersion()}
- def getContext(uripath: String) :javax.servlet.ServletContext = { wrapped.getContext(uripath)}
- def getContextPath() :String = { wrapped.getContextPath()}
+ def getInitParameterNames() :java.util.Enumeration[_] = { wrapped.getInitParameterNames()}
+ def getInitParameter(name: String) :String = { wrapped.getInitParameter(name)}
+ def getServerInfo() :String = { wrapped.getServerInfo()}
+ def getRealPath(name: String) :String = { wrapped.getRealPath(name)}
+ def log(message: String, exception: Throwable) :Unit = { wrapped.log(message,exception)}
+ def log(exception: Exception, message: String) :Unit = { wrapped.log(exception, message)}
+ def log(message: String) :Unit = { wrapped.log(message)}
+ @Deprecated
+ def getServletNames() :java.util.Enumeration[_] = { wrapped.getServletNames()}
+ @Deprecated
+ def getServlets() :java.util.Enumeration[_] = { wrapped.getServlets()}
+ @Deprecated
+ def getServlet(name: String) :javax.servlet.Servlet = { wrapped.getServlet(name)}
+ def getNamedDispatcher(name: String) :javax.servlet.RequestDispatcher = { wrapped.getNamedDispatcher(name)}
+ def getRequestDispatcher(path: String) :javax.servlet.RequestDispatcher = { wrapped.getRequestDispatcher(path)}
+ def getResourceAsStream(path: String) :java.io.InputStream = { wrapped.getResourceAsStream(path)}
+ def getResource(path: String) :java.net.URL = { wrapped.getResource(path)}
+ def getResourcePaths(path: String) :java.util.Set[_] = { wrapped.getResourcePaths(path)}
+ def getMimeType(file: String) :String = { wrapped.getMimeType(file)}
+ def getMinorVersion() :Int = { wrapped.getMajorVersion()}
+ def getMajorVersion() :Int = { wrapped.getMajorVersion()}
+ def getContext(uripath: String) :javax.servlet.ServletContext = { wrapped.getContext(uripath)}
+ def getContextPath() :String = { wrapped.getContextPath()}
}
}
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/osgi.services/src/main/scala/org/apache/clerezza/osgi/services/ActivationHelper.scala
----------------------------------------------------------------------
diff --git a/osgi.services/src/main/scala/org/apache/clerezza/osgi/services/ActivationHelper.scala b/osgi.services/src/main/scala/org/apache/clerezza/osgi/services/ActivationHelper.scala
index 3bb8fad..0239818 100644
--- a/osgi.services/src/main/scala/org/apache/clerezza/osgi/services/ActivationHelper.scala
+++ b/osgi.services/src/main/scala/org/apache/clerezza/osgi/services/ActivationHelper.scala
@@ -30,84 +30,84 @@ import org.osgi.framework.{ServiceRegistration, BundleContext, BundleActivator}
*/
trait ActivationHelper extends BundleActivator {
- /**
- * this is intended to be used exclusively in the argument to the register-methods
- */
- protected var context: BundleContext= null
+ /**
+ * this is intended to be used exclusively in the argument to the register-methods
+ */
+ protected var context: BundleContext= null
- /**
- * Registers a JAX-RS Root Resource
- */
- protected def registerRootResource(rootResource: =>Object) {
- registerService(rootResource, classOf[Object], "javax.ws.rs" -> true)
- }
+ /**
+ * Registers a JAX-RS Root Resource
+ */
+ protected def registerRootResource(rootResource: =>Object) {
+ registerService(rootResource, classOf[Object], "javax.ws.rs" -> true)
+ }
- /**
- * Register a Renderlet
- * Note: renderlet must implement org.apache.clerezza.platform.typerendering.TypeRenderlet, argument not decalred on
- * this type to avoid dependency
- */
- protected def registerRenderlet(renderlet: =>Object) {
- registerServiceStringInterfaces(renderlet, Seq("org.apache.clerezza.platform.typerendering.TypeRenderlet"), Map[String, Any]())
- }
+ /**
+ * Register a Renderlet
+ * Note: renderlet must implement org.apache.clerezza.platform.typerendering.TypeRenderlet, argument not decalred on
+ * this type to avoid dependency
+ */
+ protected def registerRenderlet(renderlet: =>Object) {
+ registerServiceStringInterfaces(renderlet, Seq("org.apache.clerezza.platform.typerendering.TypeRenderlet"), Map[String, Any]())
+ }
- /**
- * Register a TypeHandler
- */
- protected def registerTypeHandler(typeHandler: => Object) {
- registerService(typeHandler, classOf[Object], "org.apache.clerezza.platform.typehandler" -> true)
- }
+ /**
+ * Register a TypeHandler
+ */
+ protected def registerTypeHandler(typeHandler: => Object) {
+ registerService(typeHandler, classOf[Object], "org.apache.clerezza.platform.typehandler" -> true)
+ }
- /**
- * Register a service exposing a specified interface with an arbitrary number of
- * arguments
- */
- protected def registerService(instance: => AnyRef, interface:Class[_],
- arguments: (String, Any)*) {
- registerService(instance, Seq(interface), Map(arguments:_*))
- }
+ /**
+ * Register a service exposing a specified interface with an arbitrary number of
+ * arguments
+ */
+ protected def registerService(instance: => AnyRef, interface:Class[_],
+ arguments: (String, Any)*) {
+ registerService(instance, Seq(interface), Map(arguments:_*))
+ }
- /**
- * Registers a service for a Seq of interfaces and a map of arguments
- */
- protected def registerService(instance: => AnyRef, interfaces: Seq[Class[_]],
- arguments: Map[String, Any]) {
- registerServiceStringInterfaces(instance, for (i <- interfaces) yield i.getName, arguments)
- }
- /**
- * Registers a service for a Seq of interfaces and a map of arguments
- */
- private def registerServiceStringInterfaces(instance: => AnyRef, interfaces: Seq[String],
- arguments: Map[String, Any]) {
- managedServices ::= ((() => instance, interfaces, arguments))
- }
+ /**
+ * Registers a service for a Seq of interfaces and a map of arguments
+ */
+ protected def registerService(instance: => AnyRef, interfaces: Seq[Class[_]],
+ arguments: Map[String, Any]) {
+ registerServiceStringInterfaces(instance, for (i <- interfaces) yield i.getName, arguments)
+ }
+ /**
+ * Registers a service for a Seq of interfaces and a map of arguments
+ */
+ private def registerServiceStringInterfaces(instance: => AnyRef, interfaces: Seq[String],
+ arguments: Map[String, Any]) {
+ managedServices ::= ((() => instance, interfaces, arguments))
+ }
- /**
- * invoked by the OSGi environment when the bundle is started, this method registers
- * the services for which the register-methods hqave been called (during object construction)
- */
- def start(context: BundleContext) {
- this.context = context
- registeredServices = Nil
- for (entry <- managedServices) {
- val args = asJavaDictionary(mutable.Map(entry._3.toSeq:_*))
- registeredServices ::= context.registerService(
- entry._2.toArray, entry._1(), args)
- }
- this.context = null
- }
+ /**
+ * invoked by the OSGi environment when the bundle is started, this method registers
+ * the services for which the register-methods hqave been called (during object construction)
+ */
+ def start(context: BundleContext) {
+ this.context = context
+ registeredServices = Nil
+ for (entry <- managedServices) {
+ val args = asJavaDictionary(mutable.Map(entry._3.toSeq:_*))
+ registeredServices ::= context.registerService(
+ entry._2.toArray, entry._1(), args)
+ }
+ this.context = null
+ }
- /**
- * called when the bundle is stopped, this method unregisters the provided service
- */
- def stop(context: BundleContext) {
- for(sr <- registeredServices) {
- sr.unregister();
- }
- registeredServices = null
- }
+ /**
+ * called when the bundle is stopped, this method unregisters the provided service
+ */
+ def stop(context: BundleContext) {
+ for(sr <- registeredServices) {
+ sr.unregister();
+ }
+ registeredServices = null
+ }
- private var managedServices: List[(() => Any, Seq[String], Map[String, Any])] = Nil
+ private var managedServices: List[(() => Any, Seq[String], Map[String, Any])] = Nil
- private var registeredServices: List[ServiceRegistration[_]] = null
+ private var registeredServices: List[ServiceRegistration[_]] = null
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/clerezza/blob/35448624/osgi.services/src/main/scala/org/apache/clerezza/osgi/services/ServicesDsl.scala
----------------------------------------------------------------------
diff --git a/osgi.services/src/main/scala/org/apache/clerezza/osgi/services/ServicesDsl.scala b/osgi.services/src/main/scala/org/apache/clerezza/osgi/services/ServicesDsl.scala
index 15f952c..6d0f245 100644
--- a/osgi.services/src/main/scala/org/apache/clerezza/osgi/services/ServicesDsl.scala
+++ b/osgi.services/src/main/scala/org/apache/clerezza/osgi/services/ServicesDsl.scala
@@ -23,75 +23,75 @@ import scala.collection.JavaConversions._
class ServicesDsl(bundleContext: BundleContext) {
- /**
- * returns an instance of a service exposing T
- */
- def $[T](implicit m: Manifest[T]): T = {
- getService(m.erasure.asInstanceOf[Class[T]])
- }
+ /**
+ * returns an instance of a service exposing T
+ */
+ def $[T](implicit m: Manifest[T]): T = {
+ getService(m.erasure.asInstanceOf[Class[T]])
+ }
- private def getService[T](clazz : Class[T]) : T= {
- val serviceReference = bundleContext.getServiceReference(clazz.getName)
- if (serviceReference != null) {
- bundleContext.getService(serviceReference).asInstanceOf[T]
- } else null.asInstanceOf[T]
- }
+ private def getService[T](clazz : Class[T]) : T= {
+ val serviceReference = bundleContext.getServiceReference(clazz.getName)
+ if (serviceReference != null) {
+ bundleContext.getService(serviceReference).asInstanceOf[T]
+ } else null.asInstanceOf[T]
+ }
- /**
- * executes action as soon as a service exposing T is available, if such
- * a service is already available the action is executed immedtely and the
- * method blocks until the action finished executing, otherwise the method
- * returns and action will be executed when a respective becomes available.
- */
- def doWith[T](action: T => Unit)(implicit m: Manifest[T]) {
- val clazz = m.erasure.asInstanceOf[Class[T]]
- val service = getService(clazz)
- if (service != null) {
- action(service)
- } else {
- lazy val serviceListener: ServiceListener = new ServiceListener {
- def serviceChanged(e: ServiceEvent) = {
- if (e.getType == ServiceEvent.REGISTERED) {
- bundleContext.removeServiceListener(serviceListener)
- action(bundleContext.getService(e.getServiceReference).asInstanceOf[T])
- }
- }
- }
- bundleContext.addServiceListener(serviceListener,
- "("+Constants.OBJECTCLASS+"="+clazz.getName+")")
- }
- }
+ /**
+ * executes action as soon as a service exposing T is available, if such
+ * a service is already available the action is executed immedtely and the
+ * method blocks until the action finished executing, otherwise the method
+ * returns and action will be executed when a respective becomes available.
+ */
+ def doWith[T](action: T => Unit)(implicit m: Manifest[T]) {
+ val clazz = m.erasure.asInstanceOf[Class[T]]
+ val service = getService(clazz)
+ if (service != null) {
+ action(service)
+ } else {
+ lazy val serviceListener: ServiceListener = new ServiceListener {
+ def serviceChanged(e: ServiceEvent) = {
+ if (e.getType == ServiceEvent.REGISTERED) {
+ bundleContext.removeServiceListener(serviceListener)
+ action(bundleContext.getService(e.getServiceReference).asInstanceOf[T])
+ }
+ }
+ }
+ bundleContext.addServiceListener(serviceListener,
+ "("+Constants.OBJECTCLASS+"="+clazz.getName+")")
+ }
+ }
- def doWith[T,U](action: (T,U) => Unit)(implicit mt: Manifest[T], mu: Manifest[U]) {
- doWith[T] {
- t: T => {
- val clazz = mu.erasure.asInstanceOf[Class[U]]
- val service = getService(clazz)
- if (service != null) {
- action(t, service)
- } else {
- doWith[U,T] {
- (iu: U, it: T) => action(it,iu)
- }
- }
- }
- }
- }
+ def doWith[T,U](action: (T,U) => Unit)(implicit mt: Manifest[T], mu: Manifest[U]) {
+ doWith[T] {
+ t: T => {
+ val clazz = mu.erasure.asInstanceOf[Class[U]]
+ val service = getService(clazz)
+ if (service != null) {
+ action(t, service)
+ } else {
+ doWith[U,T] {
+ (iu: U, it: T) => action(it,iu)
+ }
+ }
+ }
+ }
+ }
- def doWith[T,U,V](action: (T,U,V) => Unit)(implicit mt: Manifest[T],
- mu: Manifest[U], mv: Manifest[V]) {
- doWith[T,U] {
- (t: T, u: U) => {
- val clazz = mv.erasure.asInstanceOf[Class[V]]
- val service: V = getService(clazz)
- if (service != null) {
- action(t, u, service)
- } else {
- doWith[U,V,T] {
- (iu: U, iv: V, it: T) => action(it,iu,iv)
- }
- }
- }
- }
- }
+ def doWith[T,U,V](action: (T,U,V) => Unit)(implicit mt: Manifest[T],
+ mu: Manifest[U], mv: Manifest[V]) {
+ doWith[T,U] {
+ (t: T, u: U) => {
+ val clazz = mv.erasure.asInstanceOf[Class[V]]
+ val service: V = getService(clazz)
+ if (service != null) {
+ action(t, u, service)
+ } else {
+ doWith[U,V,T] {
+ (iu: U, iv: V, it: T) => action(it,iu,iv)
+ }
+ }
+ }
+ }
+ }
}