diff options
Diffstat (limited to 'stage2')
-rw-r--r-- | stage2/BasicBuild.scala | 30 | ||||
-rw-r--r-- | stage2/BuildBuild.scala | 4 | ||||
-rw-r--r-- | stage2/BuildDependency.scala | 4 | ||||
-rw-r--r-- | stage2/GitDependency.scala | 2 | ||||
-rw-r--r-- | stage2/Lib.scala | 23 | ||||
-rw-r--r-- | stage2/Scaffold.scala | 117 | ||||
-rw-r--r-- | stage2/ToolsTasks.scala | 3 | ||||
-rw-r--r-- | stage2/mixins.scala | 57 | ||||
-rw-r--r-- | stage2/plugins/AdvancedFlags.scala | 10 | ||||
-rw-r--r-- | stage2/plugins/GithubPom.scala | 11 | ||||
-rw-r--r-- | stage2/plugins/ScalaParadise.scala | 29 | ||||
-rw-r--r-- | stage2/pom.scala | 3 |
12 files changed, 80 insertions, 213 deletions
diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala index 4be0e58..42384db 100644 --- a/stage2/BasicBuild.scala +++ b/stage2/BasicBuild.scala @@ -9,17 +9,6 @@ import java.util.jar._ import scala.util._ -trait Recommended extends BaseBuild{ - override def scalacOptions = super.scalacOptions ++ Seq( - "-feature", - "-deprecation", - "-unchecked", - "-language:postfixOps", - "-language:implicitConversions", - "-language:higherKinds", - "-language:existentials" - ) -} class BasicBuild(val context: Context) extends BaseBuild trait BaseBuild extends DependencyImplementation with BuildInterface with TriggerLoop with SbtDependencyDsl{ def context: Context @@ -98,7 +87,7 @@ trait BaseBuild extends DependencyImplementation with BuildInterface with Trigge scalaVersion: String = scalaMajorVersion ) = lib.ScalaDependency( groupId, artifactId, version, classifier, scalaVersion ) - final def BuildDependency(path: File) = cbt.BuildDependency( + final def DirectoryDependency(path: File) = cbt.DirectoryDependency( context.copy( projectDirectory = path, args = Seq() ) ) @@ -120,7 +109,11 @@ trait BaseBuild extends DependencyImplementation with BuildInterface with Trigge // ========== compile, run, test ========== /** scalac options used for zinc and scaladoc */ - def scalacOptions: Seq[String] = Seq() + def scalacOptions: Seq[String] = Seq( + "-feature", + "-deprecation", + "-unchecked" + ) private object needsUpdateCache extends Cache[Boolean] def needsUpdate: Boolean = needsUpdateCache( @@ -143,9 +136,12 @@ trait BaseBuild extends DependencyImplementation with BuildInterface with Trigge def runClass: String = "Main" def run: ExitCode = lib.runMainIfFound( runClass, context.args, classLoader(context.classLoaderCache) ) - def test: Option[ExitCode] = { - lib.test(context) - } + def test: Option[ExitCode] = + Some(new lib.ReflectBuild( + DirectoryDependency(projectDirectory++"/test").build + ).callNullary(Some("run"))) + def t = test + def rt = recursiveUnsafe(Some("test")) def recursiveSafe(_run: BuildInterface => Any): ExitCode = { val builds = (this +: transitiveDependencies).collect{ @@ -192,9 +188,7 @@ trait BaseBuild extends DependencyImplementation with BuildInterface with Trigge } def c = compile - def t = test def r = run - def rt = recursiveUnsafe(Some("test")) /* context.logger.composition(">"*80) diff --git a/stage2/BuildBuild.scala b/stage2/BuildBuild.scala index 7eab5e6..db5374c 100644 --- a/stage2/BuildBuild.scala +++ b/stage2/BuildBuild.scala @@ -8,8 +8,8 @@ trait BuildBuild extends BaseBuild{ ) object plugins{ - final val scalaTest = BuildDependency( managedContext.cbtHome ++ "/plugins/scalatest" ) - final val sbtLayout = BuildDependency( managedContext.cbtHome ++ "/plugins/sbt_layout" ) + final val scalaTest = DirectoryDependency( managedContext.cbtHome ++ "/plugins/scalatest" ) + final val sbtLayout = DirectoryDependency( managedContext.cbtHome ++ "/plugins/sbt_layout" ) } override def dependencies = diff --git a/stage2/BuildDependency.scala b/stage2/BuildDependency.scala index aba35c6..c0b53ad 100644 --- a/stage2/BuildDependency.scala +++ b/stage2/BuildDependency.scala @@ -15,7 +15,7 @@ trait TriggerLoop extends DependencyImplementation{ def triggerLoopFiles: Seq[File] } /** You likely want to use the factory method in the BasicBuild class instead of this. */ -case class BuildDependency(context: Context) extends TriggerLoop{ +case class DirectoryDependency(context: Context) extends TriggerLoop{ override def show = this.getClass.getSimpleName ++ "(" ++ context.projectDirectory.string ++ ")" final override lazy val logger = context.logger final override lazy val lib: Lib = new Lib(logger) @@ -28,7 +28,7 @@ case class BuildDependency(context: Context) extends TriggerLoop{ def targetClasspath = ClassPath() } /* -case class DependencyOr(first: BuildDependency, second: JavaDependency) extends ProjectProxy with BuildDependencyBase{ +case class DependencyOr(first: DirectoryDependency, second: JavaDependency) extends ProjectProxy with DirectoryDependencyBase{ val isFirst = new File(first.context.projectDirectory).exists def triggerLoopFiles = if(isFirst) first.triggerLoopFiles else Seq() protected val delegate = if(isFirst) first else second diff --git a/stage2/GitDependency.scala b/stage2/GitDependency.scala index bb3cc63..6510ede 100644 --- a/stage2/GitDependency.scala +++ b/stage2/GitDependency.scala @@ -39,7 +39,7 @@ case class GitDependency( } private object dependencyCache extends Cache[DependencyImplementation] def dependency = dependencyCache{ - BuildDependency( + DirectoryDependency( context.copy( projectDirectory = checkout ++ subDirectory.map("/" ++ _).getOrElse("") ) diff --git a/stage2/Lib.scala b/stage2/Lib.scala index 2430c1d..c08657f 100644 --- a/stage2/Lib.scala +++ b/stage2/Lib.scala @@ -107,26 +107,6 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ } } - def test( context: Context ): Option[ExitCode] = { - if((context.projectDirectory ++ "/test").exists){ - val loggers = logger.enabledLoggers.mkString(",") - // FIXME: this is a hack to pass logger args on to the tests. - // should probably have a more structured way - val loggerArg = if(loggers != "") Some("-Dlog="++loggers) else None - - logger.lib(s"invoke testDefault( $context )") - val exitCode: ExitCode = - new ReflectBuild( - loadDynamic( - context.copy( projectDirectory = context.projectDirectory ++ "/test", args = loggerArg.toVector ++ context.args ), - new BasicBuild(_) with mixins.Test - ) - ).callNullary( Some("run") ) - logger.lib(s"return testDefault( $context )") - Some(exitCode) - } else None - } - // task reflection helpers def tasks(cls:Class[_]): Map[String, Method] = Stream @@ -153,8 +133,7 @@ final class Lib(logger: Logger) extends Stage1Lib(logger) with Scaffold{ val baseTasks = Seq( classOf[BasicBuild], classOf[PackageJars], - classOf[Publish], - classOf[Recommended] + classOf[Publish] ).flatMap(lib.taskNames).distinct.sorted val thisTasks = lib.taskNames(buildClass) diff baseTasks ( diff --git a/stage2/Scaffold.scala b/stage2/Scaffold.scala index 0214a0d..32e474f 100644 --- a/stage2/Scaffold.scala +++ b/stage2/Scaffold.scala @@ -24,55 +24,25 @@ trait Scaffold{ ) } - def createBasicBuild( + def createBuild( projectDirectory: File ): Unit = { createFile(projectDirectory, "build/build.scala", s"""import cbt._ class Build(val context: Context) extends BaseBuild{ /* - override def dependencies = ( - super.dependencies // don't forget super.dependencies here - ++ + override def dependencies = + super.dependencies ++ // don't forget super.dependencies here + Seq( + // source dependency + DirectoryDependency( projectDirectory ++ "/subProject" ) + ) ++ Resolver( mavenCentral ).bind( - // automatically add Scala major version to artifact id - // CBT-style Scala dependency + // CBT-style Scala dependencies ScalaDependency( "com.lihaoyi", "ammonite-ops", "0.5.5" ) - // or SBT-style Scala dependency - "com.lihaoyi" %% "ammonite-ops" % "0.5.5" - - // don't mess with the artifact id - // CBT-Style Java dependency MavenDependency( "com.lihaoyi", "ammonite-ops_2.11", "0.5.5" ) - // or SBT-style Java dependency - "com.lihaoyi" % "ammonite-ops_2.11" % "0.5.5" - ) - ) - */ -} -""" - ) - } - def createBuildBuild( - projectDirectory: File - ): Unit = { - createFile(projectDirectory, "build/build/build.scala", s"""import cbt._ -class Build(val context: Context) extends BuildBuild{ -/* - override def dependencies = ( - super.dependencies // don't forget super.dependencies here - ++ - Resolver( mavenCentral ).bind( - // automatically add Scala major version to artifact id - // CBT-style Scala dependency - ScalaDependency( "com.lihaoyi", "ammonite-ops", "0.5.5" ) - // or SBT-style Scala dependency + // SBT-style dependencies "com.lihaoyi" %% "ammonite-ops" % "0.5.5" - - // don't mess with the artifact id - // CBT-Style Java dependency - MavenDependency( "com.lihaoyi", "ammonite-ops_2.11", "0.5.5" ) - // or SBT-style Java dependency "com.lihaoyi" % "ammonite-ops_2.11" % "0.5.5" ) ) @@ -81,73 +51,4 @@ class Build(val context: Context) extends BuildBuild{ """ ) } - -/*, - - "build/build/build.scala" -> s"""import cbt._ -class Build(val context: Context) extends BuildBuild{ - override def dependencies = super.dependencies ++ Seq( - BuildDependency( projectDirectory.parent ++ "/build-shared") - // , "com.lihaoyi" %% "ammonite-ops" % "0.5.5" - ) -} -""", - - "test/Main.scala" -> s"""object Main{ - def main( args: Array[String] ) = { - assert( false, "Go. Write some tests :)!" ) - } -} -""", - - "test/build/build.scala" -> s"""import cbt._ -class Build(val context: Context) extends BaseBuild with BuildShared/* with mixins.ScalaTest*/{ - // def scalaTestVersion = "2.2.6" - - override def dependencies = super.dependencies ++ Seq( - // , "org.scalacheck" %% "scalacheck" % "1.13.0" - ) } -""", - - "test/build/build/build.scala" -> s"""import cbt._ -class Build(val context: Context) extends BuildBuild{ - override def scalaVersion: String = "2.11.8" - - override def dependencies = super.dependencies ++ Seq( - BuildDependency( projectDirectory.parent.parent ++ "/build-shared") - // , "com.lihaoyi" %% "ammonite-ops" % "0.5.5" - ) -} -""", - - "build-shared/build/build.scala" -> s"""import cbt._ -class Build(val context: Context) extends BaseBuild{ - override def scalaVersion: String = "$scalaVersion" - - override def dependencies = super.dependencies ++ Seq( // don't forget super.dependencies here - CbtDependency - // , "org.cvogt" %% "scala-extensions" % "0.4.1" - ) -} -""", - - "build-shared/BuildShared.scala" -> s"""import cbt._ -trait BuildShared extends BaseBuild{ - override def scalaVersion: String = "$scalaVersion" - override def enableConcurrency = false // enable for speed, disable for debugging - - override def groupId = "$groupId" - override def version = "$version" - - // required for .pom file - override def url : URL = lib.requiredForPom("url") - override def developers: Seq[Developer] = lib.requiredForPom("developers") - override def licenses : Seq[License] = lib.requiredForPom("licenses") - override def scmUrl : String = lib.requiredForPom("scmUrl") - override def scmConnection: String = lib.requiredForPom("scmConnection") - override def pomExtra: Seq[scala.xml.Node] = Seq() -} -"""*/ - -}
\ No newline at end of file diff --git a/stage2/ToolsTasks.scala b/stage2/ToolsTasks.scala index bac3406..2c4978e 100644 --- a/stage2/ToolsTasks.scala +++ b/stage2/ToolsTasks.scala @@ -16,8 +16,7 @@ class ToolsTasks( private def Resolver( urls: URL* ) = MavenResolver(cbtHasChanged,mavenCache,urls: _*) implicit val logger: Logger = lib.logger def createMain: Unit = lib.createMain( cwd ) - def createBasicBuild: Unit = lib.createBasicBuild( cwd ) - def createBuildBuild: Unit = lib.createBuildBuild( cwd ) + def createBuild: Unit = lib.createBuild( cwd ) def resolve = { ClassPath.flatten( args(1).split(",").toVector.map{ diff --git a/stage2/mixins.scala b/stage2/mixins.scala deleted file mode 100644 index 221fcc5..0000000 --- a/stage2/mixins.scala +++ /dev/null @@ -1,57 +0,0 @@ -package cbt -package mixins -import java.net.URL -import java.io._ -trait Test extends BaseBuild{ - lazy val testedBuild = BuildDependency( projectDirectory.parent ) - override def dependencies = Seq( testedBuild ) ++ super.dependencies - override def defaultScalaVersion = testedBuild.build.scalaVersion -} -trait SbtTest extends Test{ - override def sources = Vector( projectDirectory.parent ++ "/src/test/scala" ) -} - -trait ScalaParadise extends BaseBuild{ - def scalaParadiseVersion = "2.1.0" - - private def scalaParadiseDependency = - Resolver( mavenCentral ).bindOne( - "org.scalamacros" % ("paradise_" ++ scalaVersion) % scalaParadiseVersion - ) - - override def dependencies = ( - super.dependencies // don't forget super.dependencies here - ++ ( - if(scalaVersion.startsWith("2.10.")) - Seq(scalaParadiseDependency) - else - Seq() - ) - ) - - override def scalacOptions = ( - super.scalacOptions - ++ ( - if(scalaVersion.startsWith("2.10.")) - Seq("-Xplugin:"++scalaParadiseDependency.exportedClasspath.string) - else - Seq() - ) - ) -} - -trait Suggested extends BaseBuild{ - override def scalacOptions = super.scalacOptions ++ Seq( - "-language:experimental.macros" - ) -} - -trait Github extends Publish{ - def user: String - def githubProject = name - def githubUser = user - final def githubUserProject = githubUser ++ "/" ++ githubProject - override def url = new URL(s"http://github.com/$githubUserProject") - override def scmUrl = s"git@github.com:$githubUserProject.git" - override def scmConnection = s"scm:git:$scmUrl" -} diff --git a/stage2/plugins/AdvancedFlags.scala b/stage2/plugins/AdvancedFlags.scala new file mode 100644 index 0000000..4ff701d --- /dev/null +++ b/stage2/plugins/AdvancedFlags.scala @@ -0,0 +1,10 @@ +package cbt +trait AdvancedScala extends BaseBuild{ + override def scalacOptions = super.scalacOptions ++ Seq( + "-language:postfixOps", + "-language:implicitConversions", + "-language:higherKinds", + "-language:existentials", + "-language:experimental.macros" + ) +} diff --git a/stage2/plugins/GithubPom.scala b/stage2/plugins/GithubPom.scala new file mode 100644 index 0000000..8b11385 --- /dev/null +++ b/stage2/plugins/GithubPom.scala @@ -0,0 +1,11 @@ +package cbt +import java.net.URL +trait GithubPom extends Publish{ + def user: String + def githubProject = name + def githubUser = user + final def githubUserProject = githubUser ++ "/" ++ githubProject + override def url = new URL(s"http://github.com/$githubUserProject") + override def scmUrl = s"git@github.com:$githubUserProject.git" + override def scmConnection = s"scm:git:$scmUrl" +} diff --git a/stage2/plugins/ScalaParadise.scala b/stage2/plugins/ScalaParadise.scala new file mode 100644 index 0000000..28ee934 --- /dev/null +++ b/stage2/plugins/ScalaParadise.scala @@ -0,0 +1,29 @@ +package cbt +trait ScalaParadise extends BaseBuild{ + def scalaParadiseVersion = "2.1.0" + + private def scalaParadiseDependency = + Resolver( mavenCentral ).bindOne( + "org.scalamacros" % ("paradise_" ++ scalaVersion) % scalaParadiseVersion + ) + + override def dependencies = ( + super.dependencies // don't forget super.dependencies here + ++ ( + if(scalaVersion.startsWith("2.10.")) + Seq(scalaParadiseDependency) + else + Seq() + ) + ) + + override def scalacOptions = ( + super.scalacOptions + ++ ( + if(scalaVersion.startsWith("2.10.")) + Seq("-Xplugin:"++scalaParadiseDependency.jar.string) + else + Seq() + ) + ) +} diff --git a/stage2/pom.scala b/stage2/pom.scala index 610f9f6..b521d51 100644 --- a/stage2/pom.scala +++ b/stage2/pom.scala @@ -1,5 +1,6 @@ package cbt +import java.net.URL case class Organization( name: String, - url: Option[String] + url: Option[URL] ) |