From 2c8257b0c119b38102aa0c3efecffc7fefc9d766 Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Wed, 15 Feb 2017 02:17:08 -0500 Subject: add typed constants for build directory and file and use them everywhere --- stage2/BasicBuild.scala | 4 ++-- stage2/BuildBuild.scala | 12 ++++++------ stage2/Lib.scala | 8 +++++--- test/test.scala | 6 +++--- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/stage2/BasicBuild.scala b/stage2/BasicBuild.scala index e5b3507..f32d4d9 100644 --- a/stage2/BasicBuild.scala +++ b/stage2/BasicBuild.scala @@ -24,12 +24,12 @@ trait BaseBuild extends BuildInterface with DependencyImplementation with Trigge def projectDirectory: File = lib.realpath(context.workingDirectory) assert( projectDirectory.exists, "projectDirectory does not exist: " ++ projectDirectory.string ) assert( - projectDirectory.getName =!= "build" || + projectDirectory.getName =!= lib.buildDirectoryName || { def transitiveInterfaces(cls: Class[_]): Vector[Class[_]] = cls.getInterfaces.toVector.flatMap(i => i +: transitiveInterfaces(i)) transitiveInterfaces(this.getClass).contains(classOf[BuildBuildWithoutEssentials]) }, - "You need to extend BuildBuild in: " + projectDirectory + "/build" + s"You need to extend ${lib.buildBuildClassName} in: " + projectDirectory + "/" ++ lib.buildDirectoryName ) final def usage: String = lib.usage(this.getClass, show) diff --git a/stage2/BuildBuild.scala b/stage2/BuildBuild.scala index 474599a..798bd7d 100644 --- a/stage2/BuildBuild.scala +++ b/stage2/BuildBuild.scala @@ -7,8 +7,8 @@ trait BuildBuild extends BuildBuildWithoutEssentials{ } trait BuildBuildWithoutEssentials extends BaseBuild{ assert( - projectDirectory.getName === "build", - "You can't extend BuildBuild in: " + projectDirectory + "/build" + projectDirectory.getName === lib.buildDirectoryName, + "You can't extend ${lib.buildBuildClassName} in: " + projectDirectory + "/" + lib.buildDirectoryName ) protected final val managedContext = context.copy( @@ -33,12 +33,12 @@ trait BuildBuildWithoutEssentials extends BaseBuild{ super.dependencies :+ context.cbtDependency def managedBuildDirectory: java.io.File = lib.realpath( projectDirectory.parent ) def managedBuild = taskCache[BuildBuildWithoutEssentials]("managedBuild").memoize{ - val managedBuildFile = projectDirectory++"/build.scala" + val managedBuildFile = projectDirectory++("/"++lib.buildFileName) logger.composition("Loading build at " ++ managedBuildDirectory.toString) val build = ( if( !managedBuildFile.exists ){ throw new Exception( - "No file build.scala (lower case) found in " ++ projectDirectory.getPath + s"No file ${lib.buildFileName} (lower case) found in " ++ projectDirectory.getPath ) } else { val contents = new String(Files.readAllBytes(managedBuildFile.toPath)) @@ -78,8 +78,8 @@ trait BuildBuildWithoutEssentials extends BaseBuild{ try{ build.asInstanceOf[BuildInterface] } catch { - case e: ClassCastException if e.getMessage.contains("Build cannot be cast to cbt.BuildInterface") => - throw new Exception("Your Build class needs to extend BaseBuild in: "+projectDirectory, e) + case e: ClassCastException if e.getMessage.contains(s"${lib.buildClassName} cannot be cast to cbt.BuildInterface") => + throw new Exception(s"Your ${lib.buildClassName} class needs to extend BaseBuild in: "+projectDirectory, e) } } override def triggerLoopFiles = super.triggerLoopFiles ++ managedBuild.triggerLoopFiles diff --git a/stage2/Lib.scala b/stage2/Lib.scala index 2642ec9..0d382f2 100644 --- a/stage2/Lib.scala +++ b/stage2/Lib.scala @@ -18,6 +18,8 @@ case class Developer(id: String, name: String, timezone: String, url: URL) final class Lib(val logger: Logger) extends Stage1Lib(logger) with Scaffold{ lib => + val buildFileName = "build.scala" + val buildDirectoryName = "build" val buildClassName = "Build" val buildBuildClassName = "BuildBuild" @@ -37,7 +39,7 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger) with Scaffold{ val start = findStartDir(directory) - val useBasicBuild = directory == start && start.getName != "build" + val useBasicBuild = directory == start && start.getName != buildDirectoryName try{ if(useBasicBuild) { @@ -54,8 +56,8 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger) with Scaffold{ else new cbt.BasicBuild( context.copy( workingDirectory = start ) ) with BuildBuild } catch { - case e:ClassNotFoundException if e.getMessage == "Build" => - throw new Exception(s"no class Build found in " ++ start.string) + case e:ClassNotFoundException if e.getMessage == buildClassName => + throw new Exception(s"no class ${buildClassName} found in " ++ start.string) } } diff --git a/test/test.scala b/test/test.scala index 7247e6b..1665f13 100644 --- a/test/test.scala +++ b/test/test.scala @@ -240,19 +240,19 @@ object Main{ { val res = runCbt("forgot-extend", Seq("run")) assert(!res.exit0) - assert(res.err contains "Build cannot be cast to cbt.BuildInterface", res.err) + assert(res.err contains s"${lib.buildClassName} cannot be cast to cbt.BuildInterface", res.err) } { val res = runCbt("no-build-file", Seq("run")) assert(!res.exit0) - assert(res.err contains "No file build.scala (lower case) found in", res.err) + assert(res.err contains s"No file ${lib.buildFileName} (lower case) found in", res.err) } { val res = runCbt("empty-build-file", Seq("run")) assert(!res.exit0) - assert(res.err contains "You need to define a class Build in build.scala in", res.err) + assert(res.err contains s"You need to define a class ${lib.buildClassName} in", res.err) } { -- cgit v1.2.3