2009-08-24 04:21:15 +02:00
|
|
|
package xsbt
|
|
|
|
|
|
|
|
|
|
import java.io.File
|
|
|
|
|
import FileUtilities.withTemporaryDirectory
|
|
|
|
|
import org.specs._
|
|
|
|
|
|
|
|
|
|
// compile w/ analysis a bit hard to test properly right now:
|
|
|
|
|
// requires compile project to depend on +publish-local, which is not possible in sbt (addressed in xsbt, but that doesn't help here!)
|
|
|
|
|
object CompileTest extends Specification
|
|
|
|
|
{
|
|
|
|
|
"Analysis compiler" should {
|
|
|
|
|
"compile basic sources" in {
|
2009-08-31 16:46:22 +02:00
|
|
|
WithCompiler( "2.7.2" )(testCompileAnalysis)
|
2009-08-24 04:21:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
2009-09-05 21:01:04 +02:00
|
|
|
private def testCompileAnalysis(compiler: AnalyzingCompiler, log: CompileLogger)
|
2009-08-24 04:21:15 +02:00
|
|
|
{
|
|
|
|
|
WithFiles( new File("Test.scala") -> "object Test" ) { sources =>
|
|
|
|
|
withTemporaryDirectory { temp =>
|
|
|
|
|
val callback = new xsbti.TestCallback(Array())
|
2009-09-05 18:19:34 +02:00
|
|
|
compiler(Set() ++ sources, Set.empty, temp, Nil, callback, 10, log)
|
2009-08-24 04:21:15 +02:00
|
|
|
(callback.beganSources) must haveTheSameElementsAs(sources)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-31 16:46:22 +02:00
|
|
|
}
|
|
|
|
|
object WithCompiler
|
|
|
|
|
{
|
2009-09-05 21:01:04 +02:00
|
|
|
def apply[T](scalaVersion: String)(f: (AnalyzingCompiler, CompileLogger) => T): T =
|
2009-08-31 16:46:22 +02:00
|
|
|
{
|
2009-09-05 18:19:34 +02:00
|
|
|
System.setProperty("scala.home", "") // need to make sure scala.home is unset
|
|
|
|
|
val log = new TestIvyLogger with CompileLogger
|
|
|
|
|
log.setLevel(Level.Debug)
|
|
|
|
|
log.bufferQuietly {
|
2009-08-31 16:46:22 +02:00
|
|
|
FileUtilities.withTemporaryDirectory { temp =>
|
|
|
|
|
val launch = new xsbt.boot.Launch(temp)
|
|
|
|
|
val sbtVersion = xsbti.Versions.Sbt
|
|
|
|
|
val manager = new ComponentManager(launch.getSbtHome(sbtVersion, scalaVersion), log)
|
|
|
|
|
prepare(manager, ComponentCompiler.compilerInterfaceSrcID, "CompilerInterface.scala")
|
|
|
|
|
prepare(manager, ComponentCompiler.xsbtiID, classOf[xsbti.AnalysisCallback])
|
2009-09-05 21:01:04 +02:00
|
|
|
f(AnalyzingCompiler(scalaVersion, launch, manager), log)
|
2009-08-31 16:46:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-24 04:21:15 +02:00
|
|
|
private def prepare(manager: ComponentManager, id: String, resource: Class[_]): Unit =
|
|
|
|
|
{
|
|
|
|
|
val src = FileUtilities.classLocationFile(resource)
|
|
|
|
|
prepare(manager, id, src)
|
|
|
|
|
}
|
|
|
|
|
private def prepare(manager: ComponentManager, id: String, resource: String): Unit =
|
|
|
|
|
{
|
|
|
|
|
val src = getClass.getClassLoader.getResource(resource)
|
|
|
|
|
if(src eq null)
|
|
|
|
|
error("Resource not found: " + resource)
|
|
|
|
|
prepare(manager, id, FileUtilities.asFile(src))
|
|
|
|
|
}
|
2009-08-29 16:19:00 +02:00
|
|
|
import Paths._
|
2009-08-24 04:21:15 +02:00
|
|
|
private def prepare(manager: ComponentManager, id: String, file: File): Unit =
|
2009-08-29 16:19:00 +02:00
|
|
|
FileUtilities.copy(file x FileMapper.flat(manager.location(id)))
|
2009-08-24 04:21:15 +02:00
|
|
|
}
|