2009-08-16 20:29:08 +02:00
import sbt._
2009-11-03 05:02:00 +01:00
import java.io.File
2009-08-16 20:29:08 +02:00
class XSbt ( info : ProjectInfo ) extends ParentProject ( info )
{
2009-08-26 14:38:20 +02:00
/* Subproject declarations */
2009-09-09 05:13:30 +02:00
val launchInterfaceSub = project ( launchPath / "interface" , "Launcher Interface" , new LaunchInterfaceProject ( _ ) )
2009-08-21 14:12:43 +02:00
val launchSub = project ( launchPath , "Launcher" , new LaunchProject ( _ ) , launchInterfaceSub )
2009-08-17 16:51:43 +02:00
val interfaceSub = project ( "interface" , "Interface" , new InterfaceProject ( _ ) )
2010-01-01 00:56:37 +01:00
val apiSub = baseProject ( compilePath / "api" , "API" , interfaceSub )
2009-08-16 20:29:08 +02:00
2009-11-09 15:34:52 +01:00
val controlSub = baseProject ( utilPath / "control" , "Control" )
val collectionSub = baseProject ( utilPath / "collection" , "Collections" )
2009-08-24 04:21:15 +02:00
val ioSub = project ( utilPath / "io" , "IO" , new IOProject ( _ ) , controlSub )
2009-11-09 15:34:52 +01:00
val classpathSub = baseProject ( utilPath / "classpath" , "Classpath" )
2009-08-16 20:29:08 +02:00
2009-09-27 20:39:26 +02:00
val ivySub = project ( "ivy" , "Ivy" , new IvyProject ( _ ) , interfaceSub , launchInterfaceSub )
2009-11-09 15:34:52 +01:00
val logSub = baseProject ( utilPath / "log" , "Logging" , interfaceSub )
2009-11-14 20:53:17 +01:00
val datatypeSub = baseProject ( "util" / "datatype" , "Datatype Generator" , ioSub )
2009-11-09 15:34:52 +01:00
2009-11-11 14:30:39 +01:00
val testSub = project ( "scripted" , "Test" , new TestProject ( _ ) , ioSub )
2009-09-05 18:19:34 +02:00
2009-09-09 05:13:30 +02:00
val compileInterfaceSub = project ( compilePath / "interface" , "Compiler Interface" , new CompilerInterfaceProject ( _ ) , interfaceSub )
2009-08-16 20:29:08 +02:00
2009-08-29 16:19:00 +02:00
val taskSub = project ( tasksPath , "Tasks" , new TaskProject ( _ ) , controlSub , collectionSub )
2009-08-31 16:45:32 +02:00
val cacheSub = project ( cachePath , "Cache" , new CacheProject ( _ ) , taskSub , ioSub )
2009-11-09 15:34:52 +01:00
val trackingSub = baseProject ( cachePath / "tracking" , "Tracking" , cacheSub )
2009-08-24 04:21:15 +02:00
val compilerSub = project ( compilePath , "Compile" , new CompileProject ( _ ) ,
2009-11-22 01:00:49 +01:00
launchInterfaceSub , interfaceSub , ivySub , ioSub , classpathSub , compileInterfaceSub )
2010-01-06 01:50:43 +01:00
val stdTaskSub = project ( tasksPath / "standard" , "Standard Tasks" , new StandardTaskProject ( _ ) , trackingSub , compilerSub , apiSub )
val altCompilerSub = baseProject ( "main" , "Alternate Compiler Test" , stdTaskSub , logSub )
2009-08-16 20:29:08 +02:00
2009-09-09 05:13:30 +02:00
val distSub = project ( "dist" , "Distribution" , new DistProject ( _ ) )
2009-08-26 14:38:20 +02:00
2009-11-11 14:30:39 +01:00
def baseProject ( path : Path , name : String , deps : Project * ) = project ( path , name , new Base ( _ ) , deps : _ * )
2009-11-09 15:34:52 +01:00
2009-09-09 05:13:30 +02:00
/* Multi-subproject paths */
2009-08-31 16:45:32 +02:00
def cachePath = path ( "cache" )
2009-08-29 16:19:00 +02:00
def tasksPath = path ( "tasks" )
2009-08-21 14:12:43 +02:00
def launchPath = path ( "launch" )
2009-08-18 06:51:08 +02:00
def utilPath = path ( "util" )
def compilePath = path ( "compile" )
2009-08-19 05:25:34 +02:00
2009-09-09 05:13:30 +02:00
class DistProject ( info : ProjectInfo ) extends Base ( info ) with ManagedBase
{
lazy val interDependencies = ( XSbt . this . dependencies . toList -- List ( distSub , launchSub , launchInterfaceSub , interfaceSub , compileInterfaceSub ) ) flatMap {
case b : Base => b : : Nil ; case _ => Nil
}
override def dependencies = interfaceSub : : compileInterfaceSub :: interDependencies
lazy val dist = increment dependsOn ( publishLocal )
override def artifactID = "xsbt"
}
def increment = task {
val Array ( keep , inc ) = projectVersion . value . toString . split ( "_" )
projectVersion ( ) = Version . fromString ( keep + "_" + ( inc . toInt + 1 ) ) . right . get
log . info ( "Version is now " + projectVersion . value )
None
}
def compilerInterfaceClasspath = compileInterfaceSub . projectClasspath ( Configurations . Test )
2009-08-26 14:38:20 +02:00
//run in parallel
2009-12-18 15:46:04 +01:00
override def parallelExecution = false
2009-08-26 14:38:20 +02:00
2009-10-24 04:04:15 +02:00
override def managedStyle = ManagedStyle . Ivy
2009-11-03 05:02:00 +01:00
val publishTo = Resolver . file ( "test-repo" , new File ( "/var/dbwww/repo/" ) )
2009-10-24 04:04:15 +02:00
2009-08-26 14:38:20 +02:00
/* Subproject configurations */
2009-09-09 05:13:30 +02:00
class LaunchProject ( info : ProjectInfo ) extends Base ( info ) with TestWithIO with TestDependencies with ProguardLaunch
2009-08-21 14:12:43 +02:00
{
2009-09-09 05:13:30 +02:00
val jline = "jline" % "jline" % "0.9.94"
2009-08-21 14:12:43 +02:00
val ivy = "org.apache.ivy" % "ivy" % "2.0.0"
2009-09-09 05:13:30 +02:00
def rawJarPath = jarPath
2009-09-27 20:39:26 +02:00
override final def crossScalaVersions = Set . empty // don't need to cross-build, since the distributed jar is standalone (proguard)
2009-09-09 05:13:30 +02:00
lazy val rawPackage = packageTask ( packagePaths +++ launchInterfaceSub . packagePaths , rawJarPath , packageOptions ) . dependsOn ( compile )
2009-08-24 04:21:15 +02:00
// to test the retrieving and loading of the main sbt, we package and publish the test classes to the local repository
2009-09-27 20:39:26 +02:00
override def defaultMainArtifact = Artifact ( testID )
override def projectID = ModuleID ( organization , testID , "test-" + version )
override def packageAction = packageTask ( packageTestPaths , outputPath / ( testID + "-" + projectID . revision + ".jar" ) , packageOptions ) . dependsOn ( rawTestCompile )
2009-08-24 04:21:15 +02:00
override def deliverProjectDependencies = Nil
2009-09-27 20:39:26 +02:00
def testID = "launch-test"
2009-12-18 23:46:57 +01:00
override def testClasspath = super . testClasspath +++ interfaceSub . compileClasspath +++ interfaceSub . mainResourcesPath
2009-09-27 20:39:26 +02:00
lazy val rawTestCompile = super . testCompileAction dependsOn ( interfaceSub . compile )
2009-11-12 00:41:39 +01:00
override def testCompileAction = publishLocal dependsOn ( rawTestCompile , interfaceSub . publishLocal )
2009-08-21 14:12:43 +02:00
}
2009-08-24 04:21:15 +02:00
trait TestDependencies extends Project
2009-08-16 20:29:08 +02:00
{
2009-10-19 04:25:50 +02:00
val sc = "org.scala-tools.testing" %% "scalacheck" % "1.6" % "test"
2009-10-15 02:53:15 +02:00
val sp = "org.scala-tools.testing" % "specs" % "1.6.0" % "test"
2009-08-16 20:29:08 +02:00
}
2009-09-04 05:40:47 +02:00
class StandardTaskProject ( info : ProjectInfo ) extends Base ( info )
{
2009-09-05 18:19:34 +02:00
override def testClasspath = super . testClasspath +++ compilerSub . testClasspath --- compilerInterfaceClasspath
2009-09-04 05:40:47 +02:00
}
2009-08-17 16:51:43 +02:00
2009-08-24 04:21:15 +02:00
class IOProject ( info : ProjectInfo ) extends Base ( info ) with TestDependencies
class TaskProject ( info : ProjectInfo ) extends Base ( info ) with TestDependencies
2009-08-16 20:29:08 +02:00
class CacheProject ( info : ProjectInfo ) extends Base ( info )
{
2009-08-26 14:38:20 +02:00
// these compilation options are useful for debugging caches and task composition
2009-08-16 20:29:08 +02:00
//override def compileOptions = super.compileOptions ++ List(Unchecked,ExplainTypes, CompileOption("-Xlog-implicits"))
}
2009-09-09 05:13:30 +02:00
class Base ( info : ProjectInfo ) extends DefaultProject ( info ) with ManagedBase with Component
2009-08-16 20:29:08 +02:00
{
override def scratch = true
2009-09-04 05:40:47 +02:00
override def consoleClasspath = testClasspath
2009-08-16 20:29:08 +02:00
}
2009-09-27 20:39:26 +02:00
class CompileProject ( info : ProjectInfo ) extends Base ( info ) with TestWithLog with TestWithLaunch
2009-08-24 04:21:15 +02:00
{
2009-09-27 20:39:26 +02:00
override def testCompileAction = super . testCompileAction dependsOn ( compileInterfaceSub . `package` , interfaceSub . `package` )
2009-08-26 14:38:20 +02:00
// don't include launch interface in published dependencies because it will be provided by launcher
2009-08-24 04:21:15 +02:00
override def deliverProjectDependencies = Set ( super . deliverProjectDependencies . toSeq : _ * ) - launchInterfaceSub . projectID
2009-11-03 05:02:00 +01:00
override def testClasspath = super . testClasspath +++ compileInterfaceSub . jarPath +++ interfaceSub . jarPath --- compilerInterfaceClasspath --- interfaceSub . mainCompilePath
2009-08-26 14:38:20 +02:00
override def compileOptions = super . compileOptions ++ Seq ( CompileOption ( "-Xno-varargs-conversion" ) ) //needed for invoking nsc.scala.tools.Main.process(Array[String])
2009-08-24 04:21:15 +02:00
}
2009-09-27 20:39:26 +02:00
class IvyProject ( info : ProjectInfo ) extends Base ( info ) with TestWithIO with TestWithLog with TestWithLaunch
2009-08-16 20:29:08 +02:00
{
2009-12-18 15:46:04 +01:00
val ivy = "org.apache.ivy" % "ivy" % "2.1.0"
2009-10-06 02:26:51 +02:00
override def deliverProjectDependencies = Set ( super . deliverProjectDependencies . toSeq : _ * ) - launchInterfaceSub . projectID
2009-08-16 20:29:08 +02:00
}
2009-11-10 04:02:53 +01:00
abstract class BaseInterfaceProject ( info : ProjectInfo ) extends DefaultProject ( info ) with ManagedBase with TestWithLog with Component with JavaProject
class InterfaceProject ( info : ProjectInfo ) extends BaseInterfaceProject ( info )
2009-08-17 16:51:43 +02:00
{
2009-09-09 05:13:30 +02:00
override def componentID : Option [ String ] = Some ( "xsbti" )
2009-11-10 04:02:53 +01:00
override def packageAction = super . packageAction dependsOn generateVersions
def versionPropertiesPath = mainResourcesPath / "xsbt.version.properties"
lazy val generateVersions = task {
import java.util. { Date , TimeZone }
val formatter = new java . text . SimpleDateFormat ( "yyyyMMdd'T'HHmmss" )
formatter . setTimeZone ( TimeZone . getTimeZone ( "GMT" ) )
val timestamp = formatter . format ( new Date )
2009-12-18 23:46:57 +01:00
val content = "version=" + version + "\ntimestamp=" + timestamp
log . info ( "Writing version information to " + versionPropertiesPath + " :\n" + content )
FileUtilities . write ( versionPropertiesPath . asFile , content , log )
2009-11-10 04:02:53 +01:00
}
2009-11-16 14:46:47 +01:00
override def watchPaths = super . watchPaths +++ apiDefinitionPaths --- sources ( generatedBasePath )
override def mainSourceRoots = super . mainSourceRoots +++ ( generatedBasePath # # )
def srcManagedPath = path ( "src_managed" )
def generatedBasePath = srcManagedPath / "main" / "java"
/* * Files that define the datatypes. */
def apiDefinitionPaths : PathFinder = "definition"
def apiDefinitions = apiDefinitionPaths . get . toList . map ( _ . absolutePath )
/* * Delete up the generated sources */
lazy val cleanManagedSrc = cleanTask ( srcManagedPath )
override def cleanAction = super . cleanAction dependsOn ( cleanManagedSrc )
/* * Runs the generator compiled by 'compile', putting the classes in src_managed and processing the definitions 'apiDefinitions'. */
lazy val generateSource = generateSourceAction dependsOn ( cleanManagedSrc , datatypeSub . compile )
def generateSourceAction = runTask ( datatypeSub . getMainClass ( true ) , datatypeSub . runClasspath , "xsbti.api" : : generatedBasePath . absolutePath :: apiDefinitions )
/* * compiles the generated sources */
override def compileAction = super . compileAction dependsOn ( generateSource )
2009-09-09 05:13:30 +02:00
}
2009-11-10 04:02:53 +01:00
class LaunchInterfaceProject ( info : ProjectInfo ) extends BaseInterfaceProject ( info )
2009-09-09 05:13:30 +02:00
{
override def componentID = None
2009-08-17 16:51:43 +02:00
}
2009-11-09 15:34:52 +01:00
class TestProject ( info : ProjectInfo ) extends Base ( info )
{
val process = "org.scala-tools.sbt" % "process" % "0.1"
}
2009-09-05 18:19:34 +02:00
class CompilerInterfaceProject ( info : ProjectInfo ) extends Base ( info ) with SourceProject with TestWithIO with TestWithLog
{
def xTestClasspath = projectClasspath ( Configurations . Test )
2009-09-09 05:13:30 +02:00
override def componentID = Some ( "compiler-interface-src" )
2009-09-05 18:19:34 +02:00
}
2009-09-27 20:39:26 +02:00
trait TestWithIO extends TestWith {
override def testWithTestClasspath = super . testWithTestClasspath ++ Seq ( ioSub )
}
trait TestWithLaunch extends TestWith {
override def testWithTestClasspath = super . testWithTestClasspath ++ Seq ( launchSub )
}
trait TestWithLog extends TestWith {
override def testWithCompileClasspath = super . testWithCompileClasspath ++ Seq ( logSub )
}
trait TestWith extends BasicScalaProject
2009-08-21 14:55:11 +02:00
{
2009-09-27 20:39:26 +02:00
def testWithCompileClasspath : Seq [ BasicScalaProject ] = Nil
def testWithTestClasspath : Seq [ BasicScalaProject ] = Nil
override def testCompileAction = super . testCompileAction dependsOn ( ( testWithTestClasspath . map ( _ . testCompile ) ++ testWithCompileClasspath . map ( _ . compile ) ) : _ * )
override def testClasspath = ( super . testClasspath /: ( testWithTestClasspath . map ( _ . testClasspath ) ++ testWithCompileClasspath . map ( _ . compileClasspath ) ) ) ( _ +++ _ )
2009-08-21 14:55:11 +02:00
}
2009-09-27 20:39:26 +02:00
trait WithLauncherInterface extends BasicScalaProject
2009-09-05 18:19:34 +02:00
{
2009-09-27 20:39:26 +02:00
override def deliverProjectDependencies = super . deliverProjectDependencies . toList - launchInterfaceSub . projectID
2009-09-05 18:19:34 +02:00
}
2009-08-18 06:51:08 +02:00
}
2009-09-26 08:18:04 +02:00
trait JavaProject extends BasicScalaProject
{
override final def crossScalaVersions = Set . empty // don't need to cross-build Java sources
// ensure that interfaces are only Java sources and that they cannot reference Scala classes
override def mainSources = descendents ( mainSourceRoots , "*.java" )
override def compileOrder = CompileOrder . JavaThenScala
}
2009-08-18 06:51:08 +02:00
trait SourceProject extends BasicScalaProject
{
2009-08-26 14:38:20 +02:00
override final def crossScalaVersions = Set . empty // don't need to cross-build a source package
override def packagePaths = mainResources +++ mainSources // the default artifact is a jar of the main sources and resources
2009-08-24 04:21:15 +02:00
}
trait ManagedBase extends BasicScalaProject
{
2009-10-06 02:26:51 +02:00
override def deliverScalaDependencies = Nil
override def crossScalaVersions = Set ( "2.7.2" , "2.7.5" )
2009-08-24 04:21:15 +02:00
override def managedStyle = ManagedStyle . Ivy
override def useDefaultConfigurations = false
val defaultConf = Configurations . Default
val testConf = Configurations . Test
2009-09-09 05:13:30 +02:00
}
trait Component extends DefaultProject
{
override def projectID = componentID match { case Some ( id ) => super . projectID extra ( "e:component" -> id ) ; case None => super . projectID }
def componentID : Option [ String ] = None
2009-08-16 20:29:08 +02:00
}