directly read compiler.properties so that Scala classes don't need to be loaded when no work needs to be done.

This commit is contained in:
Mark Harrah 2011-10-05 18:09:27 -04:00
parent e4848efcc8
commit 0f447c201e
1 changed files with 13 additions and 0 deletions

View File

@ -58,11 +58,24 @@ object ScalaInstance
/** Gets the version of Scala in the compiler.properties file from the loader.*/
private def actualVersion(scalaLoader: ClassLoader)(label: String) =
try fastActualVersion(scalaLoader)
catch { case e: Exception => slowActualVersion(scalaLoader)(label) }
private def slowActualVersion(scalaLoader: ClassLoader)(label: String) =
{
val v = try { Class.forName("scala.tools.nsc.Properties", true, scalaLoader).getMethod("versionString").invoke(null).toString }
catch { case cause: Exception => throw new InvalidScalaInstance("Scala instance doesn't exist or is invalid: " + label, cause) }
if(v.startsWith(VersionPrefix)) v.substring(VersionPrefix.length) else v
}
private def fastActualVersion(scalaLoader: ClassLoader): String =
{
val stream = scalaLoader.getResourceAsStream("compiler.properties")
try {
val props = new java.util.Properties
props.load(stream)
props.getProperty("version.number")
}
finally stream.close()
}
import java.net.{URL, URLClassLoader}
private def scalaLoader(launcher: xsbti.Launcher, jars: Seq[File]): ClassLoader =