aboutsummaryrefslogtreecommitdiff
path: root/stage2/BuildBuild.scala
diff options
context:
space:
mode:
Diffstat (limited to 'stage2/BuildBuild.scala')
-rw-r--r--stage2/BuildBuild.scala30
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)
+ }
}
}
)