aboutsummaryrefslogtreecommitdiff
path: root/stage2
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-02-15 03:30:46 -0500
committerChristopher Vogt <oss.nsp@cvogt.org>2017-02-15 04:07:21 -0500
commit4f4c34f3f52b87057626682dd43a21cd83e2ff7a (patch)
tree12396906bde5f51cc8fc274c387d77e438bd2c23 /stage2
parent7ee113962134e3c9c4659d6de9de3c7015174d3f (diff)
downloadcbt-4f4c34f3f52b87057626682dd43a21cd83e2ff7a.tar.gz
cbt-4f4c34f3f52b87057626682dd43a21cd83e2ff7a.tar.bz2
cbt-4f4c34f3f52b87057626682dd43a21cd83e2ff7a.zip
add package to generated Build in build.scala and in-package discovery
This should allow for build to add other builds to their dependencies and interact with them in a type-safe way. And ever regardless it seems like good practice to never have the same class existing in the same package or the top-level package even if they don’t end up on the same classpath. This might also help make stack traces easier to understand. Also improve error messages for mistakes with the build class, e.g. constructor, super classes, etc.
Diffstat (limited to 'stage2')
-rw-r--r--stage2/BuildBuild.scala30
-rw-r--r--stage2/Scaffold.scala3
2 files changed, 24 insertions, 9 deletions
diff --git a/stage2/BuildBuild.scala b/stage2/BuildBuild.scala
index 798bd7d..2eebcbc 100644
--- a/stage2/BuildBuild.scala
+++ b/stage2/BuildBuild.scala
@@ -63,15 +63,29 @@ trait BuildBuildWithoutEssentials extends BaseBuild{
.invoke( null, ctx )
}
}.getOrElse{
- try{
- classLoader
- .loadClass(lib.buildClassName)
- .getConstructors.head
- .newInstance(managedContext)
- } catch {
- case e: ClassNotFoundException if e.getMessage == lib.buildClassName =>
- throw new Exception("You need to define a class Build in build.scala in: "+projectDirectory)
+ val buildClasses =
+ lib.iterateClasses( compileTarget, classLoader, false )
+ .filter(_.getSimpleName == lib.buildClassName)
+ .filter(classOf[BaseBuild] isAssignableFrom _)
+ if( buildClasses.size == 0 ){
+ throw new Exception(
+ s"You need to define a class ${lib.buildClassName} extending an appropriate super class in\n"
+ + (projectDirectory / lib.buildFileName) ++ "\nbut none found."
+ )
+ } else if( buildClasses.size > 1 ){
+ throw new Exception(
+ s"You need to define exactly one class ${lib.buildClassName} extending an appropriate build super class, but multiple found in " + projectDirectory + ":\n" + buildClasses.mkString("\n")
+ )
+ } else {
+ val buildClass = buildClasses.head
+ if( !buildClass.getConstructors.exists(_.getParameterTypes.toList == List(classOf[Context])) ){
+ throw new Exception(
+ s"Expected class ${lib.buildClassName}(val context: Context), but found different constructor in\n"
+ + projectDirectory ++ "\n"
+ + buildClass ++ "(" ++ buildClass.getConstructors.map(_.getParameterTypes.mkString(", ")).mkString("; ") + ")" )
}
+ buildClass.getConstructors.head.newInstance(managedContext)
+ }
}
}
)
diff --git a/stage2/Scaffold.scala b/stage2/Scaffold.scala
index b110258..68a966b 100644
--- a/stage2/Scaffold.scala
+++ b/stage2/Scaffold.scala
@@ -59,7 +59,8 @@ object Main{
def createBuild(
projectDirectory: File
): Unit = {
- createFile(projectDirectory, "build/build.scala", s"""import cbt._
+ createFile(projectDirectory, lib.buildDirectoryName++"/"++lib.buildFileName, s"""package cbt_build.${packageFromDirectory(projectDirectory)}
+import cbt._
class Build(val context: Context) extends BaseBuild{
override def dependencies =
super.dependencies ++ // don't forget super.dependencies here for scala-library, etc.