diff options
-rw-r--r-- | stage2/AdminStage2.scala | 3 | ||||
-rw-r--r-- | stage2/AdminTasks.scala | 4 | ||||
-rw-r--r-- | stage2/BasicBuild.scala | 6 | ||||
-rw-r--r-- | stage2/Scaffold.scala | 48 |
4 files changed, 19 insertions, 42 deletions
diff --git a/stage2/AdminStage2.scala b/stage2/AdminStage2.scala index 59f8f7d..d923b22 100644 --- a/stage2/AdminStage2.scala +++ b/stage2/AdminStage2.scala @@ -1,10 +1,11 @@ package cbt +import java.io._ object AdminStage2{ def main(_args: Array[String]) = { val args = _args.drop(1).dropWhile(Seq("admin","direct") contains _) val init = new Init(args) val lib = new Lib(init.logger) - val adminTasks = new AdminTasks(lib, args) + val adminTasks = new AdminTasks(lib, args, new File(_args(0))) new lib.ReflectObject(adminTasks){ def usage: String = "Available methods: " ++ lib.taskNames(subclassType).mkString(" ") }.callNullary(args.lift(0)) diff --git a/stage2/AdminTasks.scala b/stage2/AdminTasks.scala index bce0ae7..e7fc78b 100644 --- a/stage2/AdminTasks.scala +++ b/stage2/AdminTasks.scala @@ -1,6 +1,7 @@ package cbt import scala.collection.immutable.Seq -class AdminTasks(lib: Lib, args: Array[String]){ +import java.io._ +class AdminTasks(lib: Lib, args: Array[String], cwd: File){ implicit val logger: Logger = lib.logger def resolve = { ClassPath.flatten( @@ -30,4 +31,5 @@ class AdminTasks(lib: Lib, args: Array[String]){ "scala.tools.nsc.MainGenericRunner", Seq("-cp", scalac.classpath.string), scalac.classLoader ) } + def scaffoldBasicBuild: Unit = lib.scaffoldBasicBuild( cwd ) } diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala index 93a55ca..2f90197 100644 --- a/stage2/BasicBuild.scala +++ b/stage2/BasicBuild.scala @@ -27,11 +27,7 @@ class Build(val context: Context) extends Dependency with TriggerLoop{ final def projectDirectory: File = lib.realpath(context.cwd) assert( projectDirectory.exists, "projectDirectory does not exist: " ++ projectDirectory.string ) final def usage: Unit = new lib.ReflectBuild(this).usage -/* - def scaffold: Unit = lib.generateBasicBuildFile( - projectDirectory, scalaVersion, groupId, artifactId, version - ) -*/ + // ========== meta data ========== def scalaVersion: String = constants.scalaVersion diff --git a/stage2/Scaffold.scala b/stage2/Scaffold.scala index 4226e21..e181ebf 100644 --- a/stage2/Scaffold.scala +++ b/stage2/Scaffold.scala @@ -5,13 +5,15 @@ import ammonite.ops.{cwd => _,_} trait Scaffold{ def logger: Logger - - def generateBasicBuildFile( - projectDirectory: File, - scalaVersion: String, - groupId: String, - artifactId: String, - version: String + + private def createFile( projectDirectory: File, fileName: String, code: String ){ + write( Path( projectDirectory.string ++ "/" ++ fileName ), code ) + import scala.Console._ + println( GREEN ++ "Created " ++ fileName ++ RESET ) + } + + def scaffoldBasicBuild( + projectDirectory: File ): Unit = { /** TODO: @@ -20,25 +22,17 @@ trait Scaffold{ - maybe not generate all of this, e.g. offer different variants */ - val generatedFiles = Seq( - "build/build.scala" -> s"""import cbt._ + createFile(projectDirectory, "build/build.scala", s"""import cbt._ import java.net.URL import java.io.File import scala.collection.immutable.Seq -class Build(context: Context) extends BasicBuild(context) with BuildShared{ - override def artifactId: String = "$artifactId" - override def groupId = "$groupId" - +class Build(context: Context) extends BasicBuild(context){ override def dependencies = super.dependencies ++ Seq( // don't forget super.dependencies here // "org.cvogt" %% "scala-extensions" % "0.4.1" ) - - // required for .pom file - override def name = artifactId - override def description : String = lib.requiredForPom("description") } -""", +"""/*, "build/build/build.scala" -> s"""import cbt._ import java.net.URL @@ -46,8 +40,6 @@ import java.io.File import scala.collection.immutable.Seq class Build(context: Context) extends BuildBuild(context){ - override def scalaVersion: String = "2.11.8" - override def dependencies = super.dependencies ++ Seq( BuildDependency( projectDirectory.parent ++ "/build-shared") // , "com.lihaoyi" %% "ammonite-ops" % "0.5.5" @@ -126,23 +118,9 @@ trait BuildShared extends BasicBuild{ override def scmConnection: String = lib.requiredForPom("scmConnection") override def pomExtra: Seq[scala.xml.Node] = Seq() } -""" +"""*/ ) - generatedFiles.map{ - case ( fileName, code ) => - scala.util.Try{ - write( Path( projectDirectory.string ++ "/" ++ fileName ), code ) - import scala.Console._ - println( GREEN ++ "Created " ++ fileName ++ RESET ) - } - }.foreach( - _.recover{ - case e: java.nio.file.FileAlreadyExistsException => - e.printStackTrace - }.get - ) - return () } }
\ No newline at end of file |