mirror of https://github.com/sbt/sbt.git
32 lines
1.6 KiB
Scala
32 lines
1.6 KiB
Scala
package xsbt
|
|
|
|
import java.io.File
|
|
|
|
/** Represents the source for Scala classes for a given version. The reason both a ClassLoader and the jars are required
|
|
* is that the compiler requires the location of the library/compiler jars on the (boot)classpath and the loader is used
|
|
* for the compiler itself.
|
|
* The 'version' field is the version used to obtain the Scala classes. This is typically the version for the maven repository.
|
|
* The 'actualVersion' field should be used to uniquely identify the compiler. It is obtained from the compiler.properties file.*/
|
|
final class ScalaInstance(val version: String, val loader: ClassLoader, val libraryJar: File, val compilerJar: File) extends NotNull
|
|
{
|
|
/** Gets the version of Scala in the compiler.properties file from the loader. This version may be different than that given by 'version'*/
|
|
lazy val actualVersion =
|
|
{
|
|
import ScalaInstance.VersionPrefix
|
|
val v = Class.forName("scala.tools.nsc.Properties", true, loader).getMethod("versionString").invoke(null).toString
|
|
if(v.startsWith(VersionPrefix)) v.substring(VersionPrefix.length) else v
|
|
}
|
|
}
|
|
object ScalaInstance
|
|
{
|
|
val VersionPrefix = "version "
|
|
/** Creates a ScalaInstance using the given provider to obtain the jars and loader.*/
|
|
def apply(version: String, provider: xsbti.ScalaProvider) =
|
|
{
|
|
val scalaLibDirectory = provider.getScalaHome(version)
|
|
// these get the locations of the scala jars given the location of the lib/ directory
|
|
val libraryJar = new File(scalaLibDirectory, "scala-library.jar")
|
|
val compilerJar = new File(scalaLibDirectory, "scala-compiler.jar")
|
|
new ScalaInstance(version, provider.getScalaLoader(version), libraryJar, compilerJar)
|
|
}
|
|
} |