aboutsummaryrefslogtreecommitdiff
path: root/stage1
diff options
context:
space:
mode:
authorChristopher Vogt <oss.nsp@cvogt.org>2017-03-28 09:35:24 -0400
committerChristopher Vogt <oss.nsp@cvogt.org>2017-03-28 10:09:15 -0400
commita3e5f304e99ff47165af6ed20182f06700e15b33 (patch)
treeecd5ab13a2a2c5a11415fa9d4f64f3634e02309a /stage1
parent497fff26705be6a21e6099a562ff14bfe1d90003 (diff)
downloadcbt-a3e5f304e99ff47165af6ed20182f06700e15b33.tar.gz
cbt-a3e5f304e99ff47165af6ed20182f06700e15b33.tar.bz2
cbt-a3e5f304e99ff47165af6ed20182f06700e15b33.zip
minor reflection related refactor
Diffstat (limited to 'stage1')
-rw-r--r--stage1/Stage1Lib.scala25
-rw-r--r--stage1/resolver.scala22
2 files changed, 17 insertions, 30 deletions
diff --git a/stage1/Stage1Lib.scala b/stage1/Stage1Lib.scala
index 3ffc878..55c9234 100644
--- a/stage1/Stage1Lib.scala
+++ b/stage1/Stage1Lib.scala
@@ -79,28 +79,11 @@ class Stage1Lib( logger: Logger ) extends
}
}
- /*
- // ========== compilation / execution ==========
- // TODO: move classLoader first
- def runMain( className: String, args: Seq[String], classLoader: ClassLoader ): ExitCode = {
- import java.lang.reflect.Modifier
- logger.run(s"Running $className.main($args) with classLoader: " ++ classLoader.toString)
- trapExitCode{
- /*
- val cls = classLoader.loadClass(className)
- discoverCbtMain( cls ) orElse discoverMain( cls ) getOrElse (
- throw new NoSuchMethodException( "No main method found in " ++ cbt )
- ).apply( arg.toVector )*/
- ExitCode.Success
- }
- }
- */
-
- def discoverCbtMainForced( cls: Class[_] ): cbt.reflect.StaticMethod[Context, ExitCode] =
- discoverStaticMethodForced[Context, ExitCode]( cls, "cbtMain" )
+ def getCbtMain( cls: Class[_] ): cbt.reflect.StaticMethod[Context, ExitCode] =
+ findStaticMethodForced[Context, ExitCode]( cls, "cbtMain" )
- def discoverCbtMain( cls: Class[_] ): Option[cbt.reflect.StaticMethod[Context, ExitCode]] =
- discoverStaticMethod[Context, ExitCode]( cls, "cbtMain" )
+ def findCbtMain( cls: Class[_] ): Option[cbt.reflect.StaticMethod[Context, ExitCode]] =
+ findStaticMethod[Context, ExitCode]( cls, "cbtMain" )
/** shows an interactive dialogue in the shell asking the user to pick one of many choices */
def pickOne[T]( msg: String, choices: Seq[T] )( show: T => String ): Option[T] = {
diff --git a/stage1/resolver.scala b/stage1/resolver.scala
index 0e5d221..be4d278 100644
--- a/stage1/resolver.scala
+++ b/stage1/resolver.scala
@@ -77,24 +77,28 @@ trait DependencyImplementation extends Dependency{
)
}
*/
- def flatClassLoader: Boolean = false
- def runMain( className: String, args: Seq[String] ): ExitCode = lib.trapExitCode{
- lib.runMain( classLoader.loadClass( className ), args )
+ def runMain( className: String, args: Seq[String] ): ExitCode = {
+ lib.getMain( classLoader.loadClass( className ) )( args )
}
- def runMain( args: Seq[String] ): ExitCode = lib.trapExitCode{
- mainMethod.getOrElse(
+ def runMain( args: Seq[String] ): ExitCode = {
+ val c = mainClass.getOrElse(
throw new RuntimeException( "No main class found in " + this )
- )( args )
+ )
+ runMain( c.getName, args )
}
- def mainMethod = lib.pickOne( "Which one do you want to run?", mainMethods )( _.name )
+ def mainClass = lib.pickOne(
+ "Which one do you want to run?",
+ classes.filter( lib.findMain(_).nonEmpty )
+ )( _.name.stripSuffix( "$" ) )
def classes = exportedClasspath.files.flatMap(
- lib.iterateClasses( _, classLoader, false )
+ lib.topLevelClasses( _, classLoader, false )
)
- def mainMethods = classes.flatMap( lib.discoverMain )
+
+ def flatClassLoader: Boolean = false
def classLoader: ClassLoader = taskCache[DependencyImplementation]( "classLoader" ).memoize{
if( flatClassLoader ){