mirror of
https://github.com/sbt/sbt.git
synced 2026-09-07 11:01:08 +02:00
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:
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user