diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2017-02-15 03:30:46 -0500 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2017-02-15 04:07:21 -0500 |
commit | 4f4c34f3f52b87057626682dd43a21cd83e2ff7a (patch) | |
tree | 12396906bde5f51cc8fc274c387d77e438bd2c23 /stage2/BuildBuild.scala | |
parent | 7ee113962134e3c9c4659d6de9de3c7015174d3f (diff) | |
download | cbt-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/BuildBuild.scala')
-rw-r--r-- | stage2/BuildBuild.scala | 30 |
1 files changed, 22 insertions, 8 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) + } } } ) |