Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 54 lines (49 sloc) 1.594 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/* sbt -- Simple Build Tool
* Copyright 2010 Mark Harrah
*/
package sbt
package classpath

import java.io.{ByteArrayInputStream, InputStream}
import java.net.{Proxy, URL, URLConnection, URLStreamHandler}
import java.util.Enumeration

object RawURL
{
def apply(file: String, value: String): URL =
apply(file, value.getBytes)
def apply(file: String, value: Array[Byte]): URL =
apply(file)(new ByteArrayInputStream(value))
def apply(file: String)(value: => InputStream): URL =
new URL("raw", null, -1, file, new RawStreamHandler(value))

private[this] final class RawStreamHandler(value: => InputStream) extends URLStreamHandler
{
override protected def openConnection(url: URL, p: Proxy): URLConnection =
openConnection(url)
override protected def openConnection(url: URL): URLConnection =
new URLConnection(url)
{
private lazy val in = value
def connect() { in }
override def getInputStream = in
}
}
}

trait RawResources extends FixedResources
{
protected def resources: Map[String, String]
override protected final val resourceURL = resources.transform(RawURL.apply)
}
trait FixedResources extends ClassLoader
{
protected def resourceURL: Map[String, URL]
override def findResource(s: String): URL = resourceURL.getOrElse(s, super.findResource(s))

import java.util.Collections.{enumeration, singletonList}
override def findResources(s: String): Enumeration[URL] =
{
val sup = super.findResources(s)
resourceURL.get(s) match
{
case Some(url) => new DualEnumeration(enumeration(singletonList(url)), sup)
case None => sup
}
}
}
Something went wrong with that request. Please try again.