Permalink
Browse files

Cut size of final jar by 300k.

  • Loading branch information...
1 parent f045123 commit 33434bc82b4b0459dfc082bc835f4f53ab6faee2 @harrah committed Oct 18, 2009
View
@@ -12,7 +12,7 @@ object Boot
{
System.clearProperty("scala.home") // avoid errors from mixing Scala versions in the same JVM
CheckProxy()
- try { Launch(args) }
+ try { Launch(args.toList) }
catch
{
case b: BootException => errorAndExit(b)
View
@@ -0,0 +1,19 @@
+package xsbt.boot
+
+import java.util.HashMap
+
+final class Cache[K,V <: AnyRef](create: K => V) extends NotNull
+{
+ private[this] val delegate = new HashMap[K,V]
+ def apply(k: K): V =
+ {
+ val existing = delegate.get(k)
+ if(existing eq null) newEntry(k) else existing
+ }
+ private[this] def newEntry(k: K): V =
+ {
+ val v = create(k)
+ delegate.put(k, v)
+ v
+ }
+}
View
@@ -3,6 +3,7 @@
*/
package xsbt.boot
+import Pre._
import java.net.{MalformedURLException, URL}
object CheckProxy
@@ -33,5 +34,5 @@ object CheckProxy
private def copyEnv(envKey: String, sysKey: String) { setProperty(sysKey, System.getenv(envKey)) }
private def setProperty(key: String, value: String) { if(value != null) System.setProperty(key, value) }
private def isPropertyDefined(k: String) = isDefined(System.getProperty(k))
- private def isDefined(s: String) = s != null && !s.isEmpty
+ private def isDefined(s: String) = s != null && isNonEmpty(s)
}
View
@@ -1,23 +1,24 @@
package xsbt.boot
+import Pre._
import java.io.{File, FileInputStream, InputStreamReader}
import java.net.{URI, URL}
object Configuration
{
def parse(file: URL, baseDirectory: File) = Using( new InputStreamReader(file.openStream, "utf8") )( (new ConfigurationParser).apply )
- def find(args: Seq[String], baseDirectory: File): (URL, Seq[String]) =
+ def find(args: List[String], baseDirectory: File): (URL, List[String]) =
args match
{
- case Seq(head, tail @ _*) if head.startsWith("@")=> (configurationFromFile(head.substring(1), baseDirectory), tail)
+ case head :: tail if head.startsWith("@")=> (configurationFromFile(head.substring(1), baseDirectory), tail)
case _ =>
val propertyConfigured = System.getProperty("sbt.boot.properties")
val url = if(propertyConfigured == null) configurationOnClasspath else configurationFromFile(propertyConfigured, baseDirectory)
(url , args)
}
def configurationOnClasspath: URL =
{
- resourcePaths.toStream.map(getClass.getResource).find(_ ne null) getOrElse
+ resourcePaths.elements.map(getClass.getResource).find(_ ne null) getOrElse
( multiPartError("Could not finder sbt launch configuration. Searched classpath for:", resourcePaths))
}
def configurationFromFile(path: String, baseDirectory: File): URL =
@@ -29,21 +30,23 @@ object Configuration
if(exists) Some(resolved.toURL) else None
}
val against = resolveAgainst(baseDirectory)
- against.toStream.flatMap(resolve).firstOption.getOrElse(multiPartError("Could not find configuration file '" + path + "'. Searched:", against))
+ val resolving = against.elements.flatMap(e => resolve(e).toList.elements)
+ if(!resolving.hasNext) multiPartError("Could not find configuration file '" + path + "'. Searched:", against)
+ resolving.next()
}
- def multiPartError[T](firstLine: String, lines: Seq[T]) = throw new BootException( (Seq(firstLine) ++ lines).mkString("\n\t") )
+ def multiPartError[T](firstLine: String, lines: List[T]) = error( (firstLine :: lines).mkString("\n\t") )
val ConfigurationName = "sbt.boot.properties"
val JarBasePath = "/sbt/"
def userConfigurationPath = "/" + ConfigurationName
def defaultConfigurationPath = JarBasePath + ConfigurationName
- def resourcePaths = Seq(userConfigurationPath, defaultConfigurationPath)
- def resolveAgainst(baseDirectory: File) = Seq(baseDirectory toURI, new File(System.getProperty("user.home")) toURI, classLocation(getClass).toURI)
+ def resourcePaths = List(userConfigurationPath, defaultConfigurationPath)
+ def resolveAgainst(baseDirectory: File) = List(baseDirectory toURI, new File(System.getProperty("user.home")) toURI, classLocation(getClass).toURI)
def classLocation(cl: Class[_]): URL =
{
val codeSource = cl.getProtectionDomain.getCodeSource
- if(codeSource == null) throw new BootException("No class location for " + cl)
+ if(codeSource == null) error("No class location for " + cl)
else codeSource.getLocation
}
}
Oops, something went wrong.

0 comments on commit 33434bc

Please sign in to comment.