diff options
author | Jan Christopher Vogt <oss.nsp@cvogt.org> | 2016-05-03 11:44:52 +0300 |
---|---|---|
committer | Jan Christopher Vogt <oss.nsp@cvogt.org> | 2016-05-03 11:44:52 +0300 |
commit | 80da1d862e49b1812c51e1b0c6eb26947d36f26d (patch) | |
tree | 6b32cd293475af176c25dfbc46ba16c481fe134c /stage2 | |
parent | 7887c63f6fc56c666f1d0baf6ab54db0ce6c8033 (diff) | |
parent | 137924b53de8429a5f8d899d08b5710868f2d4c3 (diff) | |
download | cbt-80da1d862e49b1812c51e1b0c6eb26947d36f26d.tar.gz cbt-80da1d862e49b1812c51e1b0c6eb26947d36f26d.tar.bz2 cbt-80da1d862e49b1812c51e1b0c6eb26947d36f26d.zip |
Merge pull request #118 from cvogt/chris
Chris
Diffstat (limited to 'stage2')
-rw-r--r-- | stage2/BasicBuild.scala | 7 | ||||
-rw-r--r-- | stage2/SbtDependencyDsl.scala | 28 | ||||
-rw-r--r-- | stage2/Scaffold.scala | 67 | ||||
-rw-r--r-- | stage2/ToolsStage2.scala (renamed from stage2/AdminStage2.scala) | 10 | ||||
-rw-r--r-- | stage2/ToolsTasks.scala (renamed from stage2/AdminTasks.scala) | 28 |
5 files changed, 76 insertions, 64 deletions
diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala index fb5e652..4ae4cd1 100644 --- a/stage2/BasicBuild.scala +++ b/stage2/BasicBuild.scala @@ -47,12 +47,11 @@ class BasicBuild(val context: Context) extends DependencyImplementation with Bui def copy(context: Context): BuildInterface = lib.copy(this.getClass, context).asInstanceOf[BuildInterface] def zincVersion = "0.3.9" - def dependencies: Seq[Dependency] = Seq( + def dependencies: Seq[Dependency] = // FIXME: this should probably be removed - MavenResolver(context.cbtHasChanged, context.paths.mavenCache, MavenResolver.central).resolve( + Resolver( mavenCentral ).bind( "org.scala-lang" % "scala-library" % scalaVersion ) - ) // ========== paths ========== final private val defaultSourceDirectory = projectDirectory ++ "/src" @@ -92,6 +91,8 @@ class BasicBuild(val context: Context) extends DependencyImplementation with Bui } assertSourceDirectories() + def Resolver( urls: URL* ) = MavenResolver( context.cbtHasChanged, context.paths.mavenCache, urls: _* ) + def ScalaDependency( groupId: String, artifactId: String, version: String, classifier: Classifier = Classifier.none, scalaVersion: String = scalaMajorVersion diff --git a/stage2/SbtDependencyDsl.scala b/stage2/SbtDependencyDsl.scala index d8c0786..4c95308 100644 --- a/stage2/SbtDependencyDsl.scala +++ b/stage2/SbtDependencyDsl.scala @@ -12,32 +12,4 @@ trait SbtDependencyDsl{ self: BasicBuild => def %%(artifactId: String) = new DependencyBuilder2( groupId, artifactId, Some(scalaMajorVersion) ) def %(artifactId: String) = new DependencyBuilder2( groupId, artifactId, None ) } - implicit class DependencyBuilder3(d: MavenDependency){ - def %(classifier: String): MavenDependency = d//.copy(classifier = Classifier(Some(classifier))) - } - - /* - /** SBT-like dependency builder DSL for syntax compatibility */ - implicit class DependencyBuilder0(repository: Maven){ - def %(groupId: String) = new DependencyBuilder1b(repository, groupId) - } - implicit class DependencyBuilder1a(groupId: String){ - def %%(artifactId: String) = new DependencyBuilder2( Maven.central, groupId, artifactId, Some(scalaMajorVersion) ) - def %(artifactId: String) = new DependencyBuilder2( Maven.central, groupId, artifactId, None ) - } - class DependencyBuilder1b(repository: Maven, groupId: String){ - def %%(artifactId: String) = new DependencyBuilder2( repository, groupId, artifactId, Some(scalaMajorVersion) ) - def %(artifactId: String) = new DependencyBuilder2( repository, groupId, artifactId, None ) - } - class DependencyBuilder2( repository: Maven, groupId: String, artifactId: String, scalaMajorVersion: Option[String] ){ - def %(version: String) = scalaMajorVersion.map( - v => repository(groupId, artifactId, version, scalaMajorVersion = v) - ).getOrElse( - repository.java(groupId, artifactId, version) - ) - } - implicit class DependencyBuilder3(d: MavenDependency){ - def %(classifier: String) = d.copy(classifier = Classifier(Some(classifier))) - } - */ }
\ No newline at end of file diff --git a/stage2/Scaffold.scala b/stage2/Scaffold.scala index 407fee1..a9db667 100644 --- a/stage2/Scaffold.scala +++ b/stage2/Scaffold.scala @@ -13,7 +13,19 @@ trait Scaffold{ println( GREEN ++ "Created " ++ fileName ++ RESET ) } - def scaffoldBasicBuild( + def createMain( + projectDirectory: File + ): Unit = { + createFile(projectDirectory, "Main.scala", s"""object Main{ + def main( args: Array[String] ) = { + println( Console.GREEN ++ "Hello World" ++ Console.RESET ) + } +} +""" + ) + } + + def createBasicBuild( projectDirectory: File ): Unit = { createFile(projectDirectory, "build/build.scala", s"""import cbt._ @@ -21,22 +33,32 @@ import java.net.URL import java.io.File import scala.collection.immutable.Seq -class Build(context: Context) extends BasicBuild(context){ - override def dependencies = { // don't forget super.dependencies here - super.dependencies :+ MavenResolver(context.cbtHasChanged,context.paths.mavenCache,MavenResolver.central).resolve( - MavenDependency("net.incongru.watchservice","barbary-watchservice","1.0"), - MavenDependency("org.eclipse.jgit", "org.eclipse.jgit", "4.2.0.201601211800-r"), - MavenDependency("com.typesafe.zinc","zinc","0.3.9"), - ScalaDependency("org.scala-lang.modules","scala-xml","1.0.5") +class Build( context: Context ) extends BasicBuild( context ){ + /* + 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 + "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 scaffoldBuildBuild( + def createBuildBuild( projectDirectory: File ): Unit = { createFile(projectDirectory, "build/build/build.scala", s"""import cbt._ @@ -44,14 +66,29 @@ import java.net.URL import java.io.File import scala.collection.immutable.Seq -class Build(context: Context) extends BuildBuild(context){ - override def dependencies = super.dependencies ++ Seq( - // , "com.lihaoyi" %% "ammonite-ops" % "0.5.5" +class Build( context: Context ) extends BuildBuild( context ){ +/* + 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 + "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" + ) ) + */ } """ ) - } /*, diff --git a/stage2/AdminStage2.scala b/stage2/ToolsStage2.scala index f4e61d0..df615fc 100644 --- a/stage2/AdminStage2.scala +++ b/stage2/ToolsStage2.scala @@ -1,12 +1,12 @@ package cbt import java.io._ -object AdminStage2 extends Stage2Base{ +object ToolsStage2 extends Stage2Base{ def run( _args: Stage2Args ): Unit = { - val args = _args.args.dropWhile(Seq("admin","direct") contains _) + val args = _args.args.dropWhile(Seq("tools","direct") contains _) val lib = new Lib(_args.logger) - val adminTasks = new AdminTasks(lib, args, _args.cwd, _args.classLoaderCache, _args.cache, _args.cbtHome, _args.cbtHasChanged) - new lib.ReflectObject(adminTasks){ - def usage: String = "Available methods: " ++ lib.taskNames(adminTasks.getClass).mkString(" ") + val toolsTasks = new ToolsTasks(lib, args, _args.cwd, _args.classLoaderCache, _args.cache, _args.cbtHome, _args.cbtHasChanged) + new lib.ReflectObject(toolsTasks){ + def usage: String = "Available methods: " ++ lib.taskNames(toolsTasks.getClass).mkString(" ") }.callNullary(args.lift(0)) } } diff --git a/stage2/AdminTasks.scala b/stage2/ToolsTasks.scala index 56d6ddf..c39c373 100644 --- a/stage2/AdminTasks.scala +++ b/stage2/ToolsTasks.scala @@ -1,8 +1,9 @@ package cbt import scala.collection.immutable.Seq +import java.net._ import java.io.{Console=>_,_} import java.nio.file._ -class AdminTasks( +class ToolsTasks( lib: Lib, args: Seq[String], cwd: File, @@ -13,14 +14,17 @@ class AdminTasks( ){ private val paths = CbtPaths(cbtHome, cache) import paths._ - private val mavenCentral = MavenResolver(cbtHasChanged,mavenCache,MavenResolver.central) + 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 resolve = { ClassPath.flatten( args(1).split(",").toVector.map{ d => val v = d.split(":") - mavenCentral.resolveOne(MavenDependency(v(0),v(1),v(2))).classpath + Resolver(mavenCentral).bindOne(MavenDependency(v(0),v(1),v(2))).classpath } ) } @@ -28,14 +32,14 @@ class AdminTasks( args(1).split(",").toVector.map{ d => val v = d.split(":") - mavenCentral.resolveOne(MavenDependency(v(0),v(1),v(2))).dependencyTree + Resolver(mavenCentral).bindOne(MavenDependency(v(0),v(1),v(2))).dependencyTree }.mkString("\n\n") } def amm = ammonite def ammonite = { val version = args.lift(1).getOrElse(constants.scalaVersion) val scalac = new ScalaCompilerDependency( cbtHasChanged,mavenCache, version ) - val d = mavenCentral.resolveOne( + val d = Resolver(mavenCentral).bindOne( MavenDependency( "com.lihaoyi","ammonite-repl_2.11.7",args.lift(1).getOrElse("0.5.7") ) @@ -52,24 +56,22 @@ class AdminTasks( "scala.tools.nsc.MainGenericRunner", Seq("-cp", scalac.classpath.string), scalac.classLoader(classLoaderCache) ) } - def scaffoldBasicBuild: Unit = lib.scaffoldBasicBuild( cwd ) - def scaffoldBuildBuild: Unit = lib.scaffoldBuildBuild( cwd ) def cbtEarlyDependencies = { val scalaVersion = args.lift(1).getOrElse(constants.scalaVersion) val scalaMajorVersion = scalaVersion.split("\\.").take(2).mkString(".") val scalaXmlVersion = args.lift(2).getOrElse(constants.scalaXmlVersion) val zincVersion = args.lift(3).getOrElse(constants.zincVersion) val scalaDeps = Seq( - mavenCentral.resolveOne(MavenDependency("org.scala-lang","scala-reflect",scalaVersion)), - mavenCentral.resolveOne(MavenDependency("org.scala-lang","scala-compiler",scalaVersion)) + Resolver(mavenCentral).bindOne(MavenDependency("org.scala-lang","scala-reflect",scalaVersion)), + Resolver(mavenCentral).bindOne(MavenDependency("org.scala-lang","scala-compiler",scalaVersion)) ) val scalaXml = Dependencies( - mavenCentral.resolveOne(MavenDependency("org.scala-lang.modules","scala-xml_"+scalaMajorVersion,scalaXmlVersion)), - mavenCentral.resolveOne(MavenDependency("org.scala-lang","scala-library",scalaVersion)) + Resolver(mavenCentral).bindOne(MavenDependency("org.scala-lang.modules","scala-xml_"+scalaMajorVersion,scalaXmlVersion)), + Resolver(mavenCentral).bindOne(MavenDependency("org.scala-lang","scala-library",scalaVersion)) ) - val zinc = mavenCentral.resolveOne(MavenDependency("com.typesafe.zinc","zinc",zincVersion)) + val zinc = Resolver(mavenCentral).bindOne(MavenDependency("com.typesafe.zinc","zinc",zincVersion)) def valName(dep: BoundMavenDependency) = { val words = dep.artifactId.split("_").head.split("-") @@ -100,7 +102,7 @@ class AdminTasks( val assignments = codeEach(zinc) ++ codeEach(scalaXml) val files = scalaDeps ++ transitive(scalaXml) ++ transitive(zinc) //{ case (name, dep) => s"$name =\n ${tree(dep, 4)};" }.mkString("\n\n ") - val code = s"""// This file was auto-generated using `cbt admin cbtEarlyDependencies` + val code = s"""// This file was auto-generated using `cbt tools cbtEarlyDependencies` package cbt; import java.io.*; import java.nio.file.*; |