diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-03 02:26:36 +0000 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2017-03-04 20:19:11 -0500 |
commit | 26f2dfba40198020e981f27129c911d300b418ec (patch) | |
tree | fcf084530244e235e1a3c0d82d9e2ac620bd794f /stage2/Lib.scala | |
parent | b73fa65f92882da8462d1f4da3e5954478a8f4f0 (diff) | |
download | cbt-26f2dfba40198020e981f27129c911d300b418ec.tar.gz cbt-26f2dfba40198020e981f27129c911d300b418ec.tar.bz2 cbt-26f2dfba40198020e981f27129c911d300b418ec.zip |
fix callReflective not finding special char tasks names
and better error message when top-level method not being found
Diffstat (limited to 'stage2/Lib.scala')
-rw-r--r-- | stage2/Lib.scala | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/stage2/Lib.scala b/stage2/Lib.scala index 5b6a709..a0b6605 100644 --- a/stage2/Lib.scala +++ b/stage2/Lib.scala @@ -98,12 +98,12 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){ c => c .getDeclaredMethods - .filterNot( _.getName contains "$" ) .filter{ m => java.lang.reflect.Modifier.isPublic(m.getModifiers) } .filter( _.getParameterTypes.length == 0 ) .map(m => NameTransformer.decode(m.getName) -> m) + .filterNot(_._1 contains "$") ).toMap def taskNames(cls: Class[_]): Seq[String] = taskMethods(cls).keys.toVector.sorted @@ -157,8 +157,9 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){ private def callInternal[T <: AnyRef]( obj: T, members: Seq[String], previous: Seq[String], context: Context ): Seq[(Option[Object], Option[ExitCode], Option[String])] = { members.headOption.map{ taskName => + val name = NameTransformer.decode(taskName) logger.lib("Calling task " ++ taskName.toString) - taskMethods(obj.getClass).get(taskName).map{ method => + taskMethods(obj.getClass).get(name).map{ method => Option(method.invoke(obj) /* null in case of Unit */ ).getOrElse(().asInstanceOf[AnyRef]) match { case code if code.getClass.getSimpleName == "ExitCode" => // FIXME: ExitCode needs to be part of the compatibility interfaces @@ -169,9 +170,8 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){ callInternal(result, members.tail, previous :+ taskName, context) } }.getOrElse{ - val folder = NameTransformer.decode(taskName) - if( context != null && (context.workingDirectory / folder).exists ){ - val newContext = context.copy( workingDirectory = context.workingDirectory / folder ) + if( context != null && (context.workingDirectory / name).exists ){ + val newContext = context.copy( workingDirectory = context.workingDirectory / name ) callInternal( lib.loadRoot( newContext @@ -181,7 +181,9 @@ final class Lib(val logger: Logger) extends Stage1Lib(logger){ newContext ) } else { - Seq( ( Some(obj), None, Some("Object " ++ previous.mkString(".") ++ s" has no method $taskName\n") ) ) + val p = previous.mkString(".") + val msg = (if(p.nonEmpty) p ++ s" has" else "") + Seq( ( Some(obj), None, Some( msg ++ s"no method $name\n") ) ) } } }.getOrElse{ |