mirror of https://github.com/sbt/sbt.git
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:
parent
e4848efcc8
commit
0f447c201e
|
|
@ -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 =
|
||||
|
|
|
|||
Loading…
Reference in New Issue